Enumerate the exercises
This commit is contained in:
39
04_resistor_colours.lua
Normal file
39
04_resistor_colours.lua
Normal file
@@ -0,0 +1,39 @@
|
||||
-- Write a function to determine the resistance (in ohms) of a given
|
||||
-- three-part resistor colour code. The colour code is passed as a
|
||||
-- list of strings.
|
||||
--
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function decode_resistance(colours)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luaunit")
|
||||
|
||||
function test_violet_orange_black_is_73_ohms()
|
||||
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"})
|
||||
luaunit.assertEquals(resistance, 15)
|
||||
end
|
||||
|
||||
function test_green_blue_orange_is_56_kiloohms()
|
||||
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"})
|
||||
luaunit.assertEquals(resistance, 940000)
|
||||
end
|
||||
|
||||
function test_orange_red_silver_is_320_milliohms()
|
||||
local resistance = decode_resistance({"orange", "red", "silver"})
|
||||
luaunit.assertEquals(resistance, 0.32)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
Reference in New Issue
Block a user