Skip to content

Commit

Permalink
Update space
Browse files Browse the repository at this point in the history
  • Loading branch information
glaxxie committed Feb 28, 2024
1 parent 1aa7107 commit 95231ca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 40 deletions.
18 changes: 9 additions & 9 deletions exercises/practice/resistor-color-trio/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
func color_code(colors):
var colors_code = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]
var colors_code = ["black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "grey", "white"]

var units = {
var units = {
1e9: "gigaohms",
1e6: "megaohms",
1e3: "kiloohms"
}

var base_value = colors_code.find(colors[0]) * 10 + colors_code.find(colors[1])
var magnitude = 10 ** colors_code.find(colors[2])
var total = base_value * magnitude
var base_value = colors_code.find(colors[0]) * 10 + colors_code.find(colors[1])
var magnitude = 10 ** colors_code.find(colors[2])
var total = base_value * magnitude

for key in units.keys():
if total >= key:
return str(total / key) + " " + units[key]
for key in units.keys():
if total >= key:
return str(total / key) + " " + units[key]

return str(total) + " ohms"
return str(total) + " ohms"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
func color_code(colors):
pass
pass
61 changes: 31 additions & 30 deletions exercises/practice/resistor-color-trio/resistor_color_trio_test.gd
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
func test_orange_and_orange_and_black(solution_script):
var colors = ["orange", "orange", "black"]
var expected = "33 ohms"
return [expected, solution_script.color_code(colors)]
var colors = ["orange", "orange", "black"]
var expected = "33 ohms"
return [expected, solution_script.color_code(colors)]


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


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


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


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


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


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


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


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


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

0 comments on commit 95231ca

Please sign in to comment.