summaryrefslogtreecommitdiff
path: root/go/space-age/space_age_test.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-09-22 15:08:06 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-09-22 15:08:06 +0200
commit53eefb5643c87888ddda629fd4f848ad7681662e (patch)
treeb13e988068ea525d9c24e8fdda5d9935bc92bd74 /go/space-age/space_age_test.go
parent44b00088f7d87053fd2bb3b4ecfcaea79fd0c41d (diff)
load space-age
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)
+ }
+ }
+}