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
2 changes: 1 addition & 1 deletion exercises/practice/resistor-color-duo/.meta/example.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const COLORS = [
]


func color_code(colors):
func value(colors):
var tens = colors[0]
var ones = colors[1]
return COLORS.find(tens) * 10 + COLORS.find(ones)
7 changes: 7 additions & 0 deletions exercises/practice/resistor-color-duo/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% for case in cases %}
func test_{{ case.func_name }}(solution_script):
var colors = {{ case.input.colors | togdscript }}
var expected = {{ case.expected }}
return [solution_script.{{ case.property | camel_to_snake }}(colors), expected]

{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
func color_code(colors):
func value(colors):
pass
14 changes: 7 additions & 7 deletions exercises/practice/resistor-color-duo/resistor_color_duo_test.gd
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
func test_brown_and_black(solution_script):
var colors = ["brown", "black"]
var expected = 10
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]


func test_blue_and_grey(solution_script):
var colors = ["blue", "grey"]
var expected = 68
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]


func test_yellow_and_violet(solution_script):
var colors = ["yellow", "violet"]
var expected = 47
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]


func test_white_and_red(solution_script):
var colors = ["white", "red"]
var expected = 92
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]


func test_orange_and_orange(solution_script):
var colors = ["orange", "orange"]
var expected = 33
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]


func test_ignore_additional_colors(solution_script):
var colors = ["green", "brown", "orange"]
var expected = 51
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]


func test_black_and_brown_one_digit(solution_script):
var colors = ["black", "brown"]
var expected = 1
return [solution_script.color_code(colors), expected]
return [solution_script.value(colors), expected]
4 changes: 2 additions & 2 deletions exercises/practice/resistor-color-expert/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func color_code(colors):
func resistor_label(colors):
var size = colors.size()
if size == 1: return "0 ohms"

Expand Down Expand Up @@ -34,4 +34,4 @@ func color_code(colors):
return "%s ohms ±%s%%" % [format_number(total), tolerance]

func format_number(n):
return str(int(n)) if n == int(n) else str(n)
return str(int(n)) if n == int(n) else str(n)
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
func color_code(colors):
pass
func resistor_label(colors):
pass
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
func test_orange_orange_black_and_red(solution_script):
var colors = ["orange", "orange", "black", "red"]
var colors = ["orange", "orange", "black", "red"]
var expected = "33 ohms ±2%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_blue_grey_brown_and_violet(solution_script):
var colors = ["blue", "grey", "brown", "violet"]
var colors = ["blue", "grey", "brown", "violet"]
var expected = "680 ohms ±0.1%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_red_black_red_and_green(solution_script):
var colors = ["red", "black", "red", "green"]
var colors = ["red", "black", "red", "green"]
var expected = "2 kiloohms ±0.5%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_green_brown_orange_and_grey(solution_script):
var colors = ["green", "brown", "orange", "grey"]
var colors = ["green", "brown", "orange", "grey"]
var expected = "51 kiloohms ±0.05%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_one_black_band(solution_script):
var colors = ["black"]
var colors = ["black"]
var expected = "0 ohms"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_orange_orange_yellow_black_and_brown(solution_script):
var colors = ["orange", "orange", "yellow", "black", "brown"]
var colors = ["orange", "orange", "yellow", "black", "brown"]
var expected = "334 ohms ±1%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_red_green_yellow_yellow_and_brown(solution_script):
var colors = ["red", "green", "yellow", "yellow", "brown"]
var colors = ["red", "green", "yellow", "yellow", "brown"]
var expected = "2.54 megaohms ±1%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_blue_grey_white_red_and_brown(solution_script):
var colors = ["blue", "grey", "white", "brown", "brown"]
var colors = ["blue", "grey", "white", "brown", "brown"]
var expected = "6.89 kiloohms ±1%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_violet_orange_red_and_grey(solution_script):
var colors = ["violet", "orange", "red", "grey"]
var colors = ["violet", "orange", "red", "grey"]
var expected = "7.3 kiloohms ±0.05%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]


