1 | import test from "ava";
|
2 | import Chance from "../chance.js";
|
3 | import _ from "lodash";
|
4 |
|
5 | const chance = new Chance();
|
6 |
|
7 |
|
8 | test("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 |
|
19 | test("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 |
|
28 | test("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 | });
|