Skip to content

Commit 2f83722

Browse files
committed
Merge branch '2024_sem2_dev' of https://github.com/JarrettChen217/ITP_team025_staticsound into 2024_sem2_dev
2 parents 1008be5 + 5dd0d0d commit 2f83722

File tree

1 file changed

+19
-68
lines changed

1 file changed

+19
-68
lines changed

src/algorithms/controllers/AVLTree.test.js

Lines changed: 19 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
/* The purpose of the test here is to detect whether the correct result is generated
2-
under the legal input, not to test its robustness, because this is not considered
3-
in the implementation process of the algorithm.
4-
*/
5-
6-
/* eslint-disable no-undef */
1+
/**
2+
* The purpose of the test here is to detect whether the correct result is generated
3+
* under the legal input, help developers identify potential errors that may arise
4+
* from the rotation logic.
5+
*
6+
* @author StaticSound Team
7+
* - Hao Chen (1314613) <[email protected]>
8+
* - Jiayi Sun (1305340) <[email protected]>
9+
* - Junhao Zhu (1261757) <[email protected]>
10+
* - Ziyu Wang (1243302) <[email protected]>
11+
* - Gaoyongle Zhang (1346309) <[email protected]>
12+
*
13+
* @since 10/10/2024
14+
*/
715

816
import AVLTreeInsertion from './AVLTreeInsertion';
917

@@ -13,7 +21,8 @@ const chunker = {
1321
};
1422

1523
describe('AVLTreeInsertion', () => {
16-
// Simple rotation: only envolves one rotate
24+
// Simple rotation: only envolves one rotate.
25+
// The detailed test cases are as follows:
1726
it('[Simple] No rotation', () => {
1827
const E = [10, 5, 15];
1928
const result = {
@@ -71,9 +80,6 @@ describe('AVLTreeInsertion', () => {
7180
left: null,
7281
right: null
7382
}
74-
// 1: { "height": 1, "left": null, "right": null, "par": 2 },
75-
// 2: { "height": 2, "left": 1, "right": 3, "par": null },
76-
// 3: { "height": 1, "left": null, "right": null, "par": 2 }
7783
};
7884
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
7985
});
@@ -94,9 +100,6 @@ describe('AVLTreeInsertion', () => {
94100
left: null,
95101
right: null
96102
}
97-
// 1: { "height": 1, "left": null, "right": null, "par": 2 },
98-
// 2: { "height": 2, "left": 1, "right": 3, "par": null },
99-
// 3: { "height": 1, "left": null, "right": null, "par": 2 }
100103
};
101104
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
102105
});
@@ -117,12 +120,12 @@ describe('AVLTreeInsertion', () => {
117120
left: null,
118121
right: null
119122
}
120-
// 1: { "height": 1, "left": null, "right": null, "par": 2 },
121-
// 2: { "height": 2, "left": 1, "right": 3, "par": null },
122-
// 3: { "height": 1, "left": null, "right": null, "par": 2 }
123123
};
124124
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
125125
});
126+
127+
// Complex rotation: envolves multiple rotates.
128+
// The detailed test cases are as follows:
126129
it('[Complex] Complex rotates 1', () => {
127130
const E = [4, 5, 7, 9, 8];
128131
const result = {
@@ -150,11 +153,6 @@ describe('AVLTreeInsertion', () => {
150153
right: null
151154
}
152155
}
153-
// 4: { "height": 1, "left": null, "right": null, "par": 5 },
154-
// 5: { "height": 3, "left": 4, "right": 8, "par": null },
155-
// 7: { "height": 1, "left": null, "right": null, "par": 8 },
156-
// 9: { "height": 1, "left": null, "right": null, "par": 8 },
157-
// 8: { "height": 2, "left": 7, "right": 9, "par": 5 }
158156
};
159157
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
160158
});
@@ -225,19 +223,6 @@ describe('AVLTreeInsertion', () => {
225223
right: null
226224
}
227225
}
228-
// 40: { "height": 4, "left": 20, "right": 60, "par": null },
229-
// 20: { "height": 3, "left": 10, "right": 30, "par": 40 },
230-
// 60: { "height": 3, "left": 50, "right": 70, "par": 40 },
231-
// 10: { "height": 2, "left": 5, "right": 15, "par": 20 },
232-
// 30: { "height": 2, "left": 25, "right": 35, "par": 20 },
233-
// 50: { "height": 2, "left": null, "right": 55, "par": 60 },
234-
// 70: { "height": 2, "left": 65, "right": null, "par": 60 },
235-
// 5: { "height": 1, "left": null, "right": null, "par": 10 },
236-
// 15: { "height": 1, "left": null, "right": null, "par": 10 },
237-
// 25: { "height": 1, "left": null, "right": null, "par": 30 },
238-
// 35: { "height": 1, "left": null, "right": null, "par": 30 },
239-
// 55: { "height": 1, "left": null, "right": null, "par": 50 },
240-
// 65: { "height": 1, "left": null, "right": null, "par": 70 }
241226
};
242227
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
243228
});
@@ -313,20 +298,6 @@ describe('AVLTreeInsertion', () => {
313298
right: null
314299
}
315300
}
316-
// 50: { "height": 4, "left": 30, "right": 70, "par": null },
317-
// 30: { "height": 3, "left": 20, "right": 40, "par": 50 },
318-
// 70: { "height": 3, "left": 60, "right": 80, "par": 50 },
319-
// 20: { "height": 2, "left": 10, "right": 25, "par": 30 },
320-
// 40: { "height": 2, "left": 35, "right": 45, "par": 30 },
321-
// 60: { "height": 2, "left": 58, "right": 65, "par": 70 },
322-
// 80: { "height": 2, "left": 75, "right": null, "par": 70 },
323-
// 10: { "height": 1, "left": null, "right": null, "par": 20 },
324-
// 25: { "height": 1, "left": null, "right": null, "par": 20 },
325-
// 35: { "height": 1, "left": null, "right": null, "par": 40 },
326-
// 45: { "height": 1, "left": null, "right": null, "par": 40 },
327-
// 58: { "height": 1, "left": null, "right": null, "par": 60 },
328-
// 65: { "height": 1, "left": null, "right": null, "par": 60 },
329-
// 75: { "height": 1, "left": null, "right": null, "par": 80 }
330301
};
331302
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
332303
});
@@ -432,26 +403,6 @@ describe('AVLTreeInsertion', () => {
432403
}
433404
}
434405
}
435-
// 71: { "height": 5, "left": 29, "right": 168, "par": null },
436-
// 54: { "height": 3, "left": 36, "right": 64, "par": 29 },
437-
// 168: { "height": 4, "left": 121, "right": 199, "par": 71 },
438-
// 29: { "height": 4, "left": 12, "right": 54, "par": 71 },
439-
// 121: { "height": 3, "left": 85, "right": 144, "par": 168 },
440-
// 199: { "height": 3, "left": 175, "right": 211, "par": 168 },
441-
// 12: { "height": 2, "left": 2, "right": 27, "par": 29 },
442-
// 36: { "height": 1, "left": null, "right": null, "par": 54 },
443-
// 64: { "height": 2, "left": 56, "right": null, "par": 54 },
444-
// 85: { "height": 2, "left": 73, "right": 102, "par": 121 },
445-
// 144: { "height": 2, "left": 135, "right": null, "par": 121 },
446-
// 175: { "height": 1, "left": null, "right": null, "par": 199 },
447-
// 211: { "height": 2, "left": null, "right": 307, "par": 199 },
448-
// 2: { "height": 1, "left": null, "right": null, "par": 12 },
449-
// 27: { "height": 1, "left": null, "right": null, "par": 12 },
450-
// 56: { "height": 1, "left": null, "right": null, "par": 64 },
451-
// 73: { "height": 1, "left": null, "right": null, "par": 85 },
452-
// 102: { "height": 1, "left": null, "right": null, "par": 85 },
453-
// 135: { "height": 1, "left": null, "right": null, "par": 144 },
454-
// 307: { "height": 1, "left": null, "right": null, "par": 211 }
455406
};
456407
expect(AVLTreeInsertion.run(chunker, { nodes: E })).toEqual(result);
457408
});

0 commit comments

Comments
 (0)