summaryrefslogtreecommitdiffstats
path: root/docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-10-29 18:37:26 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-11 12:20:32 +0000
commit16922b73bf17b2f23148438957cd3d18542075f4 (patch)
tree20355189f7f5f2262e7fe31be0b7119b07182ab1 /docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md
parent77ca03276ea3bb12873a1b69b1726d4e99f8dead (diff)
Docs reorganization and update
Docs reorganization and update using the latest afb-test improvments and try to make it clearer. Change-Id: If022cdb46364ef250361bdcd420d45b360f10a2e Signed-off-by: Romain Forlot <romain.forlot@iot.bzh> (cherry picked from commit 2f3654275e44f9719818a848da9a0b576d5a1b53)
Diffstat (limited to 'docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md')
-rw-r--r--docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md63
1 files changed, 63 insertions, 0 deletions
diff --git a/docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md b/docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md
new file mode 100644
index 0000000..6282755
--- /dev/null
+++ b/docs/Reference/LuaUnitAssertionFunctions/0_GeneralAssertions.md
@@ -0,0 +1,63 @@
+# General Assertions
+
+* **_AFT.assertEquals(actual, expected)**
+
+ Assert that two values are equal.
+
+ For tables, the comparison is a deep comparison :
+
+ * number of elements must be the same
+ * tables must contain the same keys
+ * each key must contain the same values. The values are also compared recursively with deep comparison.
+
+ LuaUnit provides other table-related assertions, see [Table assertions](http://luaunit.readthedocs.io/en/luaunit_v3_2_1/#assert-table)
+
+ ```lua
+ _AFT.assertEquals("string", "string")
+ ```
+
+* **_AFT.assertNotEquals(actual, expected)**
+
+ Assert that two values are different. The assertion fails if the two values are identical.
+
+ It also uses table deep comparison.
+
+ ```lua
+ _AFT.assertNotEquals("string", "Another string")
+ ```
+
+* **_AFT.assertAlmostEquals(actual, expected, margin)**
+
+ Assert that two floating point numbers are almost equal.
+
+ When comparing floating point numbers, strict equality does not work.
+ Computer arithmetic is so that an operation that mathematically yields
+ 1.00000000 might yield 0.999999999999 in lua . That’s why you need an
+ almost equals comparison, where you specify the error margin.
+
+ ```lua
+ -- convert pi/6 radian to 30 degree
+ pi_div_6_deg_calculated = math.deg(math.pi/6)
+ pi_div_6_deg_expected = 30
+
+ -- convert pi/3 radian to 60 degree
+ pi_div_3_deg_calculated = math.deg(math.pi/3)
+ pi_div_3_deg_expected = 60
+
+ -- check absolute error: it is not constant
+ print( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / lu.EPS ) -- prints: 16
+ print( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / lu.EPS ) -- prints: 32
+
+ -- Better use relative error:
+ print( ( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / pi_div_6_deg_expected) / lu.EPS ) -- prints: 0.53333
+ print( ( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / pi_div_3_deg_expected) / lu.EPS ) -- prints: 0.53333
+
+ -- relative error is constant. Assertion can take the form of:
+ assertAlmostEquals( (pi_div_6_deg_expected - pi_div_6_deg_calculated) / pi_div_6_deg_expected, lu.EPS )
+ assertAlmostEquals( (pi_div_3_deg_expected - pi_div_3_deg_calculated) / pi_div_3_deg_expected, lu.EPS )
+ ```
+
+* **_AFT.assertNotAlmostEquals(actual, expected, margin)**
+
+ Assert that two floating point numbers are not almost equal.
+ \ No newline at end of file