Skip to content

Commit 57602aa

Browse files
gliksonferhatelmas
authored andcommitted
space-age: do not force rounding of solutions (#960)
* space-age: do not force rounding of solutions The expected age values are specified (in respective canonical-data.json) with 2-digit precision (e.g., 31.69), while the actual result is a float. Instead of forcing the solution to perform an arbitrary rounding, the test code verifies the result with certain precision (currently same 2-digit, for compatibility - can be eventually added to canonical-data.json itself). Aligned with the conclusion of the discussion in exercism/problem-specifications#880 * space-age: fix formatting
1 parent 999244e commit 57602aa

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

exercises/space-age/space_age_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package space
22

33
import (
4+
"math"
45
"testing"
56
)
67

78
func TestAge(t *testing.T) {
9+
const precision = 0.01
810
for _, tc := range testCases {
9-
if actual := Age(tc.seconds, tc.planet); actual != tc.expected {
11+
if actual := Age(tc.seconds, tc.planet); math.Abs(actual-tc.expected) > precision {
1012
t.Fatalf("FAIL: %s\nExpected: %#v\nActual: %#v", tc.description, tc.expected, actual)
1113
}
1214
t.Logf("PASS: %s", tc.description)

0 commit comments

Comments
 (0)