Algorithms, Blockchain and Cloud

Unit Test Methods should support float numbers comparisons with EPSILON


VBSUnit is a VBScript Unit Testing Framework. Currently, it supports the following test methods:

  • assert_equal expected, actual, message
  • assert_not_equal expected, actual, message
  • assert_match expected_pattern, actual, message regex
  • assert_true asserted, message
  • assert_false asserted, message

vbscript

However, for floating number, the direct comparisons are often considered as strict and wrong. For example,

a = 0.15 + 0.15
b = 0.2 + 0.1
If a = b Then
    WScript.Echo "Equal"
Else
    WScript.Echo "Not Equal"
End If

This will print “Not Equal”. The floating numbers should support a EPSILON constant (which is also known as the margin error).

So it becomes:

a = 0.15 + 0.15
b = 0.2 + 0.1
If Abs(a - b) <= 1e-4 Then
    WScript.Echo "Equal"
Else
    WScript.Echo "Not Equal"
End If

This should be reflected in the testing methods. I am proposing the methods assert_equal_eps and assert_not_equal_eps to be added to the Github repro.

–EOF (The Ultimate Computing & Technology Blog) —

263 words
Last Post: Quick Tutorial to 64-bit Tablacus Scripting Control
Next Post: Does CloudFlare Cache 403 and 503 By Default?

The Permanent URL is: Unit Test Methods should support float numbers comparisons with EPSILON (AMP Version)

Exit mobile version