38 lines
1005 B
Lua
38 lines
1005 B
Lua
-- Write a function to return the hexadecimal representation (in a
|
|
-- string) of a number. Use lowercase a to f.
|
|
--
|
|
-- Solution --------------------------------------------------------------------
|
|
function hexadecimal(x)
|
|
-- Your implementation here
|
|
end
|
|
|
|
-- Tests -----------------------------------------------------------------------
|
|
|
|
local luaunit = require("luaunit.luaunit")
|
|
|
|
function test_hexadecimal_of_8_is_8()
|
|
luaunit.assertEquals(hexadecimal(8), "8")
|
|
end
|
|
|
|
function test_hexadecimal_of_14_is_e()
|
|
luaunit.assertEquals(hexadecimal(14), "e")
|
|
end
|
|
|
|
function test_hexadecimal_of_42_is_2a()
|
|
luaunit.assertEquals(hexadecimal(42), "2a")
|
|
end
|
|
|
|
function test_hexadecimal_of_3735928559_is_deadbeef()
|
|
luaunit.assertEquals(hexadecimal(3735928559), "deadbeef")
|
|
end
|
|
|
|
function test_hexadecimal_of_12648430_is_c0ffee()
|
|
luaunit.assertEquals(hexadecimal(12648430), "c0ffee")
|
|
end
|
|
|
|
function test_hexadecimal_of_49374_is_c0de()
|
|
luaunit.assertEquals(hexadecimal(49374), "c0de")
|
|
end
|
|
|
|
os.exit(luaunit.LuaUnit.run())
|