lean2/tests/lua/num1.lua
Leonardo de Moura d0bac61e74 fix(lua/numerics): bug in bindings, add more tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2013-11-17 11:02:44 -08:00

47 lines
1.4 KiB
Lua

assert(mpz(10) == mpz("10"))
assert(mpz(mpz(3)) == mpz("3"))
print(mpz(10) + mpz(3))
assert(mpz(10) + mpz(3) == mpz(13))
assert(mpz(10) + 2 == mpz(12))
assert(3 + mpz(15) == mpz(18))
assert(mpz(10) - mpz(3) == mpz(7))
assert(mpz(10) - 2 == mpz(8))
assert(3 - mpz(15) == -mpz(12))
assert(- mpz(15) == mpz("-15"))
assert(- mpz(15) == -mpz("15"))
assert(mpz(10) * mpz(3) == mpz(30))
assert(mpz(10) * 2 == mpz(20))
assert(3 * mpz(15) == mpz(45))
assert(mpz(3)^2 == mpz(9))
local a = -2
assert(not pcall(function() print(mpz(3)^a) end))
assert(mpz(3) < mpz(5))
assert(mpz(3) > mpz(1))
assert(mpq(3) == mpq("3"))
assert(mpq(3) == mpq(mpq(3)))
assert(mpq(3) == mpq(mpz(3)))
assert(mpq(0.5) == mpq(1)/2)
assert(mpq(0.4) ~= mpq(1)/2)
assert(mpq(10) + mpq(3) == mpq(13))
assert(mpq(10) + 2 == mpq(12))
assert(3 + mpq(15) == mpq(18))
assert(mpq(3) + mpz(15) == mpq(18))
assert(mpq(10) - mpq(3) == mpq(7))
assert(mpq(10) - 2 == mpq(8))
assert(3 - mpq(15) == -mpq(12))
assert(mpq(3) - mpz(15) == -mpq(12))
assert(mpq(10) * mpq(3) == mpq(30))
assert(mpq(10) * 2 == mpq(20))
assert(3 * mpq(15) == mpq(45))
assert(mpq(3) * mpz(15) == mpq(45))
assert(mpq(3)^2 == mpq(9))
print(mpq(0.5)^2)
assert(mpq(0.5)^2 == mpq(1)/4)
local a = -2
assert(not pcall(function() print(mpq(3)^a) end))
assert(mpq(10) / mpq(3) == mpq("10/3"))
assert(mpq(10) / 2 == mpq(5))
assert(3 / mpq(15) == mpq(1)/5)
assert(mpq(3) / mpz(15) == mpq("1/5"))
assert(mpq(3) < mpq(5))
assert(mpq(3) > mpq(1))