ob.test.js (2173B)
1 const BN = require('bn.js') 2 const { expect } = require('chai'); 3 const jsc = require('jsverify') 4 const isEqual = require('lodash.isequal') 5 const { 6 fein, 7 fynd, 8 feis, 9 tail 10 } = require('../src/internal/ob') 11 12 const uint32 = jsc.uint32.smap( 13 (num) => new BN(num), 14 (bn) => bn.toNumber() 15 ) 16 17 const planets = 18 jsc.number(Math.pow(2, 16), Math.pow(2, 32) - Math.pow(2, 16) - 1).smap( 19 (num) => new BN(num), 20 (bn) => bn.toNumber() 21 ) 22 23 describe('fein/fynd', () => { 24 it('fein and fynd are inverses', function() { 25 this.timeout(5000) 26 27 let prop = jsc.forall(uint32, bn => 28 fynd(fein(bn)).eq(bn) && fein(fynd(bn)).eq(bn)) 29 30 jsc.assert(prop, { tests: 100000 }) 31 }) 32 33 it('fein matches expected reference values', () => { 34 let input = new BN('123456789') 35 let output = new BN('1897766331') 36 expect(fein(input).eq(output)).to.equal(true) 37 38 input = new BN('15663360') 39 output = new BN('1208402137') 40 expect(fein(input).eq(output)).to.equal(true) 41 }) 42 43 it('fynd matches expected reference values', () => { 44 let input = new BN('1897766331') 45 let output = new BN('123456789') 46 expect(fynd(input).eq(output)).to.equal(true) 47 48 input = new BN('1208402137') 49 output = new BN('15663360') 50 expect(fynd(input).eq(output)).to.equal(true) 51 }) 52 }) 53 54 describe('feis/tail', () => { 55 it('feis and tail are inverses over the space of planets', function() { 56 this.timeout(5000) 57 58 let prop = jsc.forall(planets, bn => 59 feis(tail(bn)).eq(bn) && tail(feis(bn)).eq(bn) 60 ) 61 62 jsc.assert(prop, { tests: 100000 } ) 63 }) 64 65 it('feis matches expected reference values', () => { 66 let input = new BN ('123456789') 67 let output = new BN('2060458291') 68 expect(feis(input).eq(output)).to.equal(true) 69 70 input = new BN('15663360') 71 output = new BN('1195593620') 72 expect(feis(input).eq(output)).to.equal(true) 73 }) 74 75 it('tail matches expected reference values', () => { 76 let input = new BN('2060458291') 77 let output = new BN ('123456789') 78 expect(tail(input).eq(output)).to.equal(true) 79 80 input = new BN('1195593620') 81 output = new BN('15663360') 82 expect(tail(input).eq(output)).to.equal(true) 83 }) 84 })