Skip to content

Commit a584386

Browse files
committed
test: define MSDRadixSort tests
1 parent 95b1493 commit a584386

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"start:default": "export SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
1515
"start:win32": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
1616
"test": "react-scripts test",
17+
"test-msdrs": "npm test -- ./src/algorithms/controllers/MSDRadixSort.test.js",
1718
"test-uf": "npm test -- ./src/algorithms/controllers/unionFind.test.js",
1819
"test-234t": "npm test -- ./src/algorithms/controllers/TTFTree.test.js"
1920
},
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 */
7+
8+
import rexSort from './MSDRadixSort';
9+
10+
// Simple stub for the chunker
11+
const chunker = {
12+
add: () => {},
13+
};
14+
15+
describe('rexsort', () => {
16+
it('sorts empty array', () => {
17+
expect(rexSort.run(chunker, { nodes: [] })).toEqual([]);
18+
});
19+
it('sorts single element', () => {
20+
expect(rexSort.run(chunker, { nodes: [4] })).toEqual([4]);
21+
});
22+
it('sorts two values', () => {
23+
expect(rexSort.run(chunker, { nodes: [1, 2] })).toEqual([1, 2]);
24+
});
25+
it('sorts two values in reverse', () => {
26+
expect(rexSort.run(chunker, { nodes: [2, 1] })).toEqual([1, 2]);
27+
});
28+
it('sorts odd list', () => {
29+
expect(rexSort.run(chunker, { nodes: [1, 4, 3] })).toEqual([1, 3, 4]);
30+
});
31+
it('sorts even list', () => {
32+
expect(rexSort.run(chunker, { nodes: [1, 4, 3, 2] })).toEqual([1, 2, 3, 4]);
33+
});
34+
it('sorts ordered elements', () => {
35+
expect(rexSort.run(chunker, { nodes: [1, 2, 3, 4, 5] })).toEqual([1, 2, 3, 4, 5]);
36+
});
37+
it('sorts reversed elements', () => {
38+
expect(rexSort.run(chunker, { nodes: [5, 4, 3, 2, 1] })).toEqual([1, 2, 3, 4, 5]);
39+
});
40+
it('sorts list with duplicates', () => {
41+
expect(rexSort.run(chunker, { nodes: [1, 3, 2, 5, 3, 2] })).toEqual([1, 2, 2, 3, 3, 5]);
42+
});
43+
});

src/algorithms/controllers/collapseChunkPlugin.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const importsThis = ['quickSort', 'quickSortM3', 'msort_arr_td',
1111

1212
// eslint-disable-next-line import/no-cycle
1313
// See also accompanying mods/hooks in src/context/GlobalState.js and
14-
// src/context/actions.js
15-
import { GlobalActions } from '../../context/actions';
14+
// src/context/actions.js
15+
// import { GlobalActions } from '../../context/actions';
1616

1717
// not sure if finding the running algorithm needs such complex code, but this
1818
// seems to work...
@@ -57,4 +57,3 @@ export function onCollapseChange(chunker) {
5757
if (!importsThis.includes(alg_name)) return;
5858
chunker.refresh();
5959
}
60-

0 commit comments

Comments
 (0)