Skip to content

Commit

Permalink
Add all random tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CMEONE committed Dec 29, 2021
1 parent 91f1c9b commit d9a45eb
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require("./test/general.js");
require("./test/core.js");
require("./test/util.js");
require("./test/util.js");
require("./test/random.js");
68 changes: 68 additions & 0 deletions test/random.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const assert = require("assert");
const { tEnvoy, tEnvoyPGPKey, tEnvoyNaClKey, tEnvoyNaClSigningKey } = require("../node/tenvoy.js");
const envoy = new tEnvoy();

describe("Random Tests", function() {
let i = 0;

i++;
it(`${i}: random.bytes - exists`, function() {
assert.notEqual(envoy.random.bytes, null);
});

i++;
it(`${i}: random.bytes - properly generates`, async function() {
let random1 = await envoy.random.bytes(256);
let random2 = await envoy.random.bytes(256);
assert.deepEqual(random1.length, 256);
assert.deepEqual(random2.length, 256);
assert.notEqual(random1, random2);
});

i++;
it(`${i}: random.number - exists`, function() {
assert.notEqual(envoy.random.number, null);
});

i++;
it(`${i}: random.number - properly generates`, async function() {
let random1 = await envoy.random.number(0, 4096);
let random2 = await envoy.random.number(0, 4096);
let random3 = await envoy.random.number(0, 1);
assert.deepEqual(random1 < 4096, true);
assert.deepEqual(random1 >= 0, true);
assert.deepEqual(random2 < 4096, true);
assert.deepEqual(random2 >= 0, true);
assert.deepEqual(random3 < 1, true);
assert.deepEqual(random3 >= 0, true);
assert.notEqual(random1, random2);
});

i++;
it(`${i}: random.string - exists`, function() {
assert.notEqual(envoy.random.string, null);
});

i++;
it(`${i}: random.string - properly generates`, async function() {
let random1 = await envoy.random.string(256);
let random2 = await envoy.random.string(256);
assert.deepEqual(random1.length, 256);
assert.deepEqual(random2.length, 256);
assert.notEqual(random1, random2);
});

i++;
it(`${i}: random.words - exists`, function() {
assert.notEqual(envoy.random.words, null);
});

i++;
it(`${i}: random.words - properly generates`, async function() {
let random1 = await envoy.random.words(256);
let random2 = await envoy.random.words(256);
assert.deepEqual(random1.split(" ").length, 256);
assert.deepEqual(random2.split(" ").length, 256);
assert.notEqual(random1, random2);
});
})

0 comments on commit d9a45eb

Please sign in to comment.