testez icon indicating copy to clipboard operation
testez copied to clipboard

Inconsistent value comparisons

Open astrealRBLX opened this issue 4 years ago • 1 comments

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 avatar Jul 30 '21 04:07 astrealRBLX

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)

astrealRBLX avatar Jul 30 '21 04:07 astrealRBLX