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