1/* 2* The contents of this file are subject to the Netscape Public 3* License Version 1.1 (the "License"); you may not use this file 4* except in compliance with the License. You may obtain a copy of 5* the License at http://www.mozilla.org/NPL/ 6* 7* Software distributed under the License is distributed on an "AS IS" 8* basis, WITHOUT WARRANTY OF ANY KIND, either expressed 9* or implied. See the License for the specific language governing 10* rights and limitations under the License. 11* 12* The Original Code is mozilla.org code. 13* 14* The Initial Developer of the Original Code is Netscape 15* Communications Corporation. Portions created by Netscape are 16* Copyright (C) 1998 Netscape Communications Corporation. All 17* Rights Reserved. 18* 19* Contributor(s): pschwartau@netscape.com 20* Date: 07 May 2001 21* 22* SUMMARY: Testing the switch statement 23* 24* See ECMA3 Section 12.11, "The switch Statement" 25*/ 26//------------------------------------------------------------------------------------------------- 27var UBound = 0; 28var bug = '(none)'; 29var summary = 'Testing the switch statement'; 30var cnMatch = 'Match'; 31var cnNoMatch = 'NoMatch'; 32var status = ''; 33var statusitems = [ ]; 34var actual = ''; 35var actualvalues = [ ]; 36var expect= ''; 37var expectedvalues = [ ]; 38 39 40status = 'Section A of test'; 41actual = match(17, f(fInverse(17)), f, fInverse); 42expect = cnMatch; 43addThis(); 44 45status = 'Section B of test'; 46actual = match(17, 18, f, fInverse); 47expect = cnNoMatch; 48addThis(); 49 50status = 'Section C of test'; 51actual = match(1, 1, Math.exp, Math.log); 52expect = cnMatch; 53addThis(); 54 55status = 'Section D of test'; 56actual = match(1, 2, Math.exp, Math.log); 57expect = cnNoMatch; 58addThis(); 59 60status = 'Section E of test'; 61actual = match(1, 1, Math.sin, Math.cos); 62expect = cnNoMatch; 63addThis(); 64 65 66 67//--------------------------------------------------------------------------------- 68test(); 69//--------------------------------------------------------------------------------- 70 71 72 73/* 74 * If F,G are inverse functions and x==y, this should return cnMatch - 75 */ 76function match(x, y, F, G) 77{ 78 switch (x) 79 { 80 case F(G(y)): 81 return cnMatch; 82 83 default: 84 return cnNoMatch; 85 } 86} 87 88 89function addThis() 90{ 91 statusitems[UBound] = status; 92 actualvalues[UBound] = actual; 93 expectedvalues[UBound] = expect; 94 UBound++; 95} 96 97 98function test() 99{ 100 enterFunc ('test'); 101 printBugNumber (bug); 102 printStatus (summary); 103 104 for (var i = 0; i < UBound; i++) 105 { 106 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 107 } 108 109 exitFunc ('test'); 110} 111 112 113function f(m) 114{ 115 return 2*(m+1); 116} 117 118 119function fInverse(n) 120{ 121 return (n-2)/2; 122} 123