Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion exercises/practice/space-age/.meta/example.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ var orbital_periods = {


func on_planet(planet, seconds):
var ratio = orbital_periods.get(planet)
if planet not in orbital_periods:
return null
var ratio = orbital_periods[planet]
return seconds / EARTH_SECONDS / ratio
5 changes: 5 additions & 0 deletions exercises/practice/space-age/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ func _round(value):
{% for case in cases %}
func test_{{ case.func_name }}(solution_script):
var got = solution_script.on_planet({{ case.input.planet | togdscript }}, {{ case.input.seconds }})
{%- if not case.expect_error %}
var want = {{ case.expected }}
return [_round(got), _round(want)]
{%- else %}
var want = null
return [got, want]
{%- endif %}

{% endfor %}

1 change: 0 additions & 1 deletion exercises/practice/space-age/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ description = "age on Neptune"

[57b96e2a-1178-40b7-b34d-f3c9c34e4bf4]
description = "invalid planet causes error"
include = false
6 changes: 6 additions & 0 deletions exercises/practice/space-age/space_age_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ func test_age_on_neptune(solution_script):
var got = solution_script.on_planet("Neptune", 1821023456)
var want = 0.35
return [_round(got), _round(want)]


func test_invalid_planet_causes_error(solution_script):
var got = solution_script.on_planet("Sun", 680804807)
var want = null
return [got, want]
Loading