2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
7 window.runTests = function(log) {
8 var run = window.calculatorTestRun.create();
10 // ---------------------------------------------------------------------------
11 // Test fixes for <http://crbug.com/156448>:
13 run.test('Twenty eight can be divided by three', '28 / 3 = [9.3333333]');
14 run.test('Twenty nine can be divided by three', '29 / 3 = [9.6666667]');
15 run.test('Thirty can be divided by three', '30 / 3 = [10]');
16 run.test('Thirty one can be divided by three', '31 / 3 = [10.333333]');
17 run.test('Thirty two can be divided by three', '32 / 3 = [10.666667]');
18 run.test('Thirty three can be divided by three', '33 / 3 = [11]');
20 // ---------------------------------------------------------------------------
21 // Test fixes for <http://crbug.com/156449>:
23 // run.test('Equals without operator results in operand value',
26 // run.test('Operations without operands uses default operands',
27 // '2 + = [[2 _ 2][_ + 2][][4 _ 4]]');
29 // TODO(dharcourt): Test the display for the expected output.
30 // run.test('Successive operators replace each other.',
31 // '123 + - * / [123 / _] and no previous [* + *]');
33 // ---------------------------------------------------------------------------
34 // Test fixes for <http://crbug.com/156450>:
36 // run.test('Operand can be erased and replaced',
37 // '123 + 456 < < < < 789 = [789]');
39 // TODO(dharcourt): Test the display for the expected output.
40 // run.test('Operators can be erased and replaced.',
41 // '123 + 456 < < < < < * 2 = [246]');
43 // TODO(dharcourt): Test the display for the expected output.
44 // run.test('Erase is ignored after equals.', '123 + 456 = < [579]');
45 // run.test('Erase is ignored after zero result.', '123 - 123 = < [9]');
47 // TODO(dharcourt): Test the display for the expected output.
48 // run.test('Erasing an operand makes it blank.',
49 // '123 + 456 < < < [_ + _]');
51 // ---------------------------------------------------------------------------
52 // Test fixes for <http://crbug.com/156451>:
54 // run.test('Negation applies to zero', '~ [[-0]]');
55 // run.test('Negation applies before input', '~ 123 = [[-123]]');
56 // run.test('Negation applies after input is erased',
57 // '123 < < < ~ 456 [[-456]]');
58 // run.test('Negation is preserved when input is erased',
59 // '123 ~ < < < 456 [[-456]]');
60 // run.test('Negation supports small values',
61 // '0.0000001 ~ [[-0.0000001]]');
63 // run.test('Addition resets negated zeros', '~ + [_ + [0]]');
64 // run.test('Subtraction resets negated zeros', '~ - [_ - [0]]');
65 // run.test('Multiplication resets negated zeros', '~ * [_ * [0]]');
66 // run.test('Division resets negated zeros', '~ / [_ / [0]]');
67 // run.test('Equals resets negated zeros', '~ = [0 _ [0]]');
69 // ---------------------------------------------------------------------------
70 // Test fixes for <http://crbug.com/156452>:
72 // TODO(dharcourt): Test the display for the expected output.
73 // TODO(dharcourt): Make the test utilities support 'error'.
74 // run.test('Errors results are spelled out', '1 / 0 = [[error]]');
75 // run.test('Addition treats errors as zero',
76 // '1 / 0 = [error] + [0 + [0]] 123 = [123]');
77 // run.test('Subtraction treats errors as zero',
78 // '1 / 0 = [error] - [0 - [0]] 123 = [-123]');
79 // run.test('Multiplication treats errors as zero',
80 // '1 / 0 = [error] * [0 * [0]] 123 = [0]');
81 // run.test('Division treats errors as zero',
82 // '1 / 0 = [error] / [0 / [0]] 123 = [0]');
83 // run.test('Equals treats errors as zero',
84 // '1 / 0 = [error] = [0]');
86 // ---------------------------------------------------------------------------
87 // Test fixes for <http://crbug.com/156453>:
89 // run.test('Common operations are reversible',
90 // '1 / 3 * 3 = [[1]]');
92 // run.test('Large numbers are displayed as exponentials',
93 // '12345678 * 10 = [[1.23456e8]]');
94 // run.test('Small numbers are displayed as exponentials',
95 // '0.0000001 / 10 = [[1e-8]]');
97 // ---------------------------------------------------------------------------
99 // TODO(dharcourt): Organize and beef up these tests.
100 // TODO(dharcourt): Test {nega,posi}tive {under,over}flows.
102 run.test("Initialization", function(controller) {
103 run.verify(null, controller.model.accumulator, 'Accumulator');
104 run.verify(null, controller.model.operator, 'Operator');
105 run.verify(null, controller.model.operand, 'Operand');
106 run.verify(null, controller.model.defaults.operator, 'Default Operator');
107 run.verify(null, controller.model.defaults.operand, 'Defaults Operand');
110 run.test("AC", '1 + 2 = [3] 4 A [[_ _ 0]]');
112 run.test("back", '1 + 2 < [_ + _] < [_ _ _] < [_ _ 0]');
113 // TODO(dharcourt@chromium.org): The previous lines should be:
114 // '1 + 2 < [_ + _] < [_ _ 0] < [_ _ 0]'
115 // TODO(dharcourt@chromium.org): Test more AC, C, back
117 run.test("Miscellaneous Test A",
118 '2 [_ _ 2] + [[2 _ 2][_ + _]] = [[2 _ 2][_ + _][][4 _ 4]]' +
119 ' + [[2 _ 2][_ + _][][4 _ 4][_ + _]]' +
120 ' = [[2 _ 2][_ + _][][4 _ 4][_ + _][][8 _ 8]]' +
121 ' = [[2 _ 2][_ + _][][4 _ 4][_ + _][][8 _ 8][][12 _ 12]]');
122 // TODO(dharcourt@chromium.org): The previous lines should be:
123 // '2 [_ _ 2] + [[2 _ 2][_ + _]] = [[2 _ 2][_ + 2][][4 _ 4]]' +
124 // ' + [[2 _ 2][_ + 2][][4 _ 4][_ + _]]' +
125 // ' = [[2 _ 2][_ + 2][][4 _ 4][_ + 4][][8 _ 8]]' +
126 // ' = [[2 _ 2][_ + 2][][4 _ 4][_ + 4][][8 _ 8][][12 _ 12]]');
128 run.test("Miscellaneous Test B", '2 * = [4] * [_ * _] = [16] = [64]');
130 run.test("Miscellaneous Test C", '0.020202020 [_ _ 0.0202020==]');
132 run.test("Miscellaneous Test D", '.2 [_ _ 0 .2]');
134 run.test("Miscellaneous Test E", '0.00000014 [_ _ 0.0000001=]');
136 run.test("Miscellaneous Test F", '0.10000004 [_ _ 0.1000000=]');
138 run.test("Miscellaneous Test G", '0.12312312 [_ _ 0.1231231=]');
140 run.test("Miscellaneous Test H", '1.231231234 [_ _ 1.2312312==]');
142 run.test("Miscellaneous Test I", '123.1231234 [_ _ 123.12312==]');
144 run.test("Miscellaneous Test J", '123123.1234 [_ _ 123123.12==]');
146 run.test("Miscellaneous Test K", '12312312.34 [_ _ 12312312.==]');
148 run.test("Miscellaneous Test L", '12312312.04 [_ _ 12312312.==]');
150 run.test("Miscellaneous Test M", '1231231234 [_ _ 12312312==]');
152 run.test("Miscellaneous Test N", '1 + 1 + [[1 _ 1][2 + 1][_ + _]] = [4]');
154 run.test("Miscellaneous Test O", '1 + 1 [_ + 1] 2 [_ + 1 2]');
156 run.test("Positive + Positive", '82959 + 4 = [82963]');
158 run.test("Positive + Negative", '123 + 456~ = [-333]');
160 run.test("Negative + Positive", '502~ + 385 = [-117]');
162 run.test("Negative + Negative", '4296~ + 32~ = [-4328]');
164 run.test("Positive + Zero", '23650 + 0 = [23650]');
166 run.test("Negative + Zero", '489719~ + 0 = [-489719]');
168 run.test("Zero + Positive", '0 + 4296 = [4296]');
170 run.test("Zero + Negative", '0 + 322~ = [-322]');
172 run.test("Zero + Zero", '0 + 0 = [0]');
174 run.test("Addition Chain",
175 '+ 5 + 3~ + [2] 2~ + [0] 1~ + [-1] 3 + [2] 0 = [2]');
177 run.test("Positive - Positive", '4534 - 327 = [4207]');
179 run.test("Subtraction Chain",
180 '- 5 - [-5] 3~ - [-2] 2~ - [0] 1~ - [1] 3 - [-2] 0 = [-2]');
182 run.test("Positive * Positive", '7459 * 660 = [4922940]');
184 run.test("Multiplication Chain",
185 '* 5 = [0] 1 * [1] 5 * [5] 2~ ' +
186 '* [-10] 1.5 * [-15] 1~ * [15] 0 = [0]');
188 run.test("Positive / Positive", '181 / 778 = [0.2326478]');
190 run.test("Division Chain",
191 '/ 5 = [0] 1 / [1] 5 / [0.2] 2~ ' +
192 '/ [-0.1] 0.1 / [-1] 1~ / [1] 0 = [E]');
194 run.test("Positive Decimal Plus Positive Decimal",
195 '7.48 + 8.2 = [15.68]');
197 run.test("Decimals with Leading Zeros",
198 '0.0023 + 0.082 = [0.0843]');
200 run.test("Addition and Subtraction Chain",
201 '4 + [4] 1055226 - [1055230] 198067 = [857163]');
203 run.test("Multiplication and Division Chain",
204 '580 * [580] 544 / [315520] 64 = [4930]');
206 run.test("Addition After Equals",
207 '5138 + 3351301 = [3356439] 550 + 62338 = [62888]');
209 run.test("Missing First Operand in Addition", '+ 9701389 = [9701389]');
211 run.test("Missing First Operand in Subtraction", '- 1770 = [-1770]');
213 run.test("Missing First Operand in Multiplication", '* 65146 = [0]');
215 run.test("Missing First Operand in Division", '/ 8 = [0]');
217 run.test("Missing Second Operand in Addition",
218 '28637 + = [[28637 _ 28637][_ + _][][57274 _ 57274]]');
219 // TODO(dharcourt): Previous line should be:
220 // '28637 + = [[28637 _ 28637][_ + 28637][][57274 _ 57274]');
222 run.test("Missing Second Operand in Subtraction",
223 '52288 - = [[52288 _ 52288][_ - _][][0 _ 0]]');
224 // TODO(dharcourt): Previous line should be:
225 // '52288 - = [[52288 _ 52288][_ - 52288][][0 _ 0]]');
227 run.test("Missing Second Operand in Multiplication",
228 '17 * = [17 _ 17][_ * _][][289]');
229 // TODO(dharcourt): Previous line should be:
230 // '17 * = [17 _ 17][_ * 17][][289]');
232 run.test("Missing Second Operand in Division",
233 '47 / = [47 _ 47][_ / _][][1]');
234 // TODO(dharcourt): Previous line should be:
235 // '47 / = [47 _ 47][_ / 47][][1]');
237 run.test("Missing Last Operand in Addition and Subtraction Chain",
238 '8449 + 4205138 - [4213587] = [0]');
240 /* TODO(dharcourt): Fix & reactivate these:
242 run.test("Leading zeros should be collapsed",
243 '0 [_ _ [0]] 0 [_ _ [0]] 0 [_ _ [0]] ' +
244 '2 [_ _ [2]] 0 [_ _ [2 0]] + [20 + _] ' +
245 '0 [20 + [0]] 0 [20 + [0]] 0 [20 + [0]] ' +
246 '2 [20 + [2]] 0 [20 + [2 0]] = [40 _ _]');
248 run.test("Test utilities should correctly predict zeros collapse",
249 '000 [[0==]] 20 [[20]] + 000 [[0==]] 20 [[20]] = [40]' +
250 '00020 + 00020 = [40]');
254 if (log || typeof log === 'undefined')