Module:ScribuntoUnit/doc: Difference between revisions

Content deleted Content added
Tests: tweak parts about testing XML tags like <ref>
+ assertWithinDelta
Line 1:
This module provides [[unit test]]s for other [[WP:Lua|Lua]] modules. To test a module, you must create a separate test module, usually located at <code>Module:''Module name''/testcasestesttilfeller</code>. The module is tested with the ScribuntoUnit module, which verifies that the operations defined in the test module produce the expected results.
 
== Test module structure ==
Line 54:
=== assertEquals ===
 
This tests whether the first parameter is equal to the second parameter. If both parameters are numbers, the values are instead compared using {{code|assertWithinDelta}} with delta 1e-8 (0.00000001) since numbers are represented as [[floating point]]s with limited precision.
 
<source lang="lua">
self:assertEquals(4, calculator.add(2, 2))
</source>
 
=== assertWithinDelta ===
 
For two numbers, this tests whether the first is within a given distance (delta) from the second. This is useful to compare floating point numbers. While
1/3 == 9/3 evaluates as false, the two numbers can be compared as being within a very small distance (delta) of each other.
 
<source lang="lua">
self:assertEquals(1/3, calculator.divide(9/3), 1e-10)
</source>