urbit-ob

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

commit 2cfbf641ef3ab271fd11f9d8b09b6e666fe524cc
parent 7e9ea3f98967b2cc7df6298729a4e28eeb1d891b
Author: Jared Tobin <jared@jtobin.io>
Date:   Tue, 12 Mar 2019 18:49:25 +1300

Add new functions to existing test suite.

Diffstat:
Mtest/co.test.js | 6------
Mtest/ob.test.js | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/test/co.test.js b/test/co.test.js @@ -46,12 +46,6 @@ describe('patp, etc.', () => { expect(patp('15663360')).to.equal('~nidsut-tomdun') }) - it('patp does not produce collisions', () => { - const lil = patp('479733505') - const big = patp('3108299008') - expect(lil).to.not.equal(big) - }) - it('large patp values match expected reference values', () => { expect(hex2patp('7468697320697320736f6d6520766572792068696768207175616c69747920656e74726f7079')) .to.equal('~divmes-davset-holdet--sallun-salpel-taswet-holtex--watmeb-tarlun-picdet-magmes--holter-dacruc-timdet-divtud--holwet-maldut-padpel-sivtud') diff --git a/test/ob.test.js b/test/ob.test.js @@ -4,21 +4,31 @@ const jsc = require('jsverify') const { isEqual } = require('lodash') const { feen, + fein, fend, + fynd, fice, + feis, teil, + tail, rynd, rund } = require('../src/internal/ob') -const bignums = jsc.uint32.smap( +const uint32 = jsc.uint32.smap( (num) => new BN(num), (bn) => bn.toNumber() ) +const planets = + jsc.number(Math.pow(2, 16), Math.pow(2, 32) - Math.pow(2, 16) - 1).smap( + (num) => new BN(num), + (bn) => bn.toNumber() +) + describe('feen/fend', () => { it('feen and fend are inverses', () => { - let prop = jsc.forall(bignums, bn => + let prop = jsc.forall(uint32, bn => fend(feen(bn)).eq(bn) && feen(fend(bn)).eq(bn)) jsc.assert(prop) @@ -45,9 +55,38 @@ describe('feen/fend', () => { }) }) +describe('fein/fynd', () => { + it('fein and fynd are inverses', () => { + let prop = jsc.forall(uint32, bn => + fynd(fein(bn)).eq(bn) && fein(fynd(bn)).eq(bn)) + + jsc.assert(prop, { tests: 100000 }) + }) + + it('fein matches expected reference values', () => { + let input = new BN('123456789') + let output = new BN('249127493') + expect(fein(input).eq(output)).to.equal(true) + + input = new BN('15663360') + output = new BN('148913959') + expect(fein(input).eq(output)).to.equal(true) + }) + + it('fynd matches expected reference values', () => { + let input = new BN('249127493') + let output = new BN('123456789') + expect(fynd(input).eq(output)).to.equal(true) + + input = new BN('148913959') + output = new BN('15663360') + expect(fynd(input).eq(output)).to.equal(true) + }) +}) + describe('fice/teil', () => { it('fice and teil are inverses', () => { - let prop = jsc.forall(bignums, bn => + let prop = jsc.forall(uint32, bn => fice(teil(bn)).eq(bn) && teil(fice(bn)).eq(bn)) jsc.assert(prop) @@ -74,3 +113,33 @@ describe('fice/teil', () => { }) }) +describe('feis/tail', () => { + it('feis and tail are inverses over the space of planets', () => { + let prop = jsc.forall(planets, bn => + feis(tail(bn)).eq(bn) && tail(feis(bn)).eq(bn) + ) + + jsc.assert(prop, { tests: 100000 } ) + }) + + it('feis matches expected reference values', () => { + let input = new BN ('123456789') + let output = new BN('2483218125') + expect(feis(input).eq(output)).to.equal(true) + + input = new BN('15663360') + output = new BN('2530652268') + expect(feis(input).eq(output)).to.equal(true) + }) + + it('tail matches expected reference values', () => { + let input = new BN('2483218125') + let output = new BN ('123456789') + expect(tail(input).eq(output)).to.equal(true) + + input = new BN('2530652268') + output = new BN('15663360') + expect(tail(input).eq(output)).to.equal(true) + }) +}) +