Skip to content

Commit 9c70f4a

Browse files
committed
feat: fix test sort data and return default value
1 parent 5a26d13 commit 9c70f4a

2 files changed

Lines changed: 19 additions & 24 deletions

File tree

src/helpers/sort.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("sortProducts", () => {
7272
["E", "1", "AB 1"],
7373
["F", "1", "AB 10"],
7474
["H", "1", "AB 9"],
75-
["H", "1", "AB 7"]
75+
["J", "1", "AB 7"]
7676
];
7777
const [columns, ...rows] = data;
7878

@@ -82,7 +82,7 @@ describe("sortProducts", () => {
8282
expect(result).toEqual([
8383
["product_code", "quantity", "pick_location"],
8484
["E", "1", "AB 1"],
85-
["H", "1", "AB 7"],
85+
["J", "1", "AB 7"],
8686
["H", "1", "AB 9"],
8787
["F", "1", "AB 10"]
8888
]);
@@ -92,13 +92,14 @@ describe("sortProducts", () => {
9292
const data: ProductTuple[] = [
9393
["product_code", "quantity", "pick_location"],
9494
["B1237", "2", "A 10"],
95-
["B1237", "2", "Z 10"],
95+
["B1237", "2", "A 10"],
96+
["B12311", "2", "Z 10"],
9697
["B1234", "2", "Z 3"],
97-
["B1234", "2", "A 3"],
98-
["B1235", "3", "Z 2"],
99-
["B1236", "4", "Z 1"],
100-
["B1235", "3", "A 2"],
101-
["B1236", "4", "A 1"]
98+
["B1235", "2", "A 3"],
99+
["B1236", "3", "Z 2"],
100+
["B1238", "4", "Z 1"],
101+
["B1239", "3", "A 2"],
102+
["B12310", "4", "A 1"]
102103
];
103104

104105
const [columns, ...rows] = data;
@@ -107,14 +108,14 @@ describe("sortProducts", () => {
107108
const result = [columns, ...sortedRows];
108109
expect(result).toEqual([
109110
["product_code", "quantity", "pick_location"],
110-
["B1236", "4", "A 1"],
111-
["B1235", "3", "A 2"],
112-
["B1234", "2", "A 3"],
113-
["B1237", "2", "A 10"],
114-
["B1236", "4", "Z 1"],
115-
["B1235", "3", "Z 2"],
111+
["B12310", "4", "A 1"],
112+
["B1239", "3", "A 2"],
113+
["B1235", "2", "A 3"],
114+
["B1237", "4", "A 10"],
115+
["B1238", "4", "Z 1"],
116+
["B1236", "3", "Z 2"],
116117
["B1234", "2", "Z 3"],
117-
["B1237", "2", "Z 10"]
118+
["B12311", "2", "Z 10"]
118119
]);
119120
});
120121
});
@@ -219,7 +220,6 @@ describe("compareStrings", () => {
219220
expect(() => compareStrings("AB", "ABC")).toThrowError();
220221
expect(() => compareStrings("AB", "AB")).not.toThrowError();
221222
});
222-
// });
223223
describe("single char", () => {
224224
// Case 1: A, A - single chars, both match
225225
it("should return EQUALS if single chars, both match", () => {

src/helpers/sort.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,9 @@ export const compareStrings = (a: string, b: string) => {
122122
}
123123

124124
// Case 8: Z, AA - single char, and multiple chars
125-
if (a.length === 1 && b.length > 1) {
126-
return Compare.LESS_THAN;
127-
}
128-
129-
// default case and return value
130-
// should never be hit
131-
return Compare.EQUALS;
125+
// if (a.length === 1 && b.length > 1) {
126+
return Compare.LESS_THAN;
127+
// }
132128
};
133129

134130
export const sortProducts = (products: ProductTuple[], method: SortMethod) => {
@@ -169,7 +165,6 @@ export const sortProducts = (products: ProductTuple[], method: SortMethod) => {
169165

170166
// swap based on bay
171167
if (compare === Compare.BIGGER_THAN) {
172-
// TODO it was saying this wasn't tested before.
173168
swap(result, i, i + 1);
174169
}
175170
}

0 commit comments

Comments
 (0)