-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
exercises/practice/resistor-color-trio/resistor_color_trio_test.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | ||
|