From 3f1661281c2cfc266d53a99a45a3abba50303f10 Mon Sep 17 00:00:00 2001 From: Douglas Muth Date: Thu, 9 Nov 2017 20:56:48 -0500 Subject: [PATCH] First tests in Mocha--now testing getRandomValue(). --- tests/test.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test.js diff --git a/tests/test.js b/tests/test.js new file mode 100644 index 0000000..b51a2bd --- /dev/null +++ b/tests/test.js @@ -0,0 +1,56 @@ + +var assert = require('assert'); +var should = require('should'); + +var Promise = require("bluebird"); + +var diceware = require("../src/lib.js") + + + +describe("Diceware", function() { + describe("getRandomValue()", function(done) { + + it("Should pass", function(done) { + + Promise.try(function() { + return(diceware.getRandomValue(-1)); + + }).catch(function(err) { + err.should.match(/can't be less or equal to zero/); + return(diceware.getRandomValue(0)); + + }).catch(function(err) { + err.should.match(/can't be less or equal to zero/); + return(diceware.getRandomValue(1)); + + }).then(function(num) { + num.should.be.aboveOrEqual(0); + num.should.be.lessThanOrEqual(1); + return(diceware.getRandomValue(999)); + + }).then(function(num) { + num.should.be.aboveOrEqual(0); + num.should.be.lessThanOrEqual(999); + done(); + + }).catch(function(err) { + done(err); + + }); + + }); + + }); +}); + + +/* +TEST/TODO: Things to refactor: +X Diceware.getRandomValue +- Diceware.getBase6 +- Diceware.convertBase6ToDice +- Diceware.getNumValuesFromNumDice +- Diceware.rollDice(1).roll.length +*/ +