|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Date: 07 May 2001 |
|
8 * |
|
9 * SUMMARY: Testing the switch statement |
|
10 * |
|
11 * See ECMA3 Section 12.11, "The switch Statement" |
|
12 */ |
|
13 //----------------------------------------------------------------------------- |
|
14 var UBound = 0; |
|
15 var BUGNUMBER = '(none)'; |
|
16 var summary = 'Testing the switch statement'; |
|
17 var cnMatch = 'Match'; |
|
18 var cnNoMatch = 'NoMatch'; |
|
19 var status = ''; |
|
20 var statusitems = [ ]; |
|
21 var actual = ''; |
|
22 var actualvalues = [ ]; |
|
23 var expect= ''; |
|
24 var expectedvalues = [ ]; |
|
25 |
|
26 |
|
27 status = 'Section A of test'; |
|
28 actual = match(17, f(fInverse(17)), f, fInverse); |
|
29 expect = cnMatch; |
|
30 addThis(); |
|
31 |
|
32 status = 'Section B of test'; |
|
33 actual = match(17, 18, f, fInverse); |
|
34 expect = cnNoMatch; |
|
35 addThis(); |
|
36 |
|
37 status = 'Section C of test'; |
|
38 actual = match(1, 1, Math.exp, Math.log); |
|
39 expect = cnMatch; |
|
40 addThis(); |
|
41 |
|
42 status = 'Section D of test'; |
|
43 actual = match(1, 2, Math.exp, Math.log); |
|
44 expect = cnNoMatch; |
|
45 addThis(); |
|
46 |
|
47 status = 'Section E of test'; |
|
48 actual = match(1, 1, Math.sin, Math.cos); |
|
49 expect = cnNoMatch; |
|
50 addThis(); |
|
51 |
|
52 |
|
53 |
|
54 //--------------------------------------------------------------------------------- |
|
55 test(); |
|
56 //--------------------------------------------------------------------------------- |
|
57 |
|
58 |
|
59 |
|
60 /* |
|
61 * If F,G are inverse functions and x==y, this should return cnMatch - |
|
62 */ |
|
63 function match(x, y, F, G) |
|
64 { |
|
65 switch (x) |
|
66 { |
|
67 case F(G(y)): |
|
68 return cnMatch; |
|
69 |
|
70 default: |
|
71 return cnNoMatch; |
|
72 } |
|
73 } |
|
74 |
|
75 |
|
76 function addThis() |
|
77 { |
|
78 statusitems[UBound] = status; |
|
79 actualvalues[UBound] = actual; |
|
80 expectedvalues[UBound] = expect; |
|
81 UBound++; |
|
82 } |
|
83 |
|
84 |
|
85 function test() |
|
86 { |
|
87 enterFunc ('test'); |
|
88 printBugNumber(BUGNUMBER); |
|
89 printStatus (summary); |
|
90 |
|
91 for (var i = 0; i < UBound; i++) |
|
92 { |
|
93 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
|
94 } |
|
95 |
|
96 exitFunc ('test'); |
|
97 } |
|
98 |
|
99 |
|
100 function f(m) |
|
101 { |
|
102 return 2*(m+1); |
|
103 } |
|
104 |
|
105 |
|
106 function fInverse(n) |
|
107 { |
|
108 return (n-2)/2; |
|
109 } |