From 01681dae6152c5091c18bd83588d8b989e51f688 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 15 Oct 2023 18:11:42 +0100 Subject: [PATCH] Create anagrams exercise --- anagrams.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 anagrams.lua diff --git a/anagrams.lua b/anagrams.lua new file mode 100644 index 0000000..ed2fb0a --- /dev/null +++ b/anagrams.lua @@ -0,0 +1,39 @@ +-- 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())