-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add binary search tree Jasmine tests
Signed-off-by: Darko Draskovic <[email protected]>
- Loading branch information
1 parent
a187ceb
commit 2017cac
Showing
4 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { | ||
BinarySearchTree | ||
} from '../src/data-structures/binary-search-tree.js' | ||
|
||
describe("Function", function () { | ||
|
||
const insert = [9, 4, 6, 5, 3, 20, 20, 170, 15, 1, 25, 300, 7, 30]; | ||
const remove = [9, 300, 25, 7, 25, 9, 9, 170, 15]; | ||
|
||
it(BinarySearchTree.name + " constructs binary search tree", function () { | ||
const bst = new BinarySearchTree(); | ||
|
||
insert.forEach((value) => bst.insert(value)); | ||
|
||
insert.forEach((value) => expect(bst.lookup(value)).not.toBeNull()); | ||
|
||
remove.forEach((value) => bst.remove(value)); | ||
|
||
let difference = insert.filter(x => !remove.includes(x)); | ||
|
||
difference.forEach((value) => expect(bst.lookup(value)).not.toBeNull()); | ||
|
||
remove.forEach((value) => expect(bst.lookup(value)).toBeNull()); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// javascript built in search | ||
var beasts = ['Centaur', 'Godzilla', | ||
'Mosura', 'Minotaur', 'Hydra', 'Nessie']; | ||
|
||
(function test() { | ||
// javascript built in linear searches; O(n) | ||
console.assert(beasts.indexOf('Godzilla') == 1); | ||
console.assert(beasts.indexOf('Cyclope') == -1); | ||
|
||
console.assert(beasts.findIndex(function (item) { | ||
return item == 'Hydra' | ||
}) == 4); | ||
console.assert(beasts.findIndex(function (item) { | ||
return item == 'Cyclope' | ||
}) == -1); | ||
|
||
console.assert(beasts.find(function (item) { | ||
return item == 'Hydra' | ||
}) == 'Hydra'); | ||
|
||
console.assert(beasts.includes('Nessie') == true); | ||
console.assert(beasts.includes('Cyclope') == false); | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { test } from './algorithms/recursion.js' | ||
import { test } from './algorithms/search.js' | ||
|
||
test(); | ||
// test(); |