|
1 | 1 | import test from 'ava' ;
|
| 2 | +import https from 'https' ; |
2 | 3 |
|
3 |
| -import * as integer from '@aureooms/js-number' ; |
4 |
| -import { list , map } from '@aureooms/js-itertools' ; |
| 4 | +import * as number from '@aureooms/js-number' ; |
| 5 | +import * as integer from '@aureooms/js-integer' ; |
| 6 | +import { list , map , range } from '@aureooms/js-itertools' ; |
5 | 7 | import { Fibonacci } from '../../src' ;
|
6 | 8 |
|
7 |
| -test( 'Fibonacci' , t => { |
| 9 | +const URL = 'https://raw.githubusercontent.com/aureooms/integer-sequence-fibonacci/master/sequence/' ; |
8 | 10 |
|
9 |
| - const F = new Fibonacci( integer ) ; |
| 11 | +const N = 78 ; // biggest fibonacci number smaller than 2^53 |
10 | 12 |
|
11 |
| - const n = 10 ; |
12 |
| - const a = [ "0" , "1" , "1" , "2" , "3" , "5" , "8" , "13" , "21" , "34" ] ; |
| 13 | +function macro ( t , [ name , impl ] , i ) { |
13 | 14 |
|
14 |
| - t.deepEqual( list( map ( integer.stringify , F.range( n ) ) ) , a ) ; |
| 15 | + const F = new Fibonacci( impl ) ; |
15 | 16 |
|
16 |
| - t.deepEqual( integer.stringify( F.nth( 0 ) ) , "0" ) ; |
17 |
| - t.deepEqual( integer.stringify( F.nth( 38 ) ) , "39088169" ) ; |
| 17 | + let data = '' ; |
18 | 18 |
|
19 |
| -} ) ; |
| 19 | + https.get( |
| 20 | + URL + i , |
| 21 | + res => { |
| 22 | + res.on( 'data' , chunk => { data += chunk ; } ) ; |
| 23 | + res.on( 'end' , ( ) => { |
| 24 | + t.is( impl.stringify( F.nth( i ) ) , data.trim() ) ; |
| 25 | + t.end( ) ; |
| 26 | + } ) ; |
| 27 | + } |
| 28 | + ).on('error', e => { |
| 29 | + t.fail( e.message ) ; |
| 30 | + t.end( ) ; |
| 31 | + } ) ; |
| 32 | + |
| 33 | +} |
| 34 | + |
| 35 | +macro.title = ( _ , [ name , impl ] , i ) => `Fibonacci (${name}, ${i})` ; |
| 36 | + |
| 37 | +for ( const model of [ [ '@aureooms/js-number' , number ] , [ '@aureooms/js-integer' , integer ] ] ) |
| 38 | +for ( const i of range( 0 , N + 1 ) ) |
| 39 | +test.cb( macro , model , i ) ; |
| 40 | + |
| 41 | +// t.deepEqual( list( map ( integer.stringify , F.range( n ) ) ) , a ) ; |
0 commit comments