1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_7/geniter/simple-fib.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +//----------------------------------------------------------------------------- 1.10 +var BUGNUMBER = 326466; // bug 326466, comment 1 1.11 +var summary = "Simple Fibonacci iterator"; 1.12 +var actual, expect; 1.13 + 1.14 +printBugNumber(BUGNUMBER); 1.15 +printStatus(summary); 1.16 + 1.17 +/************** 1.18 + * BEGIN TEST * 1.19 + **************/ 1.20 + 1.21 +function fib() 1.22 +{ 1.23 + var a = 0, b = 1; 1.24 + while (true) 1.25 + { 1.26 + yield a; 1.27 + var t = a; 1.28 + a = b; 1.29 + b += t; 1.30 + } 1.31 +} 1.32 + 1.33 +var failed = false; 1.34 + 1.35 +try 1.36 +{ 1.37 + var g = fib(); 1.38 + 1.39 + if (g.next() != 0) 1.40 + throw "F_0 = 0"; 1.41 + if (g.next() != 1) 1.42 + throw "F_1 = 1"; 1.43 + if (g.next() != 1) 1.44 + throw "F_2 = 1"; 1.45 + if (g.next() != 2) 1.46 + throw "F_3 = 2"; 1.47 +} 1.48 +catch (e) 1.49 +{ 1.50 + failed = e; 1.51 +} 1.52 + 1.53 + 1.54 + 1.55 +expect = false; 1.56 +actual = failed; 1.57 + 1.58 +reportCompare(expect, actual, summary);