From ae4cd169c3d3b66b026ac741ecec3c90b4dcf099 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 15 Oct 2023 14:39:10 +0100 Subject: [PATCH] Create resistor colours exercise --- basic/resistor_colours.lua | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 basic/resistor_colours.lua diff --git a/basic/resistor_colours.lua b/basic/resistor_colours.lua new file mode 100644 index 0000000..01862c0 --- /dev/null +++ b/basic/resistor_colours.lua @@ -0,0 +1,49 @@ +-- 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 solution here +end + +-- Tests ----------------------------------------------------------------------- + +package.path = package.path .. ";../luaunit/?.lua" +local luaunit = require("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())