Content deleted Content added
No edit summary |
m Reverted edit by 103.31.11.39 (talk) to last version by Uzume |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 45:
<syntaxhighlight lang="lua">
self:assertEquals("expected value", myModule.someCall(123), "The call to myModule.someCall(123) didn't return the expected value.")
</syntaxhighlight>
=== fail ===
<syntaxhighlight lang="lua">
self:fail(message)
</syntaxhighlight>
Unconditionally fails a test.
<syntaxhighlight lang="lua">
self:fail("Test failed because of X.")
</syntaxhighlight>
Line 105 ⟶ 117:
<syntaxhighlight lang="lua">
self:assertEquals(4, calculator.add(2, 2))
</syntaxhighlight>
=== assertNotEquals ===
<syntaxhighlight lang="lua">
self:assertNotEquals(expected, actual, message)
</syntaxhighlight>
This tests whether the first parameter is not equal to the second parameter. If both parameters are numbers, the values are instead compared using {{code|assertNotWithinDelta}} with delta 1e-8 (0.00000001) since numbers are represented as [[floating point]]s with limited precision.
<syntaxhighlight lang="lua">
self:assertNotEquals(5, calculator.add(2, 2))
</syntaxhighlight>
Line 117 ⟶ 141:
<syntaxhighlight lang="lua">
self:assertWithinDelta(0.1, calculator.subtract(0.3, 0.2), 1e-10)
</syntaxhighlight>
=== assertNotWithinDelta ===
<syntaxhighlight lang="lua">
self:assertNotWithinDelta(expected, actual, delta, message)
</syntaxhighlight>
For two numbers, this tests whether the first is not within a given distance (delta) from the second. This test is the inverse of [[#assertWithinDelta|assertWithinDelta]].
<syntaxhighlight lang="lua">
self:assertNotWithinDelta(0.1, calculator.subtract(0.3, 0.1), 1e-10)
</syntaxhighlight>
Line 183 ⟶ 219:
* [[Module:UnitTests]]
<includeonly>{{sandbox other||
[[Category:Modules for test tools]]
}}</includeonly>
|