UNPKG

randex

Version:

Generates random filename, username, email, name, full name, etc for test purposes.

65 lines (64 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var custom_1 = require("../custom"); var test_util_1 = require("./test-util"); function testNumber(max) { var value = custom_1.Randex.number(max); expect(value).toBeGreaterThanOrEqual(0); expect(value).toBeLessThanOrEqual(max); } function testNumberWithArray(range, two) { if (two === void 0) { two = false; } var min = range[0], max = range[1]; var value = two ? custom_1.Randex.number(range) : custom_1.Randex.number(min, max); expect(value).toBeGreaterThanOrEqual(min); expect(value).toBeLessThanOrEqual(max); } describe("randomNumber", function () { it("param: number", function () { testNumber(0); testNumber(1); testNumber(5); }); it("much range", function () { var max = 4; var result = {}; test_util_1.TestUtil.loop(function () { var value = custom_1.Randex.number(max); result[value] = (result[value] || 0) + 1; }); for (var i = 0; i <= max; i++) { expect(result[i]).toBeGreaterThan(0); } }); it("param: number array", function () { test_util_1.TestUtil.loop(function () { testNumberWithArray([10, 15]); }); }); it("param: two numbers", function () { test_util_1.TestUtil.loop(function () { testNumberWithArray([10, 15], true); }); }); it("two numbers with decimals", function () { var count = 0; test_util_1.TestUtil.loop(function () { var value = custom_1.Randex.number(1, 10, { decimals: 2 }); if (/\.\d{2}$/g.test(value.toString())) { count++; } }); expect(count).toBeGreaterThan(1); }); it("a number with decimals", function () { var count = 0; test_util_1.TestUtil.loop(function () { var value = custom_1.Randex.number(10, { decimals: 2 }); if (/\.\d{2}$/g.test(value.toString())) { count++; } }); expect(count).toBeGreaterThan(1); }); });