22 lines
438 B
Elixir
22 lines
438 B
Elixir
defmodule LytlangTest do
|
|
use ExUnit.Case
|
|
doctest Lytlang
|
|
|
|
test "arithmetic" do
|
|
[
|
|
{"2 + 3 + 8", 13},
|
|
{"2 * 3 + 8", 14},
|
|
{"2 + 3 * 8", 26},
|
|
{"(2 + 3) * 8", 40},
|
|
{"2 * (3 + 8)", 22},
|
|
{"2 + (3 * 8)", 26},
|
|
{"8 - 3", 5},
|
|
{"8 / 4", 2.0},
|
|
{"a = 8\na + 9", 17},
|
|
{"2 + 3", 5}
|
|
]
|
|
|> Enum.map(fn {string, val} ->
|
|
assert Lytlang.eval(string) == val
|
|
end)
|
|
end
|
|
end
|