Compare commits
No commits in common. "c41bd07c6c80e1fda8228aaebd9dc39ea00f752e" and "d3d6c9e650929fc12af83a9d4ba87eb660985bb6" have entirely different histories.
c41bd07c6c
...
d3d6c9e650
@ -1,11 +0,0 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function f()
|
|
||||||
-- Your implementation here
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
local luaunit = require("luaunit.luaunit")
|
|
||||||
|
|
||||||
os.exit(luaunit.LuaUnit.run())
|
|
39
anagrams.lua
39
anagrams.lua
@ -1,39 +0,0 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function is_anagram(str1, str2)
|
|
||||||
-- Your implementation here
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
local luaunit = require("luaunit.luaunit")
|
|
||||||
|
|
||||||
function test_listen_is_anagram_of_silent()
|
|
||||||
luaunit.assertTrue(is_anagram("listen", "silent"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_astronomers_is_anagram_of_moon_starers()
|
|
||||||
luaunit.assertTrue(is_anagram("astronomers", "moon starers"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_dormitory_is_anagram_of_dirty_room()
|
|
||||||
luaunit.assertTrue(is_anagram("dormitory", "dirty room"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_foo_is_not_anagram_of_bar()
|
|
||||||
luaunit.assertFalse(is_anagram("foo", "bar"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_foo_is_not_anagram_of_of()
|
|
||||||
luaunit.assertFalse(is_anagram("foo", "of"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_bar_is_not_anagram_of_barn()
|
|
||||||
luaunit.assertFalse(is_anagram("bar", "barn"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_barn_is_not_anagram_of_bar()
|
|
||||||
luaunit.assertFalse(is_anagram("barn", "bar"))
|
|
||||||
end
|
|
||||||
|
|
||||||
os.exit(luaunit.LuaUnit.run())
|
|
@ -1,12 +1,11 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function hamming_distance(str1, str2)
|
function hamming_distance(str1, str2)
|
||||||
-- Your implementation here
|
-- Your solution here
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
-- Tests -----------------------------------------------------------------------
|
||||||
|
|
||||||
local luaunit = require("luaunit.luauint")
|
package.path = package.path .. ";../luaunit/?.lua"
|
||||||
|
local luaunit = require("luaunit")
|
||||||
|
|
||||||
function test_distance_between_foo_and_bar_is_3()
|
function test_distance_between_foo_and_bar_is_3()
|
||||||
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
26
basic/leap_year.lua
Normal file
26
basic/leap_year.lua
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
function leap_year(year)
|
||||||
|
-- Your solution here
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Tests -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
package.path = package.path .. ";../luaunit/?.lua"
|
||||||
|
local luaunit = require("luaunit")
|
||||||
|
|
||||||
|
function test_2004_is_leap_year()
|
||||||
|
luaunit.assertTrue(leap_year(2004))
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_1993_is_not_leap_year()
|
||||||
|
luaunit.assertFalse(leap_year(1993))
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_1900_is_not_leap_year()
|
||||||
|
luaunit.assertFalse(leap_year(1900))
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_2000_is_leap_year()
|
||||||
|
luaunit.assertTrue(leap_year(2000))
|
||||||
|
end
|
||||||
|
|
||||||
|
os.exit(luaunit.LuaUnit.run())
|
@ -1,5 +1,3 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
-- Give the colours whatever values are convenient
|
-- Give the colours whatever values are convenient
|
||||||
black = undefined
|
black = undefined
|
||||||
brown = undefined
|
brown = undefined
|
||||||
@ -15,12 +13,13 @@ gold = undefined
|
|||||||
silver = undefined
|
silver = undefined
|
||||||
|
|
||||||
function decode_resistance(colours)
|
function decode_resistance(colours)
|
||||||
-- Your implementation here
|
-- Your solution here
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
-- Tests -----------------------------------------------------------------------
|
||||||
|
|
||||||
local luaunit = require("luaunit.luaunit")
|
package.path = package.path .. ";../luaunit/?.lua"
|
||||||
|
local luaunit = require("luaunit")
|
||||||
|
|
||||||
function test_violet_orange_black_is_73_ohms()
|
function test_violet_orange_black_is_73_ohms()
|
||||||
local resistance = decode_resistance({violet, orange, black})
|
local resistance = decode_resistance({violet, orange, black})
|
@ -1,23 +0,0 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function greatest_common_divisor(x, y)
|
|
||||||
-- Your implementation here
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
local luaunit = require("luaunit.luaunit")
|
|
||||||
|
|
||||||
function test_greatest_common_divisor_of_1386_and_3213_is_63()
|
|
||||||
luaunit.assertEquals(greatest_common_divisor(1386, 3213), 63)
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_greatest_common_divisor_of_1470_and_3234_is_294()
|
|
||||||
luaunit.assertEquals(greatest_common_divisor(1470, 3234), 294)
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_greatest_common_divisor_of_931_and_399_is_133()
|
|
||||||
luaunit.assertEquals(greatest_common_divisor(931, 399), 133)
|
|
||||||
end
|
|
||||||
|
|
||||||
os.exit(luaunit.LuaUnit.run())
|
|
@ -1,27 +0,0 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function is_leap_year(year)
|
|
||||||
-- Your implementation here
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
local luaunit = require("luaunit.luaunit")
|
|
||||||
|
|
||||||
function test_2004_is_leap_year()
|
|
||||||
luaunit.assertTrue(is_leap_year(2004))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_1993_is_not_leap_year()
|
|
||||||
luaunit.assertFalse(is_leap_year(1993))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_1900_is_not_leap_year()
|
|
||||||
luaunit.assertFalse(is_leap_year(1900))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_2000_is_leap_year()
|
|
||||||
luaunit.assertTrue(is_leap_year(2000))
|
|
||||||
end
|
|
||||||
|
|
||||||
os.exit(luaunit.LuaUnit.run())
|
|
@ -1,31 +0,0 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function is_prime(x)
|
|
||||||
-- Your implementation here
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
local luaunit = require("luaunit.luauint")
|
|
||||||
|
|
||||||
function test_1_is_not_prime()
|
|
||||||
luaunit.assertFalse(is_prime(1))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_2_is_prime()
|
|
||||||
luaunit.assertTrue(is_prime(2))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_15_is_not_prime()
|
|
||||||
luaunit.assertFalse(is_prime(15))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_441_is_not_prime()
|
|
||||||
luaunit.assertFalse(is_prime(441))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_563_is_prime()
|
|
||||||
luaunit.assertTrue(is_prime(563))
|
|
||||||
end
|
|
||||||
|
|
||||||
os.exit(luaunit.LuaUnit.run())
|
|
@ -1,39 +0,0 @@
|
|||||||
-- Solution --------------------------------------------------------------------
|
|
||||||
|
|
||||||
function is_queen_threat(queen_position, pawn_position)
|
|
||||||
-- Your implementation here
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Tests -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
local luaunit = require("luaunit.luaunit")
|
|
||||||
|
|
||||||
function test_B4_theatens_G4()
|
|
||||||
luaunit.assertTrue(is_queen_threat("B4", "G4"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_D7_theatens_D1()
|
|
||||||
luaunit.assertTrue(is_queen_threat("D7", "D1"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_C5_theatens_F8()
|
|
||||||
luaunit.assertTrue(is_queen_threat("C5", "F8"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_B3_theatens_D1()
|
|
||||||
luaunit.assertTrue(is_queen_threat("B3", "D1"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_B4_does_not_threaten_F3()
|
|
||||||
luaunit.assertFalse(is_queen_threat("B4", "F3"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_E2_does_not_threaten_G1()
|
|
||||||
luaunit.assertFalse(is_queen_threat("E2", "G1"))
|
|
||||||
end
|
|
||||||
|
|
||||||
function test_A8_does_not_threaten_G3()
|
|
||||||
luaunit.assertFalse(is_queen_threat("A8", "G3"))
|
|
||||||
end
|
|
||||||
|
|
||||||
os.exit(luaunit.LuaUnit.run())
|
|
Loading…
x
Reference in New Issue
Block a user