Skip to content

Commit c957a95

Browse files
committed
add clamp tests
1 parent a07f6d9 commit c957a95

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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

Comments
 (0)