Skip to content

Commit df0c9cf

Browse files
committed
tests: moving tests to individual files
Towards #123
1 parent 6e8b702 commit df0c9cf

15 files changed

Lines changed: 115 additions & 137 deletions

src/numbers/methods/isEven.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ import { isInteger } from "./isInteger";
33
import { toNumber } from "./toNumber";
44

55
export function isEven(num: Numberifiable): num is number {
6-
const saneNum = toNumber(num);
7-
return isInteger(saneNum) && (saneNum & 1) === 0;
6+
return isInteger(num) && (toNumber(num) & 1) === 0;
87
}

tests/Number.test.ts

Lines changed: 0 additions & 122 deletions
This file was deleted.

tests/numbers.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { N } from "@auaust/primitive-kit";
2+
3+
import { describe, expect, it } from "vitest";
4+
5+
describe("N() static class", () => {
6+
it("should be callable without new", () => {
7+
expect(N(2)).toBe(2);
8+
expect(N("2")).toBe(2);
9+
expect(
10+
N({
11+
toString() {
12+
return "0b1010";
13+
},
14+
})
15+
).toBe(10);
16+
});
17+
});

tests/numbers/abs.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { describe, expect, it } from "vitest";
44

55
describe("abs()", () => {
66
it("should work", () => {
7-
expect(abs).toBeTypeOf("function");
7+
expect(abs(2)).toBe(2);
8+
expect(abs(-2)).toBe(2);
9+
expect(abs("2.42")).toBe(2.42);
10+
expect(abs(" -2.42 ")).toBe(2.42);
811
});
912
});

tests/numbers/ceil.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { describe, expect, it } from "vitest";
44

55
describe("ceil()", () => {
66
it("should work", () => {
7-
expect(ceil).toBeTypeOf("function");
7+
expect(ceil(2.42)).toBe(3);
8+
expect(ceil(-2.42)).toBe(-2);
9+
expect(ceil("2.42")).toBe(3);
810
});
911
});

tests/numbers/clamp.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { describe, expect, it } from "vitest";
44

55
describe("clamp()", () => {
66
it("should work", () => {
7-
expect(clamp).toBeTypeOf("function");
7+
expect(clamp(2, 3, 5)).toBe(3);
8+
expect(clamp(4, 3, 5)).toBe(4);
9+
expect(clamp(6, 3, 5)).toBe(5);
810
});
911
});

tests/numbers/floor.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { describe, expect, it } from "vitest";
44

55
describe("floor()", () => {
66
it("should work", () => {
7-
expect(floor).toBeTypeOf("function");
7+
expect(floor(2.42)).toBe(2);
8+
expect(floor(-2.42)).toBe(-3);
9+
expect(floor("2.42")).toBe(2);
810
});
911
});

tests/numbers/isBetween.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,29 @@ import { isBetween } from "@auaust/primitive-kit/numbers";
33
import { describe, expect, it } from "vitest";
44

55
describe("isBetween()", () => {
6-
it("should work", () => {
7-
expect(isBetween).toBeTypeOf("function");
6+
it("should return true if the number is between the two bounds inclusive", () => {
7+
expect(isBetween(4, 3, 5)).toBe(true);
8+
expect(isBetween(3, 3, 3)).toBe(true);
9+
expect(isBetween(5, 3, 5)).toBe(true);
10+
});
11+
12+
it("should return false if the number is not between the two bounds inclusive", () => {
13+
expect(isBetween(2, 3, 5)).toBe(false);
14+
expect(isBetween(6, 3, 5)).toBe(false);
15+
});
16+
17+
it("should return false for any bounds if the number is NaN", () => {
18+
expect(isBetween(NaN, 3, 5)).toBe(false);
19+
expect(isBetween(4, NaN, 5)).toBe(false);
20+
expect(isBetween(4, 3, NaN)).toBe(false);
21+
expect(isBetween(NaN, NaN, NaN)).toBe(false);
22+
});
23+
24+
it("should hendle Infinity and -Infinity as lower than or greater than checks", () => {
25+
expect(isBetween(4, -Infinity, Infinity)).toBe(true);
26+
expect(isBetween(10, 0, Infinity)).toBe(true);
27+
expect(isBetween(-10, 0, Infinity)).toBe(false);
28+
expect(isBetween(4, -Infinity, 5)).toBe(true);
29+
expect(isBetween(6, -Infinity, 5)).toBe(false);
830
});
931
});

tests/numbers/isEven.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import { describe, expect, it } from "vitest";
44

55
describe("isEven()", () => {
66
it("should work", () => {
7-
expect(isEven).toBeTypeOf("function");
7+
expect(isEven(0)).toBe(true);
8+
expect(isEven(2)).toBe(true);
9+
expect(isEven(3)).toBe(false);
10+
expect(isEven(2.42)).toBe(false);
11+
expect(isEven(2.0)).toBe(true);
12+
expect(isEven(-1)).toBe(false);
13+
expect(isEven(-1292)).toBe(true);
14+
expect(
15+
isEven({
16+
toString() {
17+
return "1.0";
18+
},
19+
})
20+
).toBe(false);
821
});
922
});

tests/numbers/isMultipleOf.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { describe, expect, it } from "vitest";
44

55
describe("isMultipleOf()", () => {
66
it("should work", () => {
7-
expect(isMultipleOf).toBeTypeOf("function");
7+
expect(isMultipleOf(2, 2)).toBe(true);
8+
expect(isMultipleOf(3, 2)).toBe(false);
9+
expect(isMultipleOf(2.42, 2)).toBe(false);
10+
expect(isMultipleOf(2.0, 2)).toBe(true);
11+
expect(isMultipleOf(4.5, "1.5")).toBe(true);
812
});
913
});

0 commit comments

Comments
 (0)