|
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 var BUGNUMBER = "(none)"; |
|
8 var summary = "Fibonacci generator by matrix multiplication"; |
|
9 var actual, expect; |
|
10 |
|
11 printBugNumber(BUGNUMBER); |
|
12 printStatus(summary); |
|
13 |
|
14 /************** |
|
15 * BEGIN TEST * |
|
16 **************/ |
|
17 |
|
18 function fib() |
|
19 { |
|
20 var init = [1, 0]; |
|
21 var mx = [[1, 1], [1, 0]]; |
|
22 while (true) |
|
23 { |
|
24 yield init[1]; |
|
25 var tmp = [,]; |
|
26 tmp[0] = |
|
27 mx[0][0]*init[0] + mx[0][1]*init[1]; |
|
28 tmp[1] = |
|
29 mx[1][0]*init[0] + mx[1][1]*init[1]; |
|
30 init = tmp; |
|
31 } |
|
32 } |
|
33 |
|
34 var failed = false; |
|
35 var it = fib(); |
|
36 |
|
37 try |
|
38 { |
|
39 if (it.next() != 0) |
|
40 throw "F_0 failed"; |
|
41 if (it.next() != 1) |
|
42 throw "F_1 failed"; |
|
43 if (it.next() != 1) |
|
44 throw "F_2 failed"; |
|
45 if (it.next() != 2) |
|
46 throw "F_3 failed"; |
|
47 if (it.next() != 3) |
|
48 throw "F_4 failed"; |
|
49 if (it.next() != 5) |
|
50 throw "F_5 failed"; |
|
51 if (it.next() != 8) |
|
52 throw "F_6 failed"; |
|
53 } |
|
54 catch (e) |
|
55 { |
|
56 failed = e; |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 expect = false; |
|
62 actual = failed; |
|
63 |
|
64 reportCompare(expect, actual, summary); |