about summary refs log tree commit diff stats
path: root/lua/chupacabra/test_chupacabra.lua
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2024-06-09 11:35:22 -0400
committerelioat <elioat@tilde.institute>2024-06-09 11:35:22 -0400
commit1b6ac89b5051e7f010cb9cbd23cc5465fc950b64 (patch)
tree88a863a0961e81df27ce134405b735436330e796 /lua/chupacabra/test_chupacabra.lua
parentb72b5e6ab57173afd5daa555396f8d0c7aa9c1f6 (diff)
downloadtour-1b6ac89b5051e7f010cb9cbd23cc5465fc950b64.tar.gz
*
Diffstat (limited to 'lua/chupacabra/test_chupacabra.lua')
-rw-r--r--lua/chupacabra/test_chupacabra.lua27
1 files changed, 21 insertions, 6 deletions
diff --git a/lua/chupacabra/test_chupacabra.lua b/lua/chupacabra/test_chupacabra.lua
index 4d75f70..1eb5a48 100644
--- a/lua/chupacabra/test_chupacabra.lua
+++ b/lua/chupacabra/test_chupacabra.lua
@@ -1,22 +1,37 @@
 local chupacabra = require("chupacabra") 
 
--- Define a function to run a test case
+-- convert a table to a string
+local function table_to_string(t)
+    local str = "{"
+    for i, v in ipairs(t) do
+        if i > 1 then
+            str = str .. ", "
+        end
+        str = str .. tostring(v)
+    end
+    str = str .. "}"
+    return str
+end
+
 local function test_case(input, expected_output)
     local output = chupacabra.run(input, {})
-    assert(output == expected_output, "Test failed: " .. input .. " => " .. output .. ", expected: " .. expected_output)
-    print("Test passed: " .. input .. " => " .. output)
+    local expected_output_str = type(expected_output) == "table" and table_to_string(expected_output) or tostring(expected_output)
+    local output_str = type(output) == "table" and table_to_string(output) or tostring(output)
+    assert(output_str == expected_output_str, "Test failed: " .. input .. " => " .. output_str .. ", expected: " .. expected_output_str)
+    print("Test passed: " .. input .. " => " .. output_str)
 end
 
 
--- Run some test cases
 test_case("1", 1)  -- 1
 test_case("2 1 pop", 2) -- 2
+test_case("[1 1]", {1, 1})
+test_case("[1 2 3] map+", {2, 3, 4})
 test_case("3 4 +", 7)  -- 3 + 4 = 7
 test_case("5 2 -", 3)  -- 5 - 2 = 3
 test_case("2 3 *", 6)  -- 2 * 3 = 6
-test_case("8 2 /", 4)  -- 8 / 2 = 4
+test_case("8 2 /", 4.0)  -- 8 / 2 = 4
 test_case("2 3 4 + *", 14)  -- 2 * (3 + 4) = 14
 test_case("5 2 3 + 4 + +", 14)  -- 5 + 2 + 3 + 4 = 14
 test_case("7 2 + 3 4 + +", 16)  -- 7 + 2 + 3 + 4 = 16
 test_case("5 2 - 3 4 * +", 15)  -- (5 - 2) + (3 * 4) = 15
-test_case("8 2 / 3 4 * +", 16)  -- (8 / 2) + (3 * 4) = 16
\ No newline at end of file
+test_case("8 2 / 3 4 * +", 16.0)  -- (8 / 2) + (3 * 4) = 16
\ No newline at end of file