Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages in space-age exercise #68

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions exercises/practice/space-age/space_age_test.gd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Do we need to round the expected values though? I think we can just round the calculated age. That should make it a bit clearer what's going on hopefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last example was raising an error, saying that the expected value was 0.35, and the actual one 0.35 ... 🤔 So, just to be sure, I decided to round all the values 😛 That took care of the error 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
func roughly_equal(n1, n2):
return abs(n1 - n2) <= 0.01
func _round(value):
return snappedf(value, 0.01)


func test_age_on_Earth(solution_script):
var age = solution_script.on_planet('Earth', 1000000000)
var expected = 31.69
return [roughly_equal(age, expected), true]
return [_round(age), _round(31.69)]


func test_age_on_Mercury(solution_script):
var age = solution_script.on_planet('Mercury', 2134835688)
var expected = 280.88
return [roughly_equal(age, expected), true]
return [_round(age), _round(280.88)]


func test_age_on_Venus(solution_script):
var age = solution_script.on_planet('Venus', 189839836)
var expected = 9.78
return [roughly_equal(age, expected), true]
return [_round(age), _round(9.78)]


func test_age_on_Mars(solution_script):
var age = solution_script.on_planet('Mars', 2129871239)
var expected = 35.88
return [roughly_equal(age, expected), true]
return [_round(age), _round(35.88)]


func test_age_on_Jupiter(solution_script):
var age = solution_script.on_planet('Jupiter', 901876382)
var expected = 2.41
return [roughly_equal(age, expected), true]
return [_round(age), _round(2.41)]


func test_age_on_Saturn(solution_script):
var age = solution_script.on_planet('Saturn', 2000000000)
var expected = 2.15
return [roughly_equal(age, expected), true]
return [_round(age), _round(2.15)]


func test_age_on_Uranus(solution_script):
var age = solution_script.on_planet('Uranus', 1210123456)
var expected = 0.46
return [roughly_equal(age, expected), true]
return [_round(age), _round(0.46)]


func test_age_on_Neptune(solution_script):
var age = solution_script.on_planet('Neptune', 1821023456)
var expected = 0.35
return [roughly_equal(age, expected), true]
return [_round(age), _round(0.35)]