summary refs log tree commit diff stats
path: root/go/space-age/space_age_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/space-age/space_age_test.go')
-rw-r--r--go/space-age/space_age_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/go/space-age/space_age_test.go b/go/space-age/space_age_test.go
new file mode 100644
index 0000000..71f7359
--- /dev/null
+++ b/go/space-age/space_age_test.go
@@ -0,0 +1,25 @@
+package space
+
+import (
+	"math"
+	"testing"
+)
+
+func TestAge(t *testing.T) {
+	const precision = 0.01
+	for _, tc := range testCases {
+		actual := Age(tc.seconds, tc.planet)
+		if math.IsNaN(actual) || math.Abs(actual-tc.expected) > precision {
+			t.Fatalf("FAIL: %s\nExpected: %#v\nActual: %#v", tc.description, tc.expected, actual)
+		}
+		t.Logf("PASS: %s", tc.description)
+	}
+}
+
+func BenchmarkAge(b *testing.B) {
+	for i := 0; i < b.N; i++ {
+		for _, tc := range testCases {
+			Age(tc.seconds, tc.planet)
+		}
+	}
+}