implemented tests for reorderElements

main
Inga 🏳‍🌈 1 year ago
parent 252554df6e
commit 28ee56b4f2
  1. 1
      .gitignore
  2. 8924
      package-lock.json
  3. 2
      package.json
  4. 49
      src/shared/collections.test.ts

1
.gitignore vendored

@ -130,3 +130,4 @@ dist
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
.tap

8924
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -7,6 +7,7 @@
"start-release": "npm run build && serve dist", "start-release": "npm run build && serve dist",
"lint": "eslint \"{src,test}/**/*.{ts,tsx}\"", "lint": "eslint \"{src,test}/**/*.{ts,tsx}\"",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"test": "tap run",
"prebuild": "npm run lint && npm run typecheck", "prebuild": "npm run lint && npm run typecheck",
"preview": "vite preview" "preview": "vite preview"
}, },
@ -38,6 +39,7 @@
"eslint-plugin-react": "^7.33.2", "eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"serve": "^14.2.1", "serve": "^14.2.1",
"tap": "^18.6.1",
"typescript": "^5.2.2", "typescript": "^5.2.2",
"vite": "^4.3.2" "vite": "^4.3.2"
} }

@ -0,0 +1,49 @@
import t from 'tap';
import { reorderElements } from './collections.js';
void t.test('reorderElements', (t) => {
const checkReordering = (
oldIndex: number,
newIndex: number,
expected: string,
) => {
t.match(
reorderElements('abcde'.split(''), oldIndex, newIndex),
expected.split(''),
);
};
checkReordering(0, -1, 'bcde');
checkReordering(1, -1, 'acde');
checkReordering(2, -1, 'abde');
checkReordering(3, -1, 'abce');
checkReordering(4, -1, 'abcd');
checkReordering(5, -1, 'abcde');
checkReordering(0, 0, 'abcde');
checkReordering(0, 1, 'bacde');
checkReordering(0, 2, 'bcade');
checkReordering(0, 3, 'bcdae');
checkReordering(0, 4, 'bcdea');
checkReordering(1, 0, 'bacde');
checkReordering(1, 1, 'abcde');
checkReordering(1, 2, 'acbde');
checkReordering(1, 3, 'acdbe');
checkReordering(1, 4, 'acdeb');
checkReordering(2, 0, 'cabde');
checkReordering(2, 1, 'acbde');
checkReordering(2, 2, 'abcde');
checkReordering(2, 3, 'abdce');
checkReordering(2, 4, 'abdec');
checkReordering(3, 0, 'dabce');
checkReordering(3, 1, 'adbce');
checkReordering(3, 2, 'abdce');
checkReordering(3, 3, 'abcde');
checkReordering(3, 4, 'abced');
checkReordering(4, 0, 'eabcd');
checkReordering(4, 1, 'aebcd');
checkReordering(4, 2, 'abecd');
checkReordering(4, 3, 'abced');
checkReordering(4, 4, 'abcde');
t.end();
});
Loading…
Cancel
Save