Debian Codegraph @

rhino/testsrc/tests/js1_7/geniter/simple-fib.js

raw symbols SCIP
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 var gTestfile = 'simple-fib.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = 326466; // bug 326466, comment 1
9 var summary = "Simple Fibonacci iterator";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 function fib()
20 {
21 var a = 0, b = 1;
22 while (true)
23 {
24 yield a;
25 var t = a;
26 a = b;
27 b += t;
28 }
29 }
30
31 var failed = false;
32
33 try
34 {
35 var g = fib();
36
37 if (g.next() != 0)
38 throw "F_0 = 0";
39 if (g.next() != 1)
40 throw "F_1 = 1";
41 if (g.next() != 1)
42 throw "F_2 = 1";
43 if (g.next() != 2)
44 throw "F_3 = 2";
45 }
46 catch (e)
47 {
48 failed = e;
49 }
50
51
52
53 expect = false;
54 actual = failed;
55
56 reportCompare(expect, actual, summary);