-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.test.ts
More file actions
137 lines (113 loc) · 5.3 KB
/
sort.test.ts
File metadata and controls
137 lines (113 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { sort, Classification, type Package } from "./sort";
describe("sort", () => {
// Boundary: exactly at thresholds
it("classifies as SPECIAL when width is exactly at threshold", () => {
const pkg: Package = { width: 150, height: 10, length: 10, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
it("classifies as SPECIAL when mass is exactly at threshold", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: 20 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
// Boundary: just below thresholds
it("classifies as STANDARD when just below all thresholds", () => {
const pkg: Package = { width: 99, height: 99, length: 99, mass: 19.9 };
expect(sort(pkg)).toBe(Classification.STANDARD);
});
// Boundary: just above thresholds
it("classifies as SPECIAL when just above width threshold", () => {
const pkg: Package = { width: 150.1, height: 10, length: 10, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
it("classifies as SPECIAL when just above mass threshold", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: 20.1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
// Volume threshold
it("classifies as SPECIAL when volume is exactly at threshold", () => {
const pkg: Package = { width: 100, height: 100, length: 100, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
it("classifies as SPECIAL when volume is just above threshold", () => {
const pkg: Package = { width: 100, height: 100, length: 100.01, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
// Missing/undefined fields
it("throws error when width is missing", () => {
const pkg = { height: 10, length: 10, mass: 1 } as unknown as Package;
expect(() => sort(pkg)).toThrow();
});
it("throws error when mass is undefined", () => {
const pkg = { width: 10, height: 10, length: 10, mass: undefined } as unknown as Package;
expect(() => sort(pkg)).toThrow();
});
// Floating point values
it("classifies as SPECIAL for floating point just above threshold", () => {
const pkg: Package = { width: 150.0001, height: 10, length: 10, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
// Extreme values
it("classifies as SPECIAL for extremely large width", () => {
const pkg: Package = { width: 1e6, height: 10, length: 10, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
it("classifies as STANDARD for very small positive mass", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: 0.0001 };
expect(sort(pkg)).toBe(Classification.STANDARD);
});
it("classifies as STANDARD when under all thresholds", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: 1 };
expect(sort(pkg)).toBe(Classification.STANDARD);
});
it("classifies as SPECIAL when bulky only", () => {
const pkg: Package = { width: 200, height: 10, length: 10, mass: 1 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
it("classifies as SPECIAL when heavy only", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: 25 };
expect(sort(pkg)).toBe(Classification.SPECIAL);
});
it("classifies as REJECTED when both bulky and heavy", () => {
const pkg: Package = { width: 200, height: 200, length: 200, mass: 25 };
expect(sort(pkg)).toBe(Classification.REJECTED);
});
// Error conditions
it("throws error on negative dimensions", () => {
const pkg: Package = { width: -10, height: 10, length: 10, mass: 1 };
expect(() => sort(pkg)).toThrow();
});
it("throws error on zero mass", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: 0 };
expect(() => sort(pkg)).toThrow();
});
it("throws error on non-numeric input", () => {
const pkg = { width: "a", height: 10, length: 10, mass: 1 } as unknown as Package;
expect(() => sort(pkg)).toThrow();
});
// Edge: zero for each dimension
it("throws error on zero width", () => {
const pkg: Package = { width: 0, height: 10, length: 10, mass: 1 };
expect(() => sort(pkg)).toThrow();
});
it("throws error on zero height", () => {
const pkg: Package = { width: 10, height: 0, length: 10, mass: 1 };
expect(() => sort(pkg)).toThrow();
});
it("throws error on zero length", () => {
const pkg: Package = { width: 10, height: 10, length: 0, mass: 1 };
expect(() => sort(pkg)).toThrow();
});
// Edge: negative for each property
it("throws error on negative height", () => {
const pkg: Package = { width: 10, height: -10, length: 10, mass: 1 };
expect(() => sort(pkg)).toThrow();
});
it("throws error on negative length", () => {
const pkg: Package = { width: 10, height: 10, length: -10, mass: 1 };
expect(() => sort(pkg)).toThrow();
});
it("throws error on negative mass", () => {
const pkg: Package = { width: 10, height: 10, length: 10, mass: -1 };
expect(() => sort(pkg)).toThrow();
});
});