Compare commits

...

2 Commits

Author SHA1 Message Date
Barret Schloerke
936f985273 Merge branch 'master' into ts_unit
* master:
  Move `./srcts` configs to top level to support types installation from GitHub (#3425)
  insertTab() now handles position correctly when target is NULL (#3404)
  yarn add node-gyp; yarn build (#3424)
  Export TypeScript type definitions to local folder (#3418)
  TypeScript: Remove `any` types / improve type definitions (#3414)
  Better color constrasting in sliderInput() (#3366)
  Use ggplot2::get_alt_text() if available to provide better default alt text (#3398)
  Set selectize dropdownParent to "body" to prevent clipping
2021-06-15 14:21:30 -04:00
Barret Schloerke
b0cacdd2e9 Add mergeSort test 2021-06-10 14:58:46 -04:00

View File

@@ -1,5 +1,33 @@
import { asArray } from "../";
import { asArray, mergeSort } from "../";
test("integer is converted to integer array", () => {
expect(asArray(4)).toStrictEqual([4]);
});
test("mergeSort merges two arrays", () => {
function shuffleArray<T>(arr: Array<T>): Array<T> {
if (arr.length < 2) return arr;
const copy = [...arr];
copy.sort(() => Math.random() - 0.5);
for (let i = 0; i < copy.length; i++) {
// if at least one entry is different, return it
if (arr[i] !== copy[i]) {
return copy;
}
}
// Try shuffling again (rare)
return shuffleArray(arr);
}
const original = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5];
const input = shuffleArray(original);
const output = mergeSort(input, function (x, y) {
return x - y;
});
expect(original).not.toEqual(input);
expect(original).toEqual(output);
});