func test_brown_red_orange_green_and_blue(solution_script):
var colors = ["brown", "red", "orange", "green", "blue"]
var colors = ["brown", "red", "orange", "green", "blue"]
var expected = "12.3 megaohms ±0.25%"
return [solution_script.color_code(colors), expected]
return [solution_script.resistor_label(colors), expected]

4 changes: 2 additions & 2 deletions exercises/practice/resistor-color-trio/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
func color_code(colors):
func label(colors):
var colors_code = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]

var units = {
Expand All @@ -18,4 +18,4 @@ func color_code(colors):
return format_number(total) + " ohms"

func format_number(n):
return str(int(n)) if n == int(n) else str(n)
return str(int(n)) if n == int(n) else str(n)
7 changes: 7 additions & 0 deletions exercises/practice/resistor-color-trio/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% for case in cases %}
func test_{{ case.func_name }}(solution_script):
var colors = {{ case.input.colors | togdscript }}
var expected = "{{ case.expected.value }} {{ case.expected.unit }}"
return [solution_script.{{ case.property | camel_to_snake }}(colors), expected]

{% endfor %}
4 changes: 2 additions & 2 deletions exercises/practice/resistor-color-trio/resistor_color_trio.gd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
func color_code(colors):
pass
func label(colors):
pass
41 changes: 20 additions & 21 deletions exercises/practice/resistor-color-trio/resistor_color_trio_test.gd
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
func test_orange_and_orange_and_black(solution_script):
var colors = ["orange", "orange", "black"]
var colors = ["orange", "orange", "black"]
var expected = "33 ohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_blue_and_grey_and_brown(solution_script):
var colors = ["blue", "grey", "brown"]
var colors = ["blue", "grey", "brown"]
var expected = "680 ohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_red_and_black_and_red(solution_script):
var colors = ["red", "black", "red"]
var colors = ["red", "black", "red"]
var expected = "2 kiloohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_green_and_brown_and_orange(solution_script):
var colors = ["green", "brown", "orange"]
var colors = ["green", "brown", "orange"]
var expected = "51 kiloohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_yellow_and_violet_and_yellow(solution_script):
var colors = ["yellow", "violet", "yellow"]
var colors = ["yellow", "violet", "yellow"]
var expected = "470 kiloohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_blue_and_violet_and_blue(solution_script):
var colors = ["blue", "violet", "blue"]
var colors = ["blue", "violet", "blue"]
var expected = "67 megaohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_minimum_possible_value(solution_script):
var colors = ["black", "black", "black"]
var colors = ["black", "black", "black"]
var expected = "0 ohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_maximum_possible_value(solution_script):
var colors = ["white", "white", "white"]
var colors = ["white", "white", "white"]
var expected = "99 gigaohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_first_two_colors_make_an_invalid_octal_number(solution_script):
var colors = ["black", "grey", "black"]
var colors = ["black", "grey", "black"]
var expected = "8 ohms"
return [solution_script.color_code(colors), expected]
return [solution_script.label(colors), expected]


func test_ignore_extra_colors(solution_script):
var colors = ["blue", "green", "yellow", "orange"]
var colors = ["blue", "green", "yellow", "orange"]
var expected = "650 kiloohms"
return [solution_script.color_code(colors), expected]

return [solution_script.label(colors), expected]
10 changes: 10 additions & 0 deletions exercises/practice/resistor-color/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% for case in cases %}
func test_{{ case.func_name }}(solution_script):
{%- if case.property == "colorCode" %}
return [solution_script.{{ case.property | camel_to_snake }}({{ case.input.color | togdscript }}), {{ case.expected }}]

{%- elif case.property == "colors" %}
var colors = {{ case.expected | togdscript }}
return [solution_script.{{ case.property }}(), colors]
{%- endif %}
{% endfor %}
9 changes: 3 additions & 6 deletions exercises/practice/resistor-color/resistor_color_test.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
func test_color_codes_black(solution_script):
func test_black(solution_script):
return [solution_script.color_code("black"), 0]


func test_color_codes_white(solution_script):
func test_white(solution_script):
return [solution_script.color_code("white"), 9]


func test_color_codes_orange(solution_script):
func test_orange(solution_script):
return [solution_script.color_code("orange"), 3]


func test_colors(solution_script):
var colors = [
"black",
Expand Down
Loading