Roblox / testez

BDD-style test and assertion library for Roblox Lua
https://roblox.github.io/testez/
Apache License 2.0
185 stars 58 forks source link

Inconsistent value comparisons #164

Open astrealRBLX opened 3 years ago

astrealRBLX commented 3 years ago

This is definitely a bug. I'm writing unit tests for my math interpreter and when attempting the following test it fails:

local lexer = Lexer.new('4.2 - 3.8')
lexer:tokenize()
local tree = Parser.new(lexer):parse()
local value = Interpreter:visit(tree)

expect(value).to.be.equal(0.4)

The error: image

The values are identical. Of the 20+ tests I'm running this is the only one that fails. I'm really not sure why it is. I've triple checked my interpreter and the value is always returned correctly. This error only appears to occur with the subtract binary operation.

astrealRBLX commented 3 years ago

After more testing it appears the number is not exactly 0.4 as testing near fixes it. I'm leaving this issue open however as I would like to see TestEZ internally resolve this (doing an equal check on decimals should check near to something like 10^-10) rather than leaving developers questioning their sanity.

expect(value).to.be.near(0.4, 0.0000000001)