Enumerate the exercises
This commit is contained in:
42
08_anagrams.lua
Normal file
42
08_anagrams.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
-- Implement the is_anagram() function below, so that it returns true if
|
||||
-- the two passed strings are anagrams of each other. Any non-
|
||||
-- alphabetical characters in the string should be ignored.
|
||||
--
|
||||
-- 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())
|
||||
Reference in New Issue
Block a user