Use strings instead of consts for resistor_colours exercise

This commit is contained in:
Camden Dixie O'Brien 2023-12-11 15:37:23 +00:00
parent 8c06a5172e
commit 17f44d6fec

View File

@ -1,18 +1,4 @@
-- Solution --------------------------------------------------------------------
-- Give the colours whatever values are convenient
black = undefined
brown = undefined
red = undefined
orange = undefined
yellow = undefined
green = undefined
blue = undefined
violet = undefined
grey = undefined
white = undefined
gold = undefined
silver = undefined
function decode_resistance(colours)
-- Your implementation here
end
@ -22,27 +8,27 @@ end
local luaunit = require("luaunit.luaunit")
function test_violet_orange_black_is_73_ohms()
local resistance = decode_resistance({violet, orange, black})
local resistance = decode_resistance({"violet", "orange", "black"})
luaunit.assertEquals(resistance, 73)
end
function test_brown_green_black_is_15_ohms()
local resistance = decode_resistance({brown, green, black})
local resistance = decode_resistance({"brown", "green", "black"})
luaunit.assertEquals(resistance, 15)
end
function test_green_blue_orange_is_56_kiloohms()
local resistance = decode_resistance({green, blue, orange})
local resistance = decode_resistance({"green", "blue", "orange"})
luaunit.assertEquals(resistance, 56000)
end
function test_white_yellow_yellow_is_940_kiloohms()
local resistance = decode_resistance({white, yellow, yellow})
local resistance = decode_resistance({"white", "yellow", "yellow"})
luaunit.assertEquals(resistance, 940000)
end
function test_orange_red_silver_is_320_milliohms()
local resistance = decode_resistance({orange, red, silver})
local resistance = decode_resistance({"orange", "red", "silver"})
luaunit.assertEquals(resistance, 0.32)
end