|
| 1 | +import { expect } from '@open-wc/testing'; |
| 2 | +import { clamp } from './math.js'; |
| 3 | + |
| 4 | +describe('clamp', () => { |
| 5 | + it('should not allow the returned value to be lower than min', () => { |
| 6 | + expect(clamp(-1, 0, 1)).to.equal(0); |
| 7 | + expect(clamp(-100, 5, 100)).to.equal(5); |
| 8 | + expect(clamp(-50, -7, 20)).to.equal(-7); |
| 9 | + expect(clamp(100, 500, 502)).to.equal(500); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should not allow the returned value to be higher than max', () => { |
| 13 | + expect(clamp(2, 0, 1)).to.equal(1); |
| 14 | + expect(clamp(100, 5, 100)).to.equal(100); |
| 15 | + expect(clamp(50, -7, 20)).to.equal(20); |
| 16 | + expect(clamp(1000, 500, 502)).to.equal(502); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return the value if it is within the min and max', () => { |
| 20 | + expect(clamp(0, 0, 1)).to.equal(0); |
| 21 | + expect(clamp(12, 10, 50)).to.equal(12); |
| 22 | + expect(clamp(-48, -50, 50)).to.equal(-48); |
| 23 | + expect(clamp(501, 500, 502)).to.equal(501); |
| 24 | + }); |
| 25 | +}); |
0 commit comments