@sparted/shared-library 1.0.6 → 1.0.8-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +40 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +17 -0
- package/.gitignore +37 -0
- package/CHANGELOG.md +34 -0
- package/README.md +26 -0
- package/{cdn → dist/cdn}/cdn.factory.js +1 -1
- package/dist/cdn/cdn.factory.js.map +1 -0
- package/dist/github/commits/create-git-blob.d.ts +26 -0
- package/dist/github/commits/create-git-blob.js +42 -0
- package/dist/github/commits/create-git-blob.js.map +1 -0
- package/dist/github/commits/create-git-commit.d.ts +23 -0
- package/dist/github/commits/create-git-commit.js +39 -0
- package/dist/github/commits/create-git-commit.js.map +1 -0
- package/dist/github/commits/create-git-tree.d.ts +29 -0
- package/dist/github/commits/create-git-tree.js +47 -0
- package/dist/github/commits/create-git-tree.js.map +1 -0
- package/dist/github/commits/get-sha-last-commit-of-branch.d.ts +21 -0
- package/dist/github/commits/get-sha-last-commit-of-branch.js +35 -0
- package/dist/github/commits/get-sha-last-commit-of-branch.js.map +1 -0
- package/dist/github/commits/get-tree-by-commit-sha.d.ts +23 -0
- package/dist/github/commits/get-tree-by-commit-sha.js +37 -0
- package/dist/github/commits/get-tree-by-commit-sha.js.map +1 -0
- package/dist/github/commits/index.d.ts +6 -0
- package/dist/github/commits/index.js +20 -0
- package/dist/github/commits/run-new-commit-process.d.ts +27 -0
- package/dist/github/commits/run-new-commit-process.js +49 -0
- package/dist/github/commits/run-new-commit-process.js.map +1 -0
- package/dist/github/commits/utils.d.ts +1 -0
- package/dist/github/commits/utils.js +29 -0
- package/dist/github/commits/utils.js.map +1 -0
- package/dist/github/github.d.ts +22 -0
- package/dist/github/github.js +50 -0
- package/dist/github/github.js.map +1 -0
- package/dist/github/index.d.ts +1 -0
- package/dist/github/index.js +10 -0
- package/dist/index.d.ts +15 -0
- package/{index.js → dist/index.js} +2 -0
- package/{index.js.map → dist/index.js.map} +1 -1
- package/dist/package.json +65 -0
- package/dist/string/index.js.map +1 -0
- package/dist/time/index.js.map +1 -0
- package/global.d.ts +2 -0
- package/package.json +5 -1
- package/rollup.config.ts +15 -0
- package/src/array/__tests__/array-to-map.test.ts +50 -0
- package/src/array/__tests__/get-values-from-keys.test.ts +14 -0
- package/src/array/array-to-map.ts +32 -0
- package/src/array/get-values-from-keys.ts +3 -0
- package/src/array/index.ts +2 -0
- package/src/cdn/__tests__/cdn.factory.test.ts +120 -0
- package/src/cdn/__tests__/utils.test.ts +456 -0
- package/src/cdn/cdn.factory.ts +63 -0
- package/src/cdn/index.ts +2 -0
- package/src/cdn/types/cdn-factory.type.ts +35 -0
- package/src/cdn/types/index.ts +1 -0
- package/src/cdn/utils/extract-info-from-url.util.ts +21 -0
- package/src/cdn/utils/get-cdn-from-s3-url.util.ts +20 -0
- package/src/cdn/utils/get-cdn-url.util.ts +26 -0
- package/src/formatting/__tests__/format-number.test.ts +11 -0
- package/src/formatting/format-number.ts +14 -0
- package/src/formatting/index.ts +1 -0
- package/src/fp/__tests__/run-while.test.ts +29 -0
- package/src/fp/index.ts +1 -0
- package/src/fp/run-while.ts +54 -0
- package/src/github/commits/create-git-blob.ts +57 -0
- package/src/github/commits/create-git-commit.ts +57 -0
- package/src/github/commits/create-git-tree.ts +68 -0
- package/src/github/commits/get-sha-last-commit-of-branch.ts +50 -0
- package/src/github/commits/get-tree-by-commit-sha.ts +52 -0
- package/src/github/commits/index.ts +6 -0
- package/src/github/commits/run-new-commit-process.ts +88 -0
- package/src/github/commits/utils.ts +31 -0
- package/src/github/github.ts +69 -0
- package/src/github/index.ts +1 -0
- package/src/http/__tests__/encode-search-object.test.ts +34 -0
- package/src/http/__tests__/fetch-with-timeout.test.ts +50 -0
- package/src/http/encode-search-object.ts +39 -0
- package/src/http/fetch-with-timeout.ts +24 -0
- package/src/http/index.ts +2 -0
- package/{index.d.ts → src/index.ts} +15 -14
- package/src/linked-list/__tests__/apply-diff-linked-list.test.ts +103 -0
- package/src/linked-list/__tests__/create-linked-list.test.ts +204 -0
- package/src/linked-list/__tests__/find-linked-list.test.ts +40 -0
- package/src/linked-list/__tests__/get-linked-list.test.ts +28 -0
- package/src/linked-list/__tests__/insert-linked-list.test.ts +186 -0
- package/src/linked-list/__tests__/linked-list-utils.test.ts +252 -0
- package/src/linked-list/__tests__/reduce-linked-list.test.ts +31 -0
- package/src/linked-list/__tests__/remove-linked-list.test.ts +129 -0
- package/src/linked-list/__tests__/update-linked-list.test.ts +53 -0
- package/src/linked-list/__tests__/while-linked-list.test.ts +58 -0
- package/src/linked-list/apply-diff-linked-list.ts +35 -0
- package/src/linked-list/create-linked-list.ts +79 -0
- package/src/linked-list/find-linked-list.ts +26 -0
- package/src/linked-list/get-linked-list.ts +9 -0
- package/src/linked-list/index.ts +2 -0
- package/src/linked-list/insert-linked-list.ts +50 -0
- package/src/linked-list/linked-list-utils.ts +143 -0
- package/src/linked-list/reduce-linked-list.ts +18 -0
- package/src/linked-list/remove-linked-list.ts +36 -0
- package/src/linked-list/type.ts +38 -0
- package/src/linked-list/update-linked-list.ts +29 -0
- package/src/linked-list/while-linked-list.ts +33 -0
- package/src/math/__tests__/clamp-number.test.ts +30 -0
- package/src/math/__tests__/interpolate.test.ts +28 -0
- package/src/math/__tests__/number-range.test.ts +59 -0
- package/src/math/__tests__/random-number.test.ts +11 -0
- package/src/math/clamp-number.ts +8 -0
- package/src/math/index.ts +4 -0
- package/src/math/interpolate.ts +18 -0
- package/src/math/number-range.ts +16 -0
- package/src/math/random-number.ts +10 -0
- package/src/object/__tests__/merge-deep.test.ts +56 -0
- package/src/object/index.ts +1 -0
- package/src/object/merge-deep.ts +27 -0
- package/src/parsing/__tests__/parse-boolean.test.ts +15 -0
- package/src/parsing/__tests__/parse-enum.test.ts +19 -0
- package/src/parsing/__tests__/parse-number.test.ts +20 -0
- package/src/parsing/index.ts +3 -0
- package/src/parsing/parse-boolean.ts +10 -0
- package/src/parsing/parse-enum.ts +16 -0
- package/src/parsing/parse-number.ts +12 -0
- package/src/predicates/__tests__/is-function.test.ts +11 -0
- package/src/predicates/__tests__/is-null.test.ts +11 -0
- package/src/predicates/__tests__/is-object.test.ts +11 -0
- package/src/predicates/__tests__/is-primitive.test.ts +42 -0
- package/src/predicates/__tests__/is-undefined.test.ts +11 -0
- package/src/predicates/__tests__/is-uuid.test.ts +13 -0
- package/src/predicates/index.ts +5 -0
- package/src/predicates/is-function.ts +3 -0
- package/src/predicates/is-null.ts +3 -0
- package/src/predicates/is-object.ts +3 -0
- package/src/predicates/is-primitive.ts +19 -0
- package/src/predicates/is-undefined.ts +3 -0
- package/src/predicates/is-uuid.ts +3 -0
- package/src/promise/__tests__/delay.test.ts +13 -0
- package/src/promise/__tests__/execute-or-resolve-default.test.ts +25 -0
- package/src/promise/__tests__/execute-with-delay.test.ts +24 -0
- package/src/promise/delay.ts +3 -0
- package/src/promise/execute-or-resolve-default.ts +14 -0
- package/src/promise/execute-with-delay.ts +6 -0
- package/src/promise/index.ts +3 -0
- package/src/string/__tests__/replace-in-template.test.ts +52 -0
- package/src/string/index.ts +1 -0
- package/src/string/replace-in-template.ts +45 -0
- package/src/time/__tests__/convert.test.ts +14 -0
- package/src/time/__tests__/format-minutes.test.ts +10 -0
- package/src/time/__tests__/get-time-diff-as-string.test.ts +128 -0
- package/src/time/constants.ts +4 -0
- package/src/time/convert.ts +5 -0
- package/src/time/format-minutes.ts +9 -0
- package/src/time/get-time-diff-as-string.ts +196 -0
- package/src/time/index.ts +4 -0
- package/src/types/function.ts +1 -0
- package/src/types/general.ts +8 -0
- package/src/types/index.ts +4 -0
- package/src/types/object.ts +33 -0
- package/src/types/search.ts +29 -0
- package/tsconfig.eslint.json +8 -0
- package/tsconfig.json +25 -0
- package/cdn/cdn.factory.js.map +0 -1
- /package/{_virtual → dist/_virtual}/_tslib.js +0 -0
- /package/{_virtual → dist/_virtual}/_tslib.js.map +0 -0
- /package/{array → dist/array}/array-to-map.d.ts +0 -0
- /package/{array → dist/array}/array-to-map.js +0 -0
- /package/{array → dist/array}/array-to-map.js.map +0 -0
- /package/{array → dist/array}/get-values-from-keys.d.ts +0 -0
- /package/{array → dist/array}/get-values-from-keys.js +0 -0
- /package/{array → dist/array}/get-values-from-keys.js.map +0 -0
- /package/{array → dist/array}/index.d.ts +0 -0
- /package/{array → dist/array}/index.js +0 -0
- /package/{array → dist/array}/index.js.map +0 -0
- /package/{cdn → dist/cdn}/cdn.factory.d.ts +0 -0
- /package/{cdn → dist/cdn}/index.d.ts +0 -0
- /package/{cdn → dist/cdn}/index.js +0 -0
- /package/{cdn → dist/cdn}/index.js.map +0 -0
- /package/{cdn → dist/cdn}/types/cdn-factory.type.d.ts +0 -0
- /package/{cdn → dist/cdn}/types/index.d.ts +0 -0
- /package/{cdn → dist/cdn}/types/index.js +0 -0
- /package/{cdn → dist/cdn}/types/index.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/extract-info-from-url.util.d.ts +0 -0
- /package/{cdn → dist/cdn}/utils/extract-info-from-url.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/extract-info-from-url.util.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-from-s3-url.util.d.ts +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-from-s3-url.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-from-s3-url.util.js.map +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-url.util.d.ts +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-url.util.js +0 -0
- /package/{cdn → dist/cdn}/utils/get-cdn-url.util.js.map +0 -0
- /package/{formatting → dist/formatting}/format-number.d.ts +0 -0
- /package/{formatting → dist/formatting}/format-number.js +0 -0
- /package/{formatting → dist/formatting}/format-number.js.map +0 -0
- /package/{formatting → dist/formatting}/index.d.ts +0 -0
- /package/{formatting → dist/formatting}/index.js +0 -0
- /package/{formatting → dist/formatting}/index.js.map +0 -0
- /package/{fp → dist/fp}/index.d.ts +0 -0
- /package/{fp → dist/fp}/index.js +0 -0
- /package/{fp → dist/fp}/index.js.map +0 -0
- /package/{fp → dist/fp}/run-while.d.ts +0 -0
- /package/{fp → dist/fp}/run-while.js +0 -0
- /package/{fp → dist/fp}/run-while.js.map +0 -0
- /package/{time → dist/github/commits}/index.js.map +0 -0
- /package/{linked-list → dist/github}/index.js.map +0 -0
- /package/{http → dist/http}/encode-search-object.d.ts +0 -0
- /package/{http → dist/http}/encode-search-object.js +0 -0
- /package/{http → dist/http}/encode-search-object.js.map +0 -0
- /package/{http → dist/http}/fetch-with-timeout.d.ts +0 -0
- /package/{http → dist/http}/fetch-with-timeout.js +0 -0
- /package/{http → dist/http}/fetch-with-timeout.js.map +0 -0
- /package/{http → dist/http}/index.d.ts +0 -0
- /package/{http → dist/http}/index.js +0 -0
- /package/{http → dist/http}/index.js.map +0 -0
- /package/{linked-list → dist/linked-list}/apply-diff-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/apply-diff-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/apply-diff-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/create-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/create-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/create-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/find-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/find-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/find-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/get-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/get-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/get-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/index.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/index.js +0 -0
- /package/{object → dist/linked-list}/index.js.map +0 -0
- /package/{linked-list → dist/linked-list}/insert-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/insert-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/insert-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/linked-list-utils.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/linked-list-utils.js +0 -0
- /package/{linked-list → dist/linked-list}/linked-list-utils.js.map +0 -0
- /package/{linked-list → dist/linked-list}/reduce-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/reduce-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/reduce-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/remove-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/remove-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/remove-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/type.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/update-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/update-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/update-linked-list.js.map +0 -0
- /package/{linked-list → dist/linked-list}/while-linked-list.d.ts +0 -0
- /package/{linked-list → dist/linked-list}/while-linked-list.js +0 -0
- /package/{linked-list → dist/linked-list}/while-linked-list.js.map +0 -0
- /package/{math → dist/math}/clamp-number.d.ts +0 -0
- /package/{math → dist/math}/clamp-number.js +0 -0
- /package/{math → dist/math}/clamp-number.js.map +0 -0
- /package/{math → dist/math}/index.d.ts +0 -0
- /package/{math → dist/math}/index.js +0 -0
- /package/{math → dist/math}/index.js.map +0 -0
- /package/{math → dist/math}/interpolate.d.ts +0 -0
- /package/{math → dist/math}/interpolate.js +0 -0
- /package/{math → dist/math}/interpolate.js.map +0 -0
- /package/{math → dist/math}/number-range.d.ts +0 -0
- /package/{math → dist/math}/number-range.js +0 -0
- /package/{math → dist/math}/number-range.js.map +0 -0
- /package/{math → dist/math}/random-number.d.ts +0 -0
- /package/{math → dist/math}/random-number.js +0 -0
- /package/{math → dist/math}/random-number.js.map +0 -0
- /package/{object → dist/object}/index.d.ts +0 -0
- /package/{object → dist/object}/index.js +0 -0
- /package/{string → dist/object}/index.js.map +0 -0
- /package/{object → dist/object}/merge-deep.d.ts +0 -0
- /package/{object → dist/object}/merge-deep.js +0 -0
- /package/{object → dist/object}/merge-deep.js.map +0 -0
- /package/{parsing → dist/parsing}/index.d.ts +0 -0
- /package/{parsing → dist/parsing}/index.js +0 -0
- /package/{parsing → dist/parsing}/index.js.map +0 -0
- /package/{parsing → dist/parsing}/parse-boolean.d.ts +0 -0
- /package/{parsing → dist/parsing}/parse-boolean.js +0 -0
- /package/{parsing → dist/parsing}/parse-boolean.js.map +0 -0
- /package/{parsing → dist/parsing}/parse-enum.d.ts +0 -0
- /package/{parsing → dist/parsing}/parse-enum.js +0 -0
- /package/{parsing → dist/parsing}/parse-enum.js.map +0 -0
- /package/{parsing → dist/parsing}/parse-number.d.ts +0 -0
- /package/{parsing → dist/parsing}/parse-number.js +0 -0
- /package/{parsing → dist/parsing}/parse-number.js.map +0 -0
- /package/{predicates → dist/predicates}/index.d.ts +0 -0
- /package/{predicates → dist/predicates}/index.js +0 -0
- /package/{predicates → dist/predicates}/index.js.map +0 -0
- /package/{predicates → dist/predicates}/is-function.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-function.js +0 -0
- /package/{predicates → dist/predicates}/is-function.js.map +0 -0
- /package/{predicates → dist/predicates}/is-null.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-null.js +0 -0
- /package/{predicates → dist/predicates}/is-null.js.map +0 -0
- /package/{predicates → dist/predicates}/is-object.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-object.js +0 -0
- /package/{predicates → dist/predicates}/is-object.js.map +0 -0
- /package/{predicates → dist/predicates}/is-primitive.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-primitive.js +0 -0
- /package/{predicates → dist/predicates}/is-primitive.js.map +0 -0
- /package/{predicates → dist/predicates}/is-undefined.d.ts +0 -0
- /package/{predicates → dist/predicates}/is-undefined.js +0 -0
- /package/{predicates → dist/predicates}/is-undefined.js.map +0 -0
- /package/{predicates → dist/predicates}/is-uuid.d.ts +0 -0
- /package/{promise → dist/promise}/delay.d.ts +0 -0
- /package/{promise → dist/promise}/delay.js +0 -0
- /package/{promise → dist/promise}/delay.js.map +0 -0
- /package/{promise → dist/promise}/execute-or-resolve-default.d.ts +0 -0
- /package/{promise → dist/promise}/execute-or-resolve-default.js +0 -0
- /package/{promise → dist/promise}/execute-or-resolve-default.js.map +0 -0
- /package/{promise → dist/promise}/execute-with-delay.d.ts +0 -0
- /package/{promise → dist/promise}/execute-with-delay.js +0 -0
- /package/{promise → dist/promise}/execute-with-delay.js.map +0 -0
- /package/{promise → dist/promise}/index.d.ts +0 -0
- /package/{promise → dist/promise}/index.js +0 -0
- /package/{promise → dist/promise}/index.js.map +0 -0
- /package/{string → dist/string}/index.d.ts +0 -0
- /package/{string → dist/string}/index.js +0 -0
- /package/{string → dist/string}/replace-in-template.d.ts +0 -0
- /package/{string → dist/string}/replace-in-template.js +0 -0
- /package/{string → dist/string}/replace-in-template.js.map +0 -0
- /package/{time → dist/time}/constants.d.ts +0 -0
- /package/{time → dist/time}/constants.js +0 -0
- /package/{time → dist/time}/constants.js.map +0 -0
- /package/{time → dist/time}/convert.d.ts +0 -0
- /package/{time → dist/time}/convert.js +0 -0
- /package/{time → dist/time}/convert.js.map +0 -0
- /package/{time → dist/time}/format-minutes.d.ts +0 -0
- /package/{time → dist/time}/format-minutes.js +0 -0
- /package/{time → dist/time}/format-minutes.js.map +0 -0
- /package/{time → dist/time}/get-time-diff-as-string.d.ts +0 -0
- /package/{time → dist/time}/get-time-diff-as-string.js +0 -0
- /package/{time → dist/time}/get-time-diff-as-string.js.map +0 -0
- /package/{time → dist/time}/index.d.ts +0 -0
- /package/{time → dist/time}/index.js +0 -0
- /package/{types → dist/types}/function.d.ts +0 -0
- /package/{types → dist/types}/general.d.ts +0 -0
- /package/{types → dist/types}/index.d.ts +0 -0
- /package/{types → dist/types}/index.js +0 -0
- /package/{types → dist/types}/index.js.map +0 -0
- /package/{types → dist/types}/object.d.ts +0 -0
- /package/{types → dist/types}/search.d.ts +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export * from './array';
|
|
2
|
-
export * from './cdn';
|
|
3
|
-
export * from './time';
|
|
4
|
-
export * from './formatting';
|
|
5
|
-
export * from './fp';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
1
|
+
export * from './array';
|
|
2
|
+
export * from './cdn';
|
|
3
|
+
export * from './time';
|
|
4
|
+
export * from './formatting';
|
|
5
|
+
export * from './fp';
|
|
6
|
+
export * from './github';
|
|
7
|
+
export * from './http';
|
|
8
|
+
export * from './linked-list';
|
|
9
|
+
export * from './math';
|
|
10
|
+
export * from './object';
|
|
11
|
+
export * from './parsing';
|
|
12
|
+
export * from './predicates';
|
|
13
|
+
export * from './promise';
|
|
14
|
+
export * from './string';
|
|
15
|
+
export * from './types';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createLinkedList } from '../create-linked-list';
|
|
2
|
+
import { applyDiffLinkedList } from '../apply-diff-linked-list';
|
|
3
|
+
|
|
4
|
+
describe('applyDiffLinkedList', () => {
|
|
5
|
+
const items = {
|
|
6
|
+
1: { id: '1', nextId: '2', previousId: null, value: 1 },
|
|
7
|
+
2: { id: '2', nextId: '3', previousId: '1', value: 2 },
|
|
8
|
+
3: { id: '3', nextId: '4', previousId: '2', value: 3 },
|
|
9
|
+
4: { id: '4', nextId: null, previousId: '3', value: 4 },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const linkedList = createLinkedList('1', items);
|
|
13
|
+
|
|
14
|
+
it('should handle a delete', () => {
|
|
15
|
+
const newList = applyDiffLinkedList(items['2'], null, linkedList);
|
|
16
|
+
|
|
17
|
+
expect(newList.items).toStrictEqual({
|
|
18
|
+
1: { id: '1', nextId: '3', previousId: null, value: 1 },
|
|
19
|
+
3: { id: '3', nextId: '4', previousId: '1', value: 3 },
|
|
20
|
+
4: { id: '4', nextId: null, previousId: '3', value: 4 },
|
|
21
|
+
});
|
|
22
|
+
expect(newList.head).toStrictEqual(newList.items['1']);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should handle an insert', () => {
|
|
26
|
+
const insertedItem = { id: '5', nextId: null, previousId: '4', value: 5 };
|
|
27
|
+
const newList = applyDiffLinkedList(null, insertedItem, linkedList);
|
|
28
|
+
|
|
29
|
+
expect(newList.items).toStrictEqual({
|
|
30
|
+
1: { id: '1', nextId: '2', previousId: null, value: 1 },
|
|
31
|
+
2: { id: '2', nextId: '3', previousId: '1', value: 2 },
|
|
32
|
+
3: { id: '3', nextId: '4', previousId: '2', value: 3 },
|
|
33
|
+
4: { id: '4', nextId: '5', previousId: '3', value: 4 },
|
|
34
|
+
5: { id: '5', nextId: null, previousId: '4', value: 5 },
|
|
35
|
+
});
|
|
36
|
+
expect(newList.head).toStrictEqual(newList.items['1']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should throw an error if the two items are null', () => {
|
|
40
|
+
expect(() => applyDiffLinkedList(null, null, linkedList)).toThrowError(
|
|
41
|
+
'Cannot have both before & after as null',
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should throw an error if it tries to change the id', () => {
|
|
46
|
+
const before = linkedList.items['2'];
|
|
47
|
+
const after = { ...before, id: '6' };
|
|
48
|
+
|
|
49
|
+
expect(() => applyDiffLinkedList(before, after, linkedList)).toThrowError(
|
|
50
|
+
'Cannot change id of a ListNode',
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should update a node if it has the same nextId', () => {
|
|
55
|
+
const before = linkedList.items['2'];
|
|
56
|
+
const after = { ...before, value: 22 };
|
|
57
|
+
|
|
58
|
+
const newList = applyDiffLinkedList(before, after, linkedList);
|
|
59
|
+
|
|
60
|
+
expect(newList.items).toStrictEqual({
|
|
61
|
+
1: { id: '1', nextId: '2', previousId: null, value: 1 },
|
|
62
|
+
2: { id: '2', nextId: '3', previousId: '1', value: 22 },
|
|
63
|
+
3: { id: '3', nextId: '4', previousId: '2', value: 3 },
|
|
64
|
+
4: { id: '4', nextId: null, previousId: '3', value: 4 },
|
|
65
|
+
});
|
|
66
|
+
expect(newList.head).toStrictEqual(newList.items['1']);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should update a node if it has the same nextId', () => {
|
|
70
|
+
const before = linkedList.items['2'];
|
|
71
|
+
const after = { ...before, value: 22 };
|
|
72
|
+
|
|
73
|
+
const newList = applyDiffLinkedList(before, after, linkedList);
|
|
74
|
+
|
|
75
|
+
expect(newList.items).toStrictEqual({
|
|
76
|
+
1: { id: '1', nextId: '2', previousId: null, value: 1 },
|
|
77
|
+
2: { id: '2', nextId: '3', previousId: '1', value: 22 },
|
|
78
|
+
3: { id: '3', nextId: '4', previousId: '2', value: 3 },
|
|
79
|
+
4: { id: '4', nextId: null, previousId: '3', value: 4 },
|
|
80
|
+
});
|
|
81
|
+
expect(newList.head).toStrictEqual(newList.items['1']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle a reorder and an update', () => {
|
|
85
|
+
const before = linkedList.items['2'];
|
|
86
|
+
const after = {
|
|
87
|
+
...before,
|
|
88
|
+
value: 22,
|
|
89
|
+
nextId: '4',
|
|
90
|
+
previousId: '3',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const newList = applyDiffLinkedList(before, after, linkedList);
|
|
94
|
+
|
|
95
|
+
expect(newList.items).toStrictEqual({
|
|
96
|
+
1: { id: '1', nextId: '3', previousId: null, value: 1 },
|
|
97
|
+
3: { id: '3', nextId: '2', previousId: '1', value: 3 },
|
|
98
|
+
2: { id: '2', nextId: '4', previousId: '3', value: 22 },
|
|
99
|
+
4: { id: '4', nextId: null, previousId: '2', value: 4 },
|
|
100
|
+
});
|
|
101
|
+
expect(newList.head).toStrictEqual(newList.items['1']);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { createLinkedList } from '../create-linked-list';
|
|
2
|
+
|
|
3
|
+
import { reduceLinkedList } from '../reduce-linked-list';
|
|
4
|
+
import { findLinkedList } from '../find-linked-list';
|
|
5
|
+
import { whileLinkedList } from '../while-linked-list';
|
|
6
|
+
import { removeLinkedList } from '../remove-linked-list';
|
|
7
|
+
import { insertLinkedList } from '../insert-linked-list';
|
|
8
|
+
import { getLinkedList } from '../get-linked-list';
|
|
9
|
+
import { updateLinkedList } from '../update-linked-list';
|
|
10
|
+
import { applyDiffLinkedList } from '../apply-diff-linked-list';
|
|
11
|
+
|
|
12
|
+
jest.mock('../reduce-linked-list');
|
|
13
|
+
jest.mock('../find-linked-list');
|
|
14
|
+
jest.mock('../while-linked-list');
|
|
15
|
+
jest.mock('../remove-linked-list');
|
|
16
|
+
jest.mock('../insert-linked-list');
|
|
17
|
+
jest.mock('../get-linked-list');
|
|
18
|
+
jest.mock('../update-linked-list');
|
|
19
|
+
jest.mock('../apply-diff-linked-list');
|
|
20
|
+
|
|
21
|
+
describe('createLinkedList', () => {
|
|
22
|
+
it('should create an empty list', () => {
|
|
23
|
+
const linkedList = createLinkedList(null, {});
|
|
24
|
+
|
|
25
|
+
expect(linkedList.head).toBeNull();
|
|
26
|
+
expect(linkedList.items).toStrictEqual({});
|
|
27
|
+
expect(linkedList.format).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should have the right head', () => {
|
|
31
|
+
const node = { title: 'Micro knowledge', id: '2', nextId: null };
|
|
32
|
+
const map = { 2: node };
|
|
33
|
+
|
|
34
|
+
const linkedList = createLinkedList('2', map);
|
|
35
|
+
|
|
36
|
+
expect(linkedList.head).toStrictEqual(node);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should set format to single', () => {
|
|
40
|
+
const map = {
|
|
41
|
+
1: { id: '1', nextId: '2' },
|
|
42
|
+
2: { id: '2', nextId: null },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const linkedList = createLinkedList('1', map);
|
|
46
|
+
|
|
47
|
+
expect(linkedList.format).toStrictEqual('single');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should set format to double', () => {
|
|
51
|
+
const map = {
|
|
52
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
53
|
+
2: { id: '2', nextId: null, previousId: '1' },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const linkedList = createLinkedList('1', map);
|
|
57
|
+
|
|
58
|
+
expect(linkedList.format).toStrictEqual('double');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should throw an error if some nodes are double linkedand some are single linked', () => {
|
|
62
|
+
const map = {
|
|
63
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
64
|
+
2: { id: '2', nextId: null },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
expect(() => createLinkedList('1', map)).toThrowError(
|
|
68
|
+
'Invalid previous node in the linked list',
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should throw an error if some nodes have invalid previous', () => {
|
|
73
|
+
const map = {
|
|
74
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
75
|
+
2: { id: '2', nextId: '3', previousId: '1' },
|
|
76
|
+
3: { id: '3', nextId: null, previousId: '1' },
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
expect(() => createLinkedList('1', map)).toThrowError(
|
|
80
|
+
'Invalid previous node in the linked list',
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should have the right size', () => {
|
|
85
|
+
const map = {
|
|
86
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
87
|
+
2: { id: '2', nextId: '3', previousId: '1' },
|
|
88
|
+
3: { id: '3', nextId: null, previousId: '2' },
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const linkedList = createLinkedList('1', map);
|
|
92
|
+
|
|
93
|
+
expect(linkedList.size).toStrictEqual(3);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('methods', () => {
|
|
97
|
+
const reduceLinkedListMocked = jest.mocked(reduceLinkedList);
|
|
98
|
+
const findLinkedListMocked = jest.mocked(findLinkedList);
|
|
99
|
+
const whileLinkedListMocked = jest.mocked(whileLinkedList);
|
|
100
|
+
const removeLinkedListMocked = jest.mocked(removeLinkedList);
|
|
101
|
+
const insertLinkedListMocked = jest.mocked(insertLinkedList);
|
|
102
|
+
const getLinkedListMocked = jest.mocked(getLinkedList);
|
|
103
|
+
const updateLinkedListMocked = jest.mocked(updateLinkedList);
|
|
104
|
+
const applyDiffLinkedListMocked = jest.mocked(applyDiffLinkedList);
|
|
105
|
+
|
|
106
|
+
const record = {
|
|
107
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
108
|
+
2: { id: '2', nextId: null, previousId: '1' },
|
|
109
|
+
};
|
|
110
|
+
const linkedList = createLinkedList('1', record);
|
|
111
|
+
const list = {
|
|
112
|
+
headId: '1',
|
|
113
|
+
items: record,
|
|
114
|
+
};
|
|
115
|
+
const manipulationConfig = {
|
|
116
|
+
factory: expect.toBeFunction(),
|
|
117
|
+
format: 'double',
|
|
118
|
+
list,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
beforeEach(() => {
|
|
122
|
+
jest.clearAllMocks();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('it should have reduce', () => {
|
|
126
|
+
reduceLinkedListMocked.mockReturnValue('reduce');
|
|
127
|
+
|
|
128
|
+
const accumulatorFunction = jest.fn().mockName('accumulatorFunction');
|
|
129
|
+
const result = linkedList.reduce(accumulatorFunction, 'init');
|
|
130
|
+
|
|
131
|
+
expect(result).toStrictEqual('reduce');
|
|
132
|
+
expect(reduceLinkedListMocked).toHaveBeenCalledWith(accumulatorFunction, 'init', list);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('it should have find', () => {
|
|
136
|
+
findLinkedListMocked.mockReturnValue('find' as any);
|
|
137
|
+
|
|
138
|
+
const findPredicate = jest.fn().mockName('findPredicate');
|
|
139
|
+
const result = linkedList.find(findPredicate);
|
|
140
|
+
|
|
141
|
+
expect(result).toStrictEqual('find');
|
|
142
|
+
expect(findLinkedListMocked).toHaveBeenCalledWith(findPredicate, list);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('it should have while', () => {
|
|
146
|
+
whileLinkedListMocked.mockReturnValue('while' as any);
|
|
147
|
+
|
|
148
|
+
const whilePredicate = jest.fn().mockName('whilePredicate');
|
|
149
|
+
const result = linkedList.while(whilePredicate, '2');
|
|
150
|
+
|
|
151
|
+
expect(result).toStrictEqual('while');
|
|
152
|
+
expect(whileLinkedListMocked).toHaveBeenCalledWith(whilePredicate, list, '2');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('it should have remove', () => {
|
|
156
|
+
removeLinkedListMocked.mockReturnValue('remove' as any);
|
|
157
|
+
|
|
158
|
+
const result = linkedList.remove('3');
|
|
159
|
+
|
|
160
|
+
expect(result).toStrictEqual('remove');
|
|
161
|
+
expect(removeLinkedListMocked).toHaveBeenCalledWith('3', manipulationConfig);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('it should have insert', () => {
|
|
165
|
+
insertLinkedListMocked.mockReturnValue('insert' as any);
|
|
166
|
+
|
|
167
|
+
const item = { id: '5', nextId: '6', previousId: '4' };
|
|
168
|
+
const result = linkedList.insert(item as any);
|
|
169
|
+
|
|
170
|
+
expect(result).toStrictEqual('insert');
|
|
171
|
+
expect(insertLinkedListMocked).toHaveBeenCalledWith(item, manipulationConfig);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('it should have get', () => {
|
|
175
|
+
getLinkedListMocked.mockReturnValue('get' as any);
|
|
176
|
+
|
|
177
|
+
const result = linkedList.get('5');
|
|
178
|
+
|
|
179
|
+
expect(result).toStrictEqual('get');
|
|
180
|
+
expect(getLinkedListMocked).toHaveBeenCalledWith('5', list);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('it should have update', () => {
|
|
184
|
+
updateLinkedListMocked.mockReturnValue('update' as any);
|
|
185
|
+
|
|
186
|
+
const updatedItem = { id: '5', nextId: '6', previousId: '4' };
|
|
187
|
+
const result = linkedList.update(updatedItem as any);
|
|
188
|
+
|
|
189
|
+
expect(result).toStrictEqual('update');
|
|
190
|
+
expect(updateLinkedListMocked).toHaveBeenCalledWith(updatedItem, manipulationConfig);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('it should have applyDiff', () => {
|
|
194
|
+
applyDiffLinkedListMocked.mockReturnValue('applydiff' as any);
|
|
195
|
+
|
|
196
|
+
const before = { id: '5', nextId: '6', previousId: '4' };
|
|
197
|
+
const after = { id: '5', nextId: '7', previousId: '4' };
|
|
198
|
+
const result = linkedList.applyDiff(before as any, after as any);
|
|
199
|
+
|
|
200
|
+
expect(result).toStrictEqual('applydiff');
|
|
201
|
+
expect(applyDiffLinkedListMocked).toHaveBeenCalledWith(before, after, linkedList);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { findLinkedList } from '../find-linked-list';
|
|
2
|
+
|
|
3
|
+
describe('findLinkedList', () => {
|
|
4
|
+
const list = {
|
|
5
|
+
items: {
|
|
6
|
+
1: {
|
|
7
|
+
id: '1',
|
|
8
|
+
nextId: '2',
|
|
9
|
+
},
|
|
10
|
+
2: {
|
|
11
|
+
id: '2',
|
|
12
|
+
nextId: '3',
|
|
13
|
+
},
|
|
14
|
+
3: {
|
|
15
|
+
id: '3',
|
|
16
|
+
nextId: '4',
|
|
17
|
+
},
|
|
18
|
+
4: {
|
|
19
|
+
id: '1',
|
|
20
|
+
nextId: null,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
headId: '1',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
it('should return the right item if it is found', () => {
|
|
27
|
+
const foundItem = findLinkedList((item) => item.id === '3', list);
|
|
28
|
+
|
|
29
|
+
expect(foundItem).toStrictEqual({
|
|
30
|
+
id: '3',
|
|
31
|
+
nextId: '4',
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should return null if no item match the predicate', () => {
|
|
36
|
+
const foundItem = findLinkedList((item) => item.id === '5', list);
|
|
37
|
+
|
|
38
|
+
expect(foundItem).toBeNull();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getLinkedList } from '../get-linked-list';
|
|
2
|
+
|
|
3
|
+
describe('getLinkedList', () => {
|
|
4
|
+
const list = {
|
|
5
|
+
headId: '1',
|
|
6
|
+
items: {
|
|
7
|
+
1: {
|
|
8
|
+
id: '1',
|
|
9
|
+
nextId: '2',
|
|
10
|
+
},
|
|
11
|
+
2: {
|
|
12
|
+
id: '2',
|
|
13
|
+
nextId: null,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
it('should get the item corresponding to the id', () => {
|
|
19
|
+
expect(getLinkedList('1', list)).toStrictEqual({
|
|
20
|
+
id: '1',
|
|
21
|
+
nextId: '2',
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return null if the item with the given id does not exist', () => {
|
|
26
|
+
expect(getLinkedList('5', list)).toBeNull();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { insertLinkedList } from '../insert-linked-list';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
findPreviousId,
|
|
5
|
+
assertItemCompatibility,
|
|
6
|
+
assertPresence,
|
|
7
|
+
assertNewNodePosition,
|
|
8
|
+
} from '../linked-list-utils';
|
|
9
|
+
|
|
10
|
+
jest.mock('../linked-list-utils');
|
|
11
|
+
|
|
12
|
+
describe('insertLinkedList', () => {
|
|
13
|
+
const findPreviousIdMocked = jest.mocked(findPreviousId);
|
|
14
|
+
const assertItemCompatibilityMocked = jest.mocked(assertItemCompatibility);
|
|
15
|
+
const assertPresenceMocked = jest.mocked(assertPresence);
|
|
16
|
+
const assertNewNodePositionMocked = jest.mocked(assertNewNodePosition);
|
|
17
|
+
|
|
18
|
+
const list = {
|
|
19
|
+
headId: '1',
|
|
20
|
+
items: {
|
|
21
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
22
|
+
2: { id: '2', nextId: null, previousId: '1' },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
jest.clearAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should call every assertion', () => {
|
|
31
|
+
const itemToInsert = {
|
|
32
|
+
nextId: '2',
|
|
33
|
+
previousId: '1',
|
|
34
|
+
id: '3',
|
|
35
|
+
};
|
|
36
|
+
insertLinkedList(itemToInsert, {
|
|
37
|
+
format: 'double',
|
|
38
|
+
factory: jest.fn(),
|
|
39
|
+
list: list as any,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(assertItemCompatibilityMocked).toHaveBeenCalledTimes(1);
|
|
43
|
+
expect(assertItemCompatibilityMocked).toHaveBeenCalledWith(itemToInsert, 'double');
|
|
44
|
+
|
|
45
|
+
expect(assertPresenceMocked).toHaveBeenCalledTimes(2);
|
|
46
|
+
expect(assertPresenceMocked).toHaveBeenNthCalledWith(1, '2', list.items);
|
|
47
|
+
expect(assertPresenceMocked).toHaveBeenNthCalledWith(2, '1', list.items);
|
|
48
|
+
|
|
49
|
+
expect(assertNewNodePositionMocked).toHaveBeenCalledTimes(1);
|
|
50
|
+
expect(assertNewNodePositionMocked).toHaveBeenCalledWith(itemToInsert, {
|
|
51
|
+
previousId: '1',
|
|
52
|
+
list,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should find the previous id if the linked list is not double link', () => {
|
|
57
|
+
const itemToInsert = {
|
|
58
|
+
id: '3',
|
|
59
|
+
nextId: '1',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
findPreviousIdMocked.mockReturnValue(null);
|
|
63
|
+
|
|
64
|
+
insertLinkedList(itemToInsert, {
|
|
65
|
+
format: 'single',
|
|
66
|
+
factory: jest.fn().mockImplementation((newList) => newList),
|
|
67
|
+
list: list as any,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(findPreviousIdMocked).toHaveBeenCalledTimes(1);
|
|
71
|
+
expect(findPreviousIdMocked).toHaveBeenCalledWith('1', list);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should directly take the previousId from item if the list is double link', () => {
|
|
75
|
+
const itemToInsert = {
|
|
76
|
+
id: '3',
|
|
77
|
+
nextId: '1',
|
|
78
|
+
previousId: null,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
insertLinkedList(itemToInsert, {
|
|
82
|
+
format: 'double',
|
|
83
|
+
factory: jest.fn(),
|
|
84
|
+
list: list as any,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(findPreviousIdMocked).not.toHaveBeenCalled();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should handle a middle insertion', () => {
|
|
91
|
+
const itemToInsert = {
|
|
92
|
+
id: '3',
|
|
93
|
+
nextId: '2',
|
|
94
|
+
previousId: '1',
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const newList = insertLinkedList(itemToInsert, {
|
|
98
|
+
format: 'double',
|
|
99
|
+
factory: (theList) => theList as any,
|
|
100
|
+
list: list as any,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(newList).toStrictEqual({
|
|
104
|
+
headId: '1',
|
|
105
|
+
items: {
|
|
106
|
+
1: { id: '1', nextId: '3', previousId: null },
|
|
107
|
+
3: { id: '3', nextId: '2', previousId: '1' },
|
|
108
|
+
2: { id: '2', nextId: null, previousId: '3' },
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should handle a head insertion', () => {
|
|
114
|
+
const itemToInsert = {
|
|
115
|
+
id: '3',
|
|
116
|
+
nextId: '1',
|
|
117
|
+
previousId: null,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const newList = insertLinkedList(itemToInsert, {
|
|
121
|
+
format: 'double',
|
|
122
|
+
factory: (theList) => theList as any,
|
|
123
|
+
list: list as any,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(newList).toStrictEqual({
|
|
127
|
+
headId: '3',
|
|
128
|
+
items: {
|
|
129
|
+
3: { id: '3', nextId: '1', previousId: null },
|
|
130
|
+
1: { id: '1', nextId: '2', previousId: '3' },
|
|
131
|
+
2: { id: '2', nextId: null, previousId: '1' },
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should handle a tail insertion', () => {
|
|
137
|
+
const itemToInsert = {
|
|
138
|
+
id: '3',
|
|
139
|
+
nextId: null,
|
|
140
|
+
previousId: '2',
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const newList = insertLinkedList(itemToInsert, {
|
|
144
|
+
format: 'double',
|
|
145
|
+
factory: (theList) => theList as any,
|
|
146
|
+
list: list as any,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(newList).toStrictEqual({
|
|
150
|
+
headId: '1',
|
|
151
|
+
items: {
|
|
152
|
+
1: { id: '1', nextId: '2', previousId: null },
|
|
153
|
+
2: { id: '2', nextId: '3', previousId: '1' },
|
|
154
|
+
3: { id: '3', nextId: null, previousId: '2' },
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should handle an insertion in a single linked list', () => {
|
|
160
|
+
findPreviousIdMocked.mockReturnValue('2');
|
|
161
|
+
|
|
162
|
+
const singleLinkedlist = {
|
|
163
|
+
headId: '1',
|
|
164
|
+
items: {
|
|
165
|
+
1: { id: '1', nextId: '2' },
|
|
166
|
+
2: { id: '2', nextId: null },
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
const itemToInsert = { id: '3', nextId: null };
|
|
170
|
+
|
|
171
|
+
const newList = insertLinkedList(itemToInsert, {
|
|
172
|
+
format: 'single',
|
|
173
|
+
factory: (theList) => theList as any,
|
|
174
|
+
list: singleLinkedlist as any,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(newList).toStrictEqual({
|
|
178
|
+
headId: '1',
|
|
179
|
+
items: {
|
|
180
|
+
1: { id: '1', nextId: '2' },
|
|
181
|
+
2: { id: '2', nextId: '3' },
|
|
182
|
+
3: { id: '3', nextId: null },
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|