urbit-ob

JavaScript utilities for phonemic base wrangling.
Log | Files | Refs | README

commit 7e9ea3f98967b2cc7df6298729a4e28eeb1d891b
parent 3b378b7e6d116924a623c7451befb8330c9f7273
Author: Jared Tobin <jared@jtobin.io>
Date:   Tue, 12 Mar 2019 18:48:20 +1300

Make the small and med tests use library code.

.. instead of implementing their own versions of 'fe'.  Improves our
effective test coverage quite a bit.

Diffstat:
Mtest/med.js | 21+++++++++++++++------
Mtest/small.js | 21+++++++++++++++------
2 files changed, 30 insertions(+), 12 deletions(-)

diff --git a/test/med.js b/test/med.js @@ -1,7 +1,8 @@ const BN = require('bn.js') const { expect } = require('chai') +const { isEqual } = require('lodash') -const { Fe } = require('../src/internal/ob') +const { Fe, Fen } = require('../src/internal/ob') const u_a = new BN(Math.pow(2, 4) - 1) const u_b = new BN(Math.pow(2, 4)) @@ -47,21 +48,29 @@ const eff = (_, m) => new BN(v0[m]) const feis = arg => Fe(4, u_a, u_b, u_c, eff, new BN(arg)) +const tail = arg => + Fen(4, u_a, u_b, u_c, eff, new BN(arg)) + // test -describe('feis -- medium input space', () => { +describe('feis/tail (medium input space)', () => { - const perm = emm.map(x => feis(x).toString()) + const perm = emm.map(x => feis(x).toNumber()) + const inv = perm.map(x => tail(x).toNumber()) const distincts = perm.filter((x, i, a) => a.indexOf(x) === i) - it('produces distinct outputs', () => { + it('feis produces distinct outputs', () => { expect(distincts.length).to.equal(perm.length) }) - it('permutes the input space', () => { - expect(perm.reduce((acc, x) => emm.includes(parseInt(x)) && acc, true)) + it('feis permutes the input space', () => { + expect(perm.reduce((acc, x) => emm.includes(x) && acc, true)) .to.equal(true) }) + it('tail inverts feis', () => { + expect(isEqual(emm, inv)).to.equal(true) + }) + }) diff --git a/test/small.js b/test/small.js @@ -1,7 +1,8 @@ const BN = require('bn.js') const { expect } = require('chai') +const { isEqual } = require('lodash') -const { Fe } = require('../src/internal/ob') +const { Fe, Fen } = require('../src/internal/ob') const u_a = new BN(Math.pow(2, 2) - 1) const u_b = new BN(Math.pow(2, 2)) @@ -27,22 +28,30 @@ const eff = (j, m) => { const feis = arg => Fe(4, u_a, u_b, u_c, eff, new BN(arg)) +const tail = arg => + Fen(4, u_a, u_b, u_c, eff, new BN(arg)) + // test -describe('feis -- small input space', () => { +describe('feis/tail (small input space)', () => { const emm = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] - const perm = emm.map(x => feis(x).toString()) + const perm = emm.map(x => feis(x).toNumber()) + const inv = perm.map(x => tail(x).toNumber()) const distincts = perm.filter((x, i, a) => a.indexOf(x) === i) - it('produces distinct outputs', () => { + it('feis produces distinct outputs', () => { expect(distincts.length).to.equal(perm.length) }) - it('permutes the input space', () => { - expect(perm.reduce((acc, x) => emm.includes(parseInt(x)) && acc, true)) + it('feis permutes the input space', () => { + expect(perm.reduce((acc, x) => emm.includes(x) && acc, true)) .to.equal(true) }) + it('tail inverts feis', () => { + expect(isEqual(emm, inv)).to.equal(true) + }) + })