27 lines
666 B
TypeScript
27 lines
666 B
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { clamp, clamp01 } from './clamp';
|
|
|
|
describe('clamp', () => {
|
|
it('returns value when within bounds', () => {
|
|
expect(clamp(5, 0, 10)).toBe(5);
|
|
});
|
|
it('clamps below to lower bound', () => {
|
|
expect(clamp(-3, 0, 10)).toBe(0);
|
|
});
|
|
it('clamps above to upper bound', () => {
|
|
expect(clamp(42, 0, 10)).toBe(10);
|
|
});
|
|
});
|
|
|
|
describe('clamp01', () => {
|
|
it('passes through values in [0, 1]', () => {
|
|
expect(clamp01(0.25)).toBe(0.25);
|
|
});
|
|
it('clamps negatives to 0', () => {
|
|
expect(clamp01(-1)).toBe(0);
|
|
});
|
|
it('clamps above 1 to 1', () => {
|
|
expect(clamp01(2)).toBe(1);
|
|
});
|
|
});
|