Enumerate the exercises
This commit is contained in:
23
03_hamming_distance.lua
Normal file
23
03_hamming_distance.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- The hamming distance is the number of positions in which two
|
||||
-- strings differ, and is used to measure how similar strings are.
|
||||
-- Implement the hamming_distance() function below to calculate this;
|
||||
-- you may assume that the strings are of equal length.
|
||||
--
|
||||
-- Solution --------------------------------------------------------------------
|
||||
function hamming_distance(str1, str2)
|
||||
-- Your implementation here
|
||||
end
|
||||
|
||||
-- Tests -----------------------------------------------------------------------
|
||||
|
||||
local luaunit = require("luaunit.luauint")
|
||||
|
||||
function test_distance_between_foo_and_bar_is_3()
|
||||
luaunit.assertEquals(hamming_distance("foo", "bar"), 3)
|
||||
end
|
||||
|
||||
function test_distance_between_bar_and_baz_is_1()
|
||||
luaunit.assertEquals(hamming_distance("bar", "baz"), 1)
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
Reference in New Issue
Block a user