Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: test/webkit/comparison-operators-greater.js

Issue 18068003: Migrated several tests from blink to V8 repository. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
6 // are met:
7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24 description("test that comparison operators work correctly.")
25
26 function makeTest(start, end, expression, relationship, override, invert) {
27 var resultValue = eval(relationship + expression + 0) || !!override;
28 if (invert)
29 resultValue = !resultValue;
30 var expr = start + expression + end;
31 var result = [];
32 function func(content) { var f = new Function(content); f.toString = functio n(){ return content}; return f; }
33 result.push([new func("return " + expr + ";"), resultValue]);
34 result.push([new func("if (" + expr + ") return true; return false;"), resul tValue]);
35 result.push([new func("var k = 0; while (" + expr + ") if (k++) return true; return false;"), resultValue]);
36 result.push([new func("var k = 0; for (; " + expr + "; ) if (k++) return tru e; return false;"), resultValue]);
37 return result;
38 }
39 function doTest(lhs, rhs, relationship) {
40 var expressionParts = [["(",")"],["(", ") || 1", true],["(", ") && 1"],["(", ") || 1", true],["1 || (",")", true],["1 && (",")"]];
41 var expressions = [];
42 var tests = [];
43 for (var i = 0; i < expressionParts.length; i++) {
44 var start = expressionParts[i][0] + lhs;
45 var end = String(rhs) + expressionParts[i][1];
46 tests.push.apply(tests, makeTest(start, end, ">", relationship, expressi onParts[i][2]));
47 tests.push.apply(tests, makeTest(start, end, ">=", relationship, express ionParts[i][2]));
48 }
49 for (var i = 0; i < tests.length; i++) {
50 if ((r=tests[i][0]()) == tests[i][1])
51 testPassed(tests[i][0] + " is " + tests[i][1]);
52 else
53 testFailed(tests[i][0] + " is " + r + " and should be " + tests[i][1 ] + ".");
54 }
55 }
56
57 var letterA = "a";
58 var letterB = "b";
59 var letter0 = "0";
60
61 var One = 1;
62 var Zero = 0;
63 doTest('"a"', '"b"', -1);
64 doTest('"a"', '"a"', 0);
65 doTest('"b"', '"a"', 1);
66 doTest('letterA', '"b"', -1);
67 doTest('letterA', '"a"', 0);
68 doTest('"b"', '"a"', 1);
69 doTest('letterA', '"b"', -1);
70 doTest('letterA', 'letterA', 0);
71 doTest('"b"', 'letterA', 1);
72 doTest('"a"', '"b"', -1);
73 doTest('"a"', 'letterA', 0);
74 doTest('"b"', 'letterA', 1);
75
76 doTest('"a"', '0', NaN);
77 doTest('0', '"a"', NaN);
78
79 doTest('0', '"0"', 0);
80 doTest('Zero', 'letter0', 0);
81 doTest('0', 'letter0', 0);
82 doTest('Zero', '"0"', 0);
83 doTest('-1', '"0"', -1);
84 doTest('1', '"0"', 1);
85 doTest('0', '"-1"', 1);
86 doTest('0', '"1"', -1);
87
88 doTest('letterA', '0', NaN);
89 doTest('letterA', '"a"', 0);
90 doTest('0', '"a"', NaN);
91 doTest('letterA', 'letterA', 0);
92 doTest('0', 'letterA', NaN);
93 doTest('"a"', 'letterA', 0);
94 doTest('0', 'letterA', NaN);
95
96
97 doTest('0', '1', -1);
98 doTest('0', '0', 0);
99 doTest('1', '0', 1);
100 doTest('Zero', '1', -1);
101 doTest('Zero', '0', 0);
102 doTest('1', 'Zero', 1);
103 doTest('0', 'One', -1);
104 doTest('One', '0', 1);
105
106 shouldBeTrue("0 >= 0");
107 shouldBeTrue("1 >= 0");
108 shouldBeTrue("1 >= 1");
109 shouldBeTrue("1 > 0");
110 shouldBeFalse("0 >= 1");
111 shouldBeFalse("1 >= 2");
112 shouldBeFalse("1 > 1");
113 shouldBeFalse("1 > 2");
114
115 shouldBeTrue("if (0 >= 0 || 0) true; else false");
116 shouldBeTrue("if (1 >= 0 || 0) true; else false");
117 shouldBeTrue("if (1 >= 1 || 0) true; else false");
118 shouldBeTrue("if (0 < 1 || 0) true; else false");
119 shouldBeFalse("if (0 >= 1 || 0) true; else false");
120 shouldBeFalse("if (1 >= 2 || 0) true; else false");
121 shouldBeFalse("if (1 < 1 || 0) true; else false");
122 shouldBeFalse("if (2 < 1 || 0) true; else false");
123
124 shouldBeTrue("0.5 >= 0");
125 shouldBeTrue("1.5 >= 0");
126 shouldBeTrue("1.5 >= 1");
127 shouldBeTrue("1.5 > 0");
128 shouldBeFalse("0.5 >= 1");
129 shouldBeFalse("1.5 >= 2");
130 shouldBeTrue("1.5 > 1");
131 shouldBeFalse("1.5 > 2");
132
133 shouldBeTrue("if (0.5 >= 0 || 0) true; else false");
134 shouldBeTrue("if (1.5 >= 0 || 0) true; else false");
135 shouldBeTrue("if (1.5 >= 1 || 0) true; else false");
136 shouldBeTrue("if (0 < 1.5 || 0) true; else false");
137 shouldBeFalse("if (0.5 >= 1 || 0) true; else false");
138 shouldBeFalse("if (1.5 >= 2 || 0) true; else false");
139 shouldBeTrue("if (1 < 1.5 || 0) true; else false");
140 shouldBeFalse("if (2 < 1.5 || 0) true; else false");
141
142 var zero = 0;
143 var one = 1;
144 var two = 2;
145 var p5 = 0.5;
146 var p15 = 1.5;
147
148
149 shouldBeTrue("zero >= zero");
150 shouldBeTrue("1 >= zero");
151 shouldBeTrue("1 >= 1");
152 shouldBeTrue("1 > zero");
153 shouldBeFalse("zero >= 1");
154 shouldBeFalse("1 >= 2");
155 shouldBeFalse("1 > 1");
156 shouldBeFalse("1 > 2");
157
158 shouldBeTrue("if (zero >= zero || 0) true; else false");
159 shouldBeTrue("if (1 >= zero || zero) true; else false");
160 shouldBeTrue("if (1 >= 1 || zero) true; else false");
161 shouldBeTrue("if (zero < 1 || zero) true; else false");
162 shouldBeFalse("if (zero >= 1 || zero) true; else false");
163 shouldBeFalse("if (1 >= 2 || zero) true; else false");
164 shouldBeFalse("if (1 < 1 || zero) true; else false");
165 shouldBeFalse("if (2 < 1 || zero) true; else false");
166
167 shouldBeTrue("p5 >= 0");
168 shouldBeTrue("p15 >= 0");
169 shouldBeTrue("p15 >= 1");
170 shouldBeTrue("p15 > 0");
171 shouldBeFalse("p5 >= 1");
172 shouldBeFalse("p15 >= 2");
173 shouldBeTrue("p15 > 1");
174 shouldBeFalse("p15 > 2");
175
176 shouldBeTrue("if (p5 >= 0 || 0) true; else false");
177 shouldBeTrue("if (p15 >= 0 || 0) true; else false");
178 shouldBeTrue("if (p15 >= 1 || 0) true; else false");
179 shouldBeTrue("if (0 < p15 || 0) true; else false");
180 shouldBeFalse("if (p5 >= 1 || 0) true; else false");
181 shouldBeFalse("if (p15 >= 2 || 0) true; else false");
182 shouldBeTrue("if (1 < p15 || 0) true; else false");
183 shouldBeFalse("if (2 < p15 || 0) true; else false");
184
185
186 shouldBeTrue("zero >= zero");
187 shouldBeTrue("one >= zero");
188 shouldBeTrue("one >= one");
189 shouldBeTrue("one > zero");
190 shouldBeFalse("zero >= one");
191 shouldBeFalse("one >= two");
192 shouldBeFalse("one > one");
193 shouldBeFalse("one > two");
194
195 shouldBeTrue("if (zero >= zero || 0) true; else false");
196 shouldBeTrue("if (one >= zero || zero) true; else false");
197 shouldBeTrue("if (one >= one || zero) true; else false");
198 shouldBeTrue("if (zero < one || zero) true; else false");
199 shouldBeFalse("if (zero >= one || zero) true; else false");
200 shouldBeFalse("if (one >= two || zero) true; else false");
201 shouldBeFalse("if (one < one || zero) true; else false");
202 shouldBeFalse("if (two < one || zero) true; else false");
203
204 shouldBeTrue("p5 >= 0");
205 shouldBeTrue("p15 >= 0");
206 shouldBeTrue("p15 >= one");
207 shouldBeTrue("p15 > 0");
208 shouldBeFalse("p5 >= one");
209 shouldBeFalse("p15 >= two");
210 shouldBeTrue("p15 > one");
211 shouldBeFalse("p15 > two");
212
213 shouldBeTrue("if (p5 >= 0 || 0) true; else false");
214 shouldBeTrue("if (p15 >= 0 || 0) true; else false");
215 shouldBeTrue("if (p15 >= one || 0) true; else false");
216 shouldBeTrue("if (0 < p15 || 0) true; else false");
217 shouldBeFalse("if (p5 >= one || 0) true; else false");
218 shouldBeFalse("if (p15 >= two || 0) true; else false");
219 shouldBeTrue("if (one < p15 || 0) true; else false");
220 shouldBeFalse("if (two < p15 || 0) true; else false");
221
222 shouldBeFalse(" 0 > NaN");
223 shouldBeFalse(" NaN > NaN");
224 shouldBeFalse(" 0 >= NaN");
225 shouldBeFalse(" NaN >= NaN");
226 shouldBeFalse(" 0.5 > NaN");
227 shouldBeFalse(" NaN > NaN");
228 shouldBeFalse(" 0.5 >= NaN");
229 shouldBeFalse(" NaN >= NaN");
230 shouldBeFalse(" zero > NaN");
231 shouldBeFalse("zero >= NaN");
232 shouldBeFalse(" NaN >= NaN");
233 shouldBeFalse(" p5 > NaN");
234 shouldBeFalse("NaN > NaN");
235 shouldBeFalse("p5 >= NaN");
236 shouldBeFalse("NaN >= NaN");
237
238
239 shouldBeFalse("if ( 0 > NaN) true; else false;");
240 shouldBeFalse("if ( NaN > NaN) true; else false;");
241 shouldBeFalse("if ( 0 >= NaN) true; else false;");
242 shouldBeFalse("if ( NaN >= NaN) true; else false;");
243 shouldBeFalse("if ( 0.5 > NaN) true; else false;");
244 shouldBeFalse("if ( NaN > NaN) true; else false;");
245 shouldBeFalse("if ( 0.5 >= NaN) true; else false;");
246 shouldBeFalse("if ( NaN >= NaN) true; else false;");
247 shouldBeFalse("if ( zero > NaN) true; else false;");
248 shouldBeFalse("if (zero >= NaN) true; else false;");
249 shouldBeFalse("if ( NaN >= NaN) true; else false;");
250 shouldBeFalse("if ( p5 > NaN) true; else false;");
251 shouldBeFalse("if (NaN > NaN) true; else false;");
252 shouldBeFalse("if (p5 >= NaN) true; else false;");
253 shouldBeFalse("if (NaN >= NaN) true; else false;");
OLDNEW
« no previous file with comments | « test/webkit/comparison-operators-expected.txt ('k') | test/webkit/comparison-operators-greater-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698