UNPKG

746 BJavaScriptView Raw
1import test from "ava";
2import Chance from "../chance.js";
3import _ from "lodash";
4
5const chance = new Chance();
6
7// chance.buffer()
8test("buffer() returns a random buffer", t => {
9 _.times(1000, () => {
10 let buffer = chance.buffer();
11 t.true(_.isBuffer(buffer));
12 let len = buffer.byteLength;
13 t.true(len >= 5);
14 t.true(len <= 20);
15 });
16});
17
18// chance.buffer()
19test("buffer() will obey bounds", t => {
20 _.times(1000, () => {
21 let buffer = chance.buffer({ length: 12 });
22 t.true(_.isBuffer(buffer));
23 t.is(buffer.byteLength, 12);
24 });
25});
26
27// chance.buffer()
28test("buffer() throws if length < 0", t => {
29 const fn = () => chance.buffer({ length: -3 });
30 t.throws(fn, "Chance: Length cannot be less than zero.");
31});