diff --git a/.eslintrc b/.eslintrc index ec0d68b9b851aecd5fed5b8c2c7b6c87f52f46f9..15eefba00ead3e95099b0064fe507a5cdc2e93e8 100755 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,9 @@ "browser": true, "jquery": true, }, + "parserOptions": { + "sourceType": "module", + }, "rules": { "no-await-in-loop": "warn", "no-compare-neg-zero": "warn", diff --git a/js/binary_search_tree.js b/js/binary_search_tree.js index f343d466662353511be5378a4922e476191fee78..74188ab1b2d86be61c786747cb2e51d0753e89eb 100644 --- a/js/binary_search_tree.js +++ b/js/binary_search_tree.js @@ -1,5 +1,3 @@ -/* exported BinarySearchTree */ - function opposite(side) { return 1 - side; } @@ -79,7 +77,7 @@ class BSTNode { } } -class BinarySearchTree { +export class BinarySearchTree { constructor(elements = []) { this.root = undefined; for (const element of elements) { @@ -122,7 +120,16 @@ class BinarySearchTree { } delete(element) { - // TODO: stub + let moribund = this._find(element); + if (moribund.isBranch()) { + const original = moribund; + // TODO: incomplete + original.swap(moribund); + } + // TODO: incomplete + if (this.root === moribund) { + // TODO: incomplete + } } enumerate(inclusiveMinimum, exclusiveMaximum) { diff --git a/unit_tests/test_enumeration.js b/unit_tests/test_enumeration.js index fbee1a3ac1986805f61d528cd03ccd9fefa7f519..26c37d18174b0f0d67e892b3e02614db647cc69d 100644 --- a/unit_tests/test_enumeration.js +++ b/unit_tests/test_enumeration.js @@ -1,5 +1,7 @@ -QUnit.module('enumeration'); -/* globals QUnit BinarySearchTree */ +import {BinarySearchTree} from '../js/binary_search_tree.js'; + +/* globals QUnit */ +QUnit.module('test_enumeration.js'); /* eslint-disable no-magic-numbers */ QUnit.test('Enumeration test #0', (assert) => { diff --git a/unit_tests/test_insertion.js b/unit_tests/test_insertion.js index 00677541d8da4750e618ac6b94e58b1c2319f6fa..955993217027289afc0bbdba3b9da08dc0e8cc16 100644 --- a/unit_tests/test_insertion.js +++ b/unit_tests/test_insertion.js @@ -1,5 +1,7 @@ -QUnit.module('insertion'); -/* globals QUnit BinarySearchTree */ +import {BinarySearchTree} from '../js/binary_search_tree.js'; + +/* globals QUnit */ +QUnit.module('test_insertion.js'); /* eslint-disable no-magic-numbers */ QUnit.test('Insertion test #0', (assert) => { diff --git a/unit_tests/test_membership.js b/unit_tests/test_membership.js index e045322d6cd575d007c0173eced75f68318bbc66..9a97d9a2771a3ce096fcaed73ff8414ed24d776b 100644 --- a/unit_tests/test_membership.js +++ b/unit_tests/test_membership.js @@ -1,5 +1,7 @@ -QUnit.module('membership'); -/* globals QUnit BinarySearchTree */ +import {BinarySearchTree} from '../js/binary_search_tree.js'; + +/* globals QUnit */ +QUnit.module('test_membership.js'); /* eslint-disable no-magic-numbers */ QUnit.test('Membership test #0', (assert) => { diff --git a/unit_tests/test_multiple_insertion.js b/unit_tests/test_multiple_insertion.js index a581cd97c54139c82a217894d8ca965bbc67349c..ac3ff836a902a9ac3f2f03196f716cd2b7c58d49 100644 --- a/unit_tests/test_multiple_insertion.js +++ b/unit_tests/test_multiple_insertion.js @@ -1,5 +1,7 @@ -QUnit.module('multiple insertion'); -/* globals QUnit BinarySearchTree */ +import {BinarySearchTree} from '../js/binary_search_tree.js'; + +/* globals QUnit */ +QUnit.module('test_multiple_insertion.js'); /* eslint-disable no-magic-numbers */ QUnit.test('Mulitple insertion test #0', (assert) => { diff --git a/unit_tests/test_multiple_removal.js b/unit_tests/test_multiple_removal.js index 7ca0aca2abb68df382b60b27adb26e8e03d18064..7a314832f2c51a1567bdb31d6efdfbf972514d4f 100644 --- a/unit_tests/test_multiple_removal.js +++ b/unit_tests/test_multiple_removal.js @@ -1,5 +1,7 @@ -QUnit.module('multiple removal'); -/* globals QUnit BinarySearchTree */ +import {BinarySearchTree} from '../js/binary_search_tree.js'; + +/* globals QUnit */ +QUnit.module('test_multiple_removal.js'); /* eslint-disable no-magic-numbers */ QUnit.test('Multiple removal test #0', (assert) => { diff --git a/unit_tests/test_removal.js b/unit_tests/test_removal.js index 1648a6e48d4bc9651472148403d2f1aee2b95a7f..088f710c3d425a983f7d47ff90fceeeaf316e163 100644 --- a/unit_tests/test_removal.js +++ b/unit_tests/test_removal.js @@ -1,5 +1,7 @@ -QUnit.module('removal'); -/* globals QUnit BinarySearchTree */ +import {BinarySearchTree} from '../js/binary_search_tree.js'; + +/* globals QUnit */ +QUnit.module('test_removal.js'); /* eslint-disable no-magic-numbers */ QUnit.test('Removal test #0', (assert) => { diff --git a/unit_tests/unit_tests.html b/unit_tests/unit_tests.html index 89b9bcb9b6c6bcf1728145f0dde61dc6518747d6..056d98166f72bae21c9d690dd2615f6ed389d796 100644 --- a/unit_tests/unit_tests.html +++ b/unit_tests/unit_tests.html @@ -13,13 +13,12 @@ <script src="../libraries/qunit/qunit.js"></script> <script src="overrides.js"></script> - <script src="../js/binary_search_tree.js"></script> - <script src="test_insertion.js"></script> - <script src="test_membership.js"></script> - <script src="test_multiple_insertion.js"></script> - <script src="test_removal.js"></script> - <script src="test_multiple_removal.js"></script> - <script src="test_enumeration.js"></script> + <script type="module" src="test_insertion.js"></script> + <script type="module" src="test_membership.js"></script> + <script type="module" src="test_multiple_insertion.js"></script> + <script type="module" src="test_removal.js"></script> + <script type="module" src="test_multiple_removal.js"></script> + <script type="module" src="test_enumeration.js"></script> </body> </html>