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
6 changes: 5 additions & 1 deletion exercises/practice/all-your-base/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ func test_{{ case.func_name }}(solution_script):
{%- else %}
var want = null
{%- endif %}
return [got, want]
return [
got,
want,
'{{ case.property | camel_to_snake }}({{ case.input.inputBase | quote }}, {{ case.input.digits | quote }}, {{ case.input.outputBase | quote }}) = %s, but want %s' % [got, want]
]

{% endfor %}

126 changes: 105 additions & 21 deletions exercises/practice/all-your-base/all_your_base_test.gd
Original file line number Diff line number Diff line change
@@ -1,124 +1,208 @@
func test_single_bit_one_to_decimal(solution_script):
var got = solution_script.rebase(2, [1], 10)
var want = [1]
return [got, want]
return [
got,
want,
'rebase(2, [1], 10) = %s, but want %s' % [got, want]
]


func test_binary_to_single_decimal(solution_script):
var got = solution_script.rebase(2, [1, 0, 1], 10)
var want = [5]
return [got, want]
return [
got,
want,
'rebase(2, [1, 0, 1], 10) = %s, but want %s' % [got, want]
]


func test_single_decimal_to_binary(solution_script):
var got = solution_script.rebase(10, [5], 2)
var want = [1, 0, 1]
return [got, want]
return [
got,
want,
'rebase(10, [5], 2) = %s, but want %s' % [got, want]
]


func test_binary_to_multiple_decimal(solution_script):
var got = solution_script.rebase(2, [1, 0, 1, 0, 1, 0], 10)
var want = [4, 2]
return [got, want]
return [
got,
want,
'rebase(2, [1, 0, 1, 0, 1, 0], 10) = %s, but want %s' % [got, want]
]


func test_decimal_to_binary(solution_script):
var got = solution_script.rebase(10, [4, 2], 2)
var want = [1, 0, 1, 0, 1, 0]
return [got, want]
return [
got,
want,
'rebase(10, [4, 2], 2) = %s, but want %s' % [got, want]
]


func test_trinary_to_hexadecimal(solution_script):
var got = solution_script.rebase(3, [1, 1, 2, 0], 16)
var want = [2, 10]
return [got, want]
return [
got,
want,
'rebase(3, [1, 1, 2, 0], 16) = %s, but want %s' % [got, want]
]


func test_hexadecimal_to_trinary(solution_script):
var got = solution_script.rebase(16, [2, 10], 3)
var want = [1, 1, 2, 0]
return [got, want]
return [
got,
want,
'rebase(16, [2, 10], 3) = %s, but want %s' % [got, want]
]


func test_15_bit_integer(solution_script):
var got = solution_script.rebase(97, [3, 46, 60], 73)
var want = [6, 10, 45]
return [got, want]
return [
got,
want,
'rebase(97, [3, 46, 60], 73) = %s, but want %s' % [got, want]
]


func test_empty_list(solution_script):
var got = solution_script.rebase(2, [], 10)
var want = [0]
return [got, want]
return [
got,
want,
'rebase(2, [], 10) = %s, but want %s' % [got, want]
]


func test_single_zero(solution_script):
var got = solution_script.rebase(10, [0], 2)
var want = [0]
return [got, want]
return [
got,
want,
'rebase(10, [0], 2) = %s, but want %s' % [got, want]
]


func test_multiple_zeros(solution_script):
var got = solution_script.rebase(10, [0, 0, 0], 2)
var want = [0]
return [got, want]
return [
got,
want,
'rebase(10, [0, 0, 0], 2) = %s, but want %s' % [got, want]
]


func test_leading_zeros(solution_script):
var got = solution_script.rebase(7, [0, 6, 0], 10)
var want = [4, 2]
return [got, want]
return [
got,
want,
'rebase(7, [0, 6, 0], 10) = %s, but want %s' % [got, want]
]


func test_input_base_is_one(solution_script):
var got = solution_script.rebase(1, [0], 10)
var want = null
return [got, want]
return [
got,
want,
'rebase(1, [0], 10) = %s, but want %s' % [got, want]
]


func test_input_base_is_zero(solution_script):
var got = solution_script.rebase(0, [], 10)
var want = null
return [got, want]
return [
got,
want,
'rebase(0, [], 10) = %s, but want %s' % [got, want]
]


func test_input_base_is_negative(solution_script):
var got = solution_script.rebase(-2, [1], 10)
var want = null
return [got, want]
return [
got,
want,
'rebase(-2, [1], 10) = %s, but want %s' % [got, want]
]


func test_negative_digit(solution_script):
var got = solution_script.rebase(2, [1, -1, 1, 0, 1, 0], 10)
var want = null
return [got, want]
return [
got,
want,
'rebase(2, [1, -1, 1, 0, 1, 0], 10) = %s, but want %s' % [got, want]
]


func test_invalid_positive_digit(solution_script):
var got = solution_script.rebase(2, [1, 2, 1, 0, 1, 0], 10)
var want = null
return [got, want]
return [
got,
want,
'rebase(2, [1, 2, 1, 0, 1, 0], 10) = %s, but want %s' % [got, want]
]


func test_output_base_is_one(solution_script):
var got = solution_script.rebase(2, [1, 0, 1, 0, 1, 0], 1)
var want = null
return [got, want]
return [
got,
want,
'rebase(2, [1, 0, 1, 0, 1, 0], 1) = %s, but want %s' % [got, want]
]


func test_output_base_is_zero(solution_script):
var got = solution_script.rebase(10, [7], 0)
var want = null
return [got, want]
return [
got,
want,
'rebase(10, [7], 0) = %s, but want %s' % [got, want]
]


func test_output_base_is_negative(solution_script):
var got = solution_script.rebase(2, [1], -7)
var want = null
return [got, want]
return [
got,
want,
'rebase(2, [1], -7) = %s, but want %s' % [got, want]
]


func test_both_bases_are_negative(solution_script):
var got = solution_script.rebase(-2, [1], -7)
var want = null
return [got, want]
return [
got,
want,
'rebase(-2, [1], -7) = %s, but want %s' % [got, want]
]
11 changes: 8 additions & 3 deletions exercises/practice/allergies/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ func _sorted(array):

func test_{{ case.input.item }}_{{ case.func_name }}(allergies):
allergies.score = {{ case.input.score }}
return [allergies.allergic_to("{{ case.input.item }}"), {{ case.expected | quote }}]
var got = allergies.allergic_to("{{ case.input.item }}")
var want = {{ case.expected | quote }}
return [got, want, "with score={{ case.input.score }}, allergic_to() == %s, but want %s" % [got, want]]
{%- else %}

func test_list_when_{{ case.func_name }}(allergies):
allergies.score = {{ case.input.score }}
var got =_sorted(allergies.lst)
var want = _sorted({{ case.expected }})
return [
_sorted(allergies.lst),
_sorted({{ case.expected }})
got,
want,
"with score={{ case.input.score }}, lst\n got: %s\n want %s" % [got, want]
]
{%- endif %}
{% endfor %}
Loading
Loading