forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfinity.livecodescript
More file actions
202 lines (172 loc) · 7.11 KB
/
Copy pathinfinity.livecodescript
File metadata and controls
202 lines (172 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
script "CoreMathInfinity"
/*
Copyright (C) 2018 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
private function StringEqualToInf pNumber, pNegative
local tInfPlusJunk
put "inf plus some junk" into tInfPlusJunk
if pNegative then
put "-" before tInfPlusJunk
end if
return offset(pNumber, tInfPlusJunk) is 1
end StringEqualToInf
command TestInfinityString
TestAssert "inf is not padded when converted to string", \
StringEqualToInf("inf"+0, false)
TestAssert "-inf is not padded when converted to string", \
StringEqualToInf("-inf"+0, true)
end TestInfinityString
private command _TestBinaryOperator pLeft, pRight, pOperator, pExpected
local tResult, tExpr
switch pOperator
case "plus"
put pLeft + pRight into tResult
break
case "minus"
put pLeft - pRight into tResult
break
case "times"
put pLeft * pRight into tResult
break
case "over"
put pLeft / pRight into tResult
break
case "to the power of"
put pLeft ^ pRight into tResult
break
case "added to"
add pLeft to pRight
put pRight into tResult
break
case "subtracted from"
subtract pLeft from pRight
put pRight into tResult
break
case "multiplied by"
multiply pLeft by pRight
put pLeft into tResult
break
case "divided by"
divide pLeft by pRight
put pLeft into tResult
break
case "div"
put pLeft div pRight into tResult
break
case "mod"
put pLeft mod pRight into tResult
break
case "wrap"
put pLeft wrap pRight into tResult
break
default
put pOperator & "(" & pLeft & "," & pRight & ")" into tExpr
put value(tExpr) into tResult
break
end switch
if tExpr is empty then
TestAssert "Result of" && pLeft && pOperator && pRight && "is" && pExpected, \
tResult is pExpected
else
TestAssert "Result of" && tExpr && "is" && pExpected, \
tResult is pExpected
end if
end _TestBinaryOperator
on TestInfinityBinaryOperators
_TestBinaryOperator infinity, 1, "plus", infinity
_TestBinaryOperator -infinity, 1, "plus", -infinity
_TestBinaryOperator infinity, 1, "minus", infinity
_TestBinaryOperator -infinity, 1, "minus", -infinity
_TestBinaryOperator 1, infinity, "minus", -infinity
_TestBinaryOperator 1, -infinity, "minus", infinity
_TestBinaryOperator infinity, 2, "times", infinity
_TestBinaryOperator -infinity, 2, "times", -infinity
_TestBinaryOperator infinity, 2, "over", infinity
_TestBinaryOperator -infinity, 2, "over", -infinity
_TestBinaryOperator 2, infinity, "over", 0
_TestBinaryOperator 2, -infinity, "over", 0
_TestBinaryOperator infinity, 2, "to the power of", infinity
_TestBinaryOperator -infinity, 2, "to the power of", infinity
_TestBinaryOperator -infinity, 3, "to the power of", -infinity
_TestBinaryOperator 2, infinity, "to the power of", infinity
_TestBinaryOperator 2, -infinity, "to the power of", 0
_TestBinaryOperator infinity, 1, "added to", infinity
_TestBinaryOperator -infinity, 1, "added to", -infinity
_TestBinaryOperator 1, infinity, "added to", infinity
_TestBinaryOperator 1, -infinity, "added to", -infinity
_TestBinaryOperator 1, infinity, "subtracted from", infinity
_TestBinaryOperator 1, -infinity, "subtracted from", -infinity
_TestBinaryOperator infinity, 1, "subtracted from", -infinity
_TestBinaryOperator -infinity, 1, "subtracted from", infinity
_TestBinaryOperator infinity, 2, "multiplied by", infinity
_TestBinaryOperator -infinity, 2, "multiplied by", -infinity
_TestBinaryOperator 2, infinity, "multiplied by", infinity
_TestBinaryOperator 2, -infinity, "multiplied by", -infinity
_TestBinaryOperator infinity, 2, "divided by", infinity
_TestBinaryOperator -infinity, 2, "divided by", -infinity
_TestBinaryOperator 2, infinity, "divided by", 0
_TestBinaryOperator 2, -infinity, "divided by", 0
_TestBinaryOperator infinity, 2, "div", infinity
_TestBinaryOperator -infinity, 2, "div", -infinity
_TestBinaryOperator 2, infinity, "div", 0
_TestBinaryOperator 2, -infinity, "div", 0
_TestBinaryOperator 2, infinity, "mod", 2
_TestBinaryOperator 2, -infinity, "mod", 2
_TestBinaryOperator 2, infinity, "wrap", 2
_TestBinaryOperator 2, -infinity, "wrap", 2
_TestBinaryOperator 1, infinity, "atan2", 0
_TestBinaryOperator infinity, 1, "atan2", pi/2
_TestBinaryOperator infinity, infinity, "atan2", pi/4
_TestBinaryOperator 1, -infinity, "atan2", pi
_TestBinaryOperator -infinity, 1, "atan2", -pi/2
_TestBinaryOperator -infinity, -infinity, "atan2", -3*pi/4
end TestInfinityBinaryOperators
private command _TestUnaryOperator pOperator, pOperand, pExpected
local tResult, tExpr
put pOperator & "(" & pOperand & ")" into tExpr
put value(tExpr) into tResult
TestAssert tExpr && "is" && pExpected, \
tResult is pExpected
end _TestUnaryOperator
on TestInfinityUnaryOperators
_TestUnaryOperator "atan", infinity, pi/2
_TestUnaryOperator "atan", -infinity, -pi/2
_TestUnaryOperator "exp", infinity, infinity
_TestUnaryOperator "exp", -infinity, 0
_TestUnaryOperator "exp1", infinity, infinity
_TestUnaryOperator "exp1", -infinity, -1
_TestUnaryOperator "exp2", infinity, infinity
_TestUnaryOperator "exp2", -infinity, 0
_TestUnaryOperator "exp10", infinity, infinity
_TestUnaryOperator "exp10", -infinity, 0
_TestUnaryOperator "ln", infinity, infinity
_TestUnaryOperator "ln1", infinity, infinity
_TestUnaryOperator "log2", infinity, infinity
_TestUnaryOperator "log10", infinity, infinity
_TestUnaryOperator "sqrt", infinity, infinity
end TestInfinityUnaryOperators
on TestInfinityNaryOperators
repeat for each item tItem in "sum,min,max,avg,median"
_TestUnaryOperator tItem, infinity, infinity
if the platform is "win32" then
TestSkip tItem & "(-inf) is -inf", "Bug 22038"
else
_TestUnaryOperator tItem, -infinity, -infinity
end if
end repeat
_TestBinaryOperator 2, infinity, "min", 2
_TestBinaryOperator 2, -infinity, "min", -infinity
_TestBinaryOperator 2, infinity, "max", infinity
_TestBinaryOperator 2, -infinity, "max", 2
TestAssert "Result of median(2,inf,inf) is inf", median(2,infinity,infinity) is infinity
TestAssert "Result of median(2,-inf,-inf) is -inf", median(2,-infinity,-infinity) is -infinity
end TestInfinityNaryOperators