Skip to content

Commit ea21f1d

Browse files
authored
Improve error messages in space-age exercise (#68)
[no important files changed]
1 parent 30ed8aa commit ea21f1d

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed
Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,42 @@
1-
func roughly_equal(n1, n2):
2-
return abs(n1 - n2) <= 0.01
1+
func _round(value):
2+
return snappedf(value, 0.01)
33

44

55
func test_age_on_Earth(solution_script):
66
var age = solution_script.on_planet('Earth', 1000000000)
7-
var expected = 31.69
8-
return [roughly_equal(age, expected), true]
7+
return [_round(age), _round(31.69)]
98

109

1110
func test_age_on_Mercury(solution_script):
1211
var age = solution_script.on_planet('Mercury', 2134835688)
13-
var expected = 280.88
14-
return [roughly_equal(age, expected), true]
12+
return [_round(age), _round(280.88)]
1513

1614

1715
func test_age_on_Venus(solution_script):
1816
var age = solution_script.on_planet('Venus', 189839836)
19-
var expected = 9.78
20-
return [roughly_equal(age, expected), true]
17+
return [_round(age), _round(9.78)]
2118

2219

2320
func test_age_on_Mars(solution_script):
2421
var age = solution_script.on_planet('Mars', 2129871239)
25-
var expected = 35.88
26-
return [roughly_equal(age, expected), true]
22+
return [_round(age), _round(35.88)]
2723

2824

2925
func test_age_on_Jupiter(solution_script):
3026
var age = solution_script.on_planet('Jupiter', 901876382)
31-
var expected = 2.41
32-
return [roughly_equal(age, expected), true]
27+
return [_round(age), _round(2.41)]
3328

3429

3530
func test_age_on_Saturn(solution_script):
3631
var age = solution_script.on_planet('Saturn', 2000000000)
37-
var expected = 2.15
38-
return [roughly_equal(age, expected), true]
32+
return [_round(age), _round(2.15)]
3933

4034

4135
func test_age_on_Uranus(solution_script):
4236
var age = solution_script.on_planet('Uranus', 1210123456)
43-
var expected = 0.46
44-
return [roughly_equal(age, expected), true]
37+
return [_round(age), _round(0.46)]
4538

4639

4740
func test_age_on_Neptune(solution_script):
4841
var age = solution_script.on_planet('Neptune', 1821023456)
49-
var expected = 0.35
50-
return [roughly_equal(age, expected), true]
42+
return [_round(age), _round(0.35)]

0 commit comments

Comments
 (0)