Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit db7bdcd

Browse files
committed
[Bug 14593] com.livecode.arithmetic: Improve tests for mod operator
Test the invariant that the "mod" operator is supposed to conform to directly. For an operation: x mod y The following must hold: z = x div y = trunc(x / y) r = x mod y y*z + r = x
1 parent 1be425d commit db7bdcd

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

tests/lcb/stdlib/arithmetic.lcb

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public handler TestDivide()
110110
test "divide (operator, int)" when 30 / tInt = 6
111111

112112
divide tInt by 2
113-
test diagnostic "Expecting floor"
113+
test diagnostic "Expecting trunc"
114114
broken test "divide (syntax, int)" when tInt = 2 because "bug 14592"
115115

116116
variable tReal as Real
@@ -126,11 +126,46 @@ public handler TestDivide()
126126
test "divide (operator, number)" when tNumber / 8 = 2.5
127127
end handler
128128

129-
public handler TestMod()
130-
test "mod (+ve, +ve)" when 10 mod 3 = 1
131-
broken test "mod (-ve, +ve)" when -10 mod 3 = 2 because "bug 14593"
132-
broken test "mod (+ve, -ve)" when 10 mod -3 = -2 because "bug 14593"
133-
test "mod (-ve, -ve)" when -10 mod -3 = -1
129+
private handler ModInvariantDiagnostic(in pX, in pY, in pZ, in pR)
130+
test diagnostic pX formatted as string && "mod" && pY formatted as string
131+
test diagnostic pY formatted as string && "*" && \
132+
pZ formatted as string && "+" && \
133+
pR formatted as string && "=" && \
134+
(pY * pZ + pR) formatted as string
135+
end handler
136+
137+
private handler ModInvariantInteger(in pX as Integer, in pY as Integer) \
138+
returns Boolean
139+
variable tZ as Integer
140+
variable tR as Integer
141+
put (pX / pY) into tZ
142+
put (pX mod pY) into tR
143+
144+
ModInvariantDiagnostic(pX, pY, tZ, tR)
145+
return (pY * tZ + tR) is pX
146+
end handler
147+
148+
private handler ModInvariantReal(in pX as Real, in pY as Real) \
149+
returns Boolean
150+
variable tZ as Real
151+
variable tR as Real
152+
put the trunc of (pX / pY) into tZ -- because there is no "div" operator
153+
put (pX mod pY) into tR
154+
155+
ModInvariantDiagnostic(pX, pY, tZ, tR)
156+
return (pY * tZ + tR) is pX
157+
end handler
158+
159+
public handler TestModInteger()
160+
broken test "mod int (+ve, +ve)" when ModInvariantInteger(10, 3) because "bug 14592"
161+
broken test "mod (-ve, +ve)" when ModInvariantInteger(-10, 3) because "bug 14592"
162+
broken test "mod int (+ve, -ve)" when ModInvariantInteger(10, -3) because "bug 14592"
163+
broken test "mod int (-ve, -ve)" when ModInvariantInteger(-10, -3) because "bug 14592"
164+
165+
test "mod real (+ve, +ve)" when ModInvariantReal(16, 3.75)
166+
test "mod real (-ve, +ve)" when ModInvariantReal(-16, 3.75)
167+
test "mod real (+ve, -ve)" when ModInvariantReal(16, -3.75)
168+
test "mod real (-ve, -ve)" when ModInvariantReal(-16, -3.75)
134169
end handler
135170

136171
public handler TestWrap()

0 commit comments

Comments
 (0)