Skip to content

Commit af02890

Browse files
committed
(#68) Added upper and lower bound utility functions
1 parent 4f3e6f4 commit af02890

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { lowerBound, upperBound } from "./bound-value.function";
2+
3+
describe("lowerBound function", () => {
4+
it.each([
5+
[5, 10, 1, 1],
6+
[5, 5, 10, 10],
7+
[5, 1, 10, 5],
8+
[0, 0, 0, 0]
9+
])("Input: %f, Boundary: %f, minValue: %f, Expected: %f",
10+
(input: number, boundary: number, minValue: number, expected: number) => {
11+
// WHEN
12+
const result = lowerBound(input, boundary, minValue);
13+
14+
// THEN
15+
expect(result).toBe(expected);
16+
});
17+
});
18+
19+
describe("upperBound function", () => {
20+
it.each([
21+
[5, 10, 1, 5],
22+
[5, 5, 10, 10],
23+
[5, 1, 10, 10],
24+
[5, 5, 5, 5]
25+
])("Input: %f, Boundary: %f, maxValue: %f, Expected: %f",
26+
(input: number, boundary: number, maxValue: number, expected: number) => {
27+
// WHEN
28+
const result = upperBound(input, boundary, maxValue);
29+
30+
// THEN
31+
expect(result).toBe(expected);
32+
});
33+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function lowerBound(value: number, boundary: number, minValue: number): number {
2+
return (value <= boundary) ? minValue : value;
3+
}
4+
5+
export function upperBound(value: number, boundary: number, maxValue: number): number {
6+
return (value >= boundary) ? maxValue : value;
7+
}

0 commit comments

Comments
 (0)