|
1 | 1 | import { expect } from "chai";
|
2 |
| -import { limit, wrapInBounds } from "./numbers"; |
| 2 | +import { inRange, limit, wrapInBounds } from "./numbers"; |
3 | 3 |
|
4 | 4 | describe("wrapInBounds", () => {
|
5 | 5 | it("should not throw if any parameters are null", () => {
|
@@ -76,3 +76,45 @@ describe("limit", () => {
|
76 | 76 | expect(limit(0, 10, 5)).to.equal(5);
|
77 | 77 | });
|
78 | 78 | });
|
| 79 | + |
| 80 | +describe("inRange", () => { |
| 81 | + it("should not throw if any parameters are null", () => { |
| 82 | + expect(() => { |
| 83 | + inRange(null, null, null); |
| 84 | + }).not.to.throw(); |
| 85 | + expect(() => { |
| 86 | + inRange(0, null, null); |
| 87 | + }).not.to.throw(); |
| 88 | + expect(() => { |
| 89 | + inRange(0, null, 1); |
| 90 | + }).not.to.throw(); |
| 91 | + expect(() => { |
| 92 | + inRange(0, 10, null); |
| 93 | + }).not.to.throw(); |
| 94 | + }); |
| 95 | + |
| 96 | + it("should return `true` if `value` is within range of `min` and `max`", () => { |
| 97 | + expect(inRange(10, 0, 20)).to.be.true; |
| 98 | + expect(inRange(10, 20)).to.be.true; |
| 99 | + }); |
| 100 | + |
| 101 | + it("should return `false` when `value` is less than `min` and `max`", () => { |
| 102 | + expect(inRange(10, 20, 30)).to.be.false; |
| 103 | + }); |
| 104 | + |
| 105 | + it("should return `false` when `value` is greater than `min` and `max`", () => { |
| 106 | + expect(inRange(10, 0, 5)).to.be.false; |
| 107 | + }); |
| 108 | + |
| 109 | + it("should return `false` when `value` is equal to `max`", () => { |
| 110 | + expect(inRange(10, 0, 10)).to.be.false; |
| 111 | + }); |
| 112 | + |
| 113 | + it("should return `true` when `value` is less than `min` and `max` is omitted", () => { |
| 114 | + expect(inRange(10, 20)).to.be.true; |
| 115 | + }); |
| 116 | + |
| 117 | + it("should return `false` when `value` is less than 0 and `max` is omitted", () => { |
| 118 | + expect(inRange(-10, 20)).to.be.false; |
| 119 | + }); |
| 120 | +}); |
0 commit comments