small.js (1353B)
1 const BN = require('bn.js') 2 const { expect } = require('chai') 3 const isEqual = require('lodash.isequal') 4 5 const { Fe, Fen } = require('../src/internal/ob') 6 7 const u_a = new BN(Math.pow(2, 2) - 1) 8 const u_b = new BN(Math.pow(2, 2)) 9 const u_c = u_a.mul(u_b) 10 11 const eff = (j, m) => { 12 let v0 = [5, 9, 2, 6, 4, 0, 8, 7, 1, 10, 3, 11] 13 let v1 = [2, 1, 0, 3, 10, 4, 9, 5, 7, 11, 6, 8] 14 let v2 = [10, 6, 7, 1, 0, 11, 3, 9, 5, 2, 8, 4] 15 let v3 = [11, 0, 3, 5, 9, 8, 6, 10, 4, 1, 2, 7] 16 17 return ( 18 j === 0 19 ? new BN(v0[m]) 20 : j === 1 21 ? new BN(v1[m]) 22 : j === 2 23 ? new BN(v2[m]) 24 : new BN(v3[m]) 25 ) 26 } 27 28 const feis = arg => 29 Fe(4, u_a, u_b, u_c, eff, new BN(arg)) 30 31 const tail = arg => 32 Fen(4, u_a, u_b, u_c, eff, new BN(arg)) 33 34 // test 35 36 describe('feis/tail (small input space)', () => { 37 38 const emm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] 39 const perm = emm.map(x => feis(x).toNumber()) 40 const inv = perm.map(x => tail(x).toNumber()) 41 const distincts = perm.filter((x, i, a) => a.indexOf(x) === i) 42 43 it('feis produces distinct outputs', () => { 44 expect(distincts.length).to.equal(perm.length) 45 }) 46 47 it('feis permutes the input space', () => { 48 expect(perm.reduce((acc, x) => emm.includes(x) && acc, true)) 49 .to.equal(true) 50 }) 51 52 it('tail inverts feis', () => { 53 expect(isEqual(emm, inv)).to.equal(true) 54 }) 55 56 })