Comparing version 0.2.0 to 0.4.0
{ | ||
"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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
46903
30
1272
2
47
1
4
1
2
+ Addedproteus@>=0.1.x
+ Addedproteus@0.1.3(transitive)