New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dice-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dice-js - npm Package Compare versions

Comparing version 0.2.0 to 0.4.0

node_modules/dice-js/behavior.js

20

package.json
{
"name": "dice-js",
"description": "Roll some dice.",
"version": "0.2.0",
"version": "0.4.0",
"keywords": [

@@ -9,10 +9,15 @@ "dice",

],
"main": "./lib/dice.js",
"directories": {
"lib": "lib"
"main": "./node_modules/dice-js/index.js",
"dependencies": {
"proteus": ">=0.1.x"
},
"devDependencies": {
"mocha": "0.3.x",
"should": "0.5.x"
"mocha": ">=0.3.x",
"should": ">=0.5.x",
"infuse": "*",
"sake": ">=0.1.x"
},
"bundledDependencies": [
"dice-js"
],
"scripts": {

@@ -31,3 +36,6 @@ "test": "mocha"

},
"bugs": {
"url": "http://github.com/jhamlet/dice-js/issues"
},
"preferGlobal": true
}

@@ -0,145 +1,75 @@

/*globals suite, test, setup, teardown */
var lib = require("../"),
Dice = lib.Dice,
behaviors = Dice.behaviors
var Dice = require("dice-js/dice"),
repeat = require("./repeat"),
count = 20,
tries = 5000,
dice = [2, 4, 6, 8, 10, 12, 20, 100],
format = require("util").format
;
suite("Dice", function () {
test("Instantiation", function () {
var dice = new Dice(3, 6);
dice.count.should.equal(3);
dice.rolled.should.equal(false);
dice.total.should.equal(0);
("" + dice).should.equal("3d6");
});
test("Roll d6", function () {
var dice = new Dice(1, 6),
result
;
("" + dice).should.equal("d6");
result = dice.roll();
result.should.be.within(1, 6);
dice.rolled.should.equal(true);
dice.total.should.not.equal(0);
dice.results.length.should.equal(1);
console.log("" + dice);
("" + dice).should.match(/d6 \[(\d+)\] = \d+/);
test("Bad arguments throw an error", function () {
[1, -1, 0, null, true, false, "2", NaN].forEach(function (faces) {
(function () {
new dice(faces);
}).should.throw();
});
});
test("Roll 3d6", function () {
var dice = new Dice(3, 6),
result
;
("" + dice).should.equal("3d6");
result = dice.roll();
result.should.be.within(1, 18);
dice.rolled.should.equal(true);
dice.total.should.not.equal(0);
dice.results.length.should.equal(3);
console.log("" + dice);
("" + dice).should.match(/d6 \[(\d+(?:, )?){3}\] = \d+/);
});
test("Roll 3d6+2", function () {
var dice = new Dice(3, 6, [new behaviors.ResultModifier(2)]),
result, dietotal
;
result = dice.roll();
result.should.be.within(5, 20);
dietotal = dice.results.reduce(function (p, d) {
return p + d;
}, 0);
dietotal.should.equal(result - 2);
test("Empty arguments produces a 1d6", function () {
var dice = new Dice();
dice.faces.should.equal(6);
dice.count.should.equal(1);
}),
dice.forEach(function (faces) {
test(
format("d%s die faces correctly set when ommitting first argument", faces),
function () {
var dice = new Dice(faces);
dice.faces.should.equal(faces);
}
);
console.log("" + dice);
});
test("Roll 3d6 and add 1 to every die", function () {
var dice = new Dice(3, 6, [new behaviors.DieModifier(1)]),
result, dietotal
;
test(
format("d%s#rolled correctly set", faces),
function () {
var dice = new Dice(faces);
dice.rolled.should.equal(false);
dice.roll();
dice.rolled.should.equal(true);
dice.reset();
dice.rolled.should.equal(false);
}
);
result = dice.roll();
result.should.be.within(6, 21);
test("Correct #toString output", function () {
var dice = new Dice(faces);
// #join sets the appropriate hinting mechanism to "string"
[dice].join().should.equal(format("[d%s]", faces));
dice.roll();
(dice + "").should.be.within(0, faces);
[dice].join().should.match(/^\[d\d+ \(\d+\) = \d+\]$/);
});
dietotal = dice.results.reduce(function (p, d) {
return (p + d);
}, 0);
dietotal.should.equal(result - 3);
console.log("" + dice);
repeat(count, function (nil, idx) {
var num = idx + 1,
min = num,
max = min * faces
;
test(
format("%sd%s rolled %s times all fall within %s and %s", num, faces, tries, min, max),
function () {
repeat(tries, function () {
var dice = new Dice(num, faces);
dice.roll().result.should.be.within(num, num * faces);
});
}
);
});
});
test("5d6 minus two lowest (5d6-2low)", function () {
var dice = new Dice(5, 6),
results
;
dice.addBehavior(new behaviors.RemoveLowest(2));
results = dice.roll();
results.should.be.within(3, 18);
dice.results.length.should.equal(3);
dice.lowResults.length.should.equal(2);
console.log("" + dice);
});
test("10d6 Hero Dice", function () {
var dice = lib.heroDice(10);
dice.roll();
dice.stun.should.be.within(10, 60);
dice.body.should.be.within(0, 20);
console.log("" + dice);
});
test("6d6 Success dice", function () {
var dice = new Dice(6, 6);
dice.addBehavior(new behaviors.SuccessDice(5));
dice.roll();
dice.total.should.be.within(0, 6);
console.log("" + dice);
});
test("6d6 Shadowrun dice", function () {
var dice = lib.shadowrunDice(6);
dice.roll();
console.log("" + dice);
});
test("6d6 WEG Star Wars", function () {
var dice = lib.d6StarWarsDice(6);
dice.roll();
console.log("" + dice);
});
test("4d6+2 WEG Star Wars", function () {
var dice = lib.d6StarWarsDice(4, 2);
dice.roll();
dice.total.should.be.above(6);
dice.results.reduce(function (t, d) { return (t + d); }, 0).
should.equal(dice.total - 2);
("" + dice).should.match(/4d6\+2 \[(\d+(?:, )?)+\] = \d+!?/);
console.log("" + dice);
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc