Skip to content

Commit

Permalink
🔍 test: Increase coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Jul 29, 2020
1 parent 5f47e39 commit 6ce225b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/src/montgomery/conversion/from_out.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import test from 'ava';

import {parse, stringify} from '@aureooms/js-integer-big-endian';

import {Montgomery} from '../../../../src';

const REPRESENTATION_BASE = 10;
const DISPLAY_BASE = 10;

function mod(t, N, A, expected) {
const n = parse(DISPLAY_BASE, REPRESENTATION_BASE, N);
const mont = new Montgomery(REPRESENTATION_BASE, n);

const a = parse(DISPLAY_BASE, REPRESENTATION_BASE, A);

const _amodN = mont.from(a);

const amodN = mont.out(_amodN);

const AmodN = stringify(
REPRESENTATION_BASE,
DISPLAY_BASE,
amodN,
0,
amodN.length,
);

t.is(expected, AmodN);
}

mod.title = (_, N, A, expected) => `${A} = ${expected} mod ${N}`;

test(mod, '13', '125', '8');
test(mod, '497', '4', '4');
test(mod, '497', '16', '16');
test(mod, '497', '64', '64');
test(mod, '497', '256', '256');
test(mod, '497', '1024', '30');
test(mod, '497', '120', '120');
test(mod, '497', '480', '480');
test(mod, '497', '1920', '429');
test(mod, '497', '1716', '225');
test(mod, '497', '900', '403');
test(mod, '497', '1612', '121');
test(mod, '497', '484', '484');
test(mod, '497', '1936', '445');
25 changes: 25 additions & 0 deletions test/src/montgomery/throws_GCD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import test from 'ava';

import {Montgomery} from '../../../src';
import {parse} from '@aureooms/js-integer-big-endian';

const DISPLAY_BASE = 10;

function throws(t, b, N) {
const n = parse(DISPLAY_BASE, b, N);
t.throws(() => new Montgomery(b, n), {message: /GCD/});
}

throws.title = (_, b, N) => `Montgomery(${b}, ${N}) throws because of GCD.`;

test(throws, 10, '2');
test(throws, 10, '5');
test(throws, 10, '10');
test(throws, 10, '12');
test(throws, 10, '242');
test(throws, 10, '385');
test(throws, 10, '490');

test(throws, 100, '12');

test(throws, 82733, '82733');

0 comments on commit 6ce225b

Please sign in to comment.