Skip to content
Snippets Groups Projects
Commit 8ea488d9 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
Branches
No related tags found
No related merge requests found
Showing with 993 additions and 0 deletions
# Disable line-ending conversions for this repository.
* -text
# dependencies
/node_modules
# testing
/coverage
# production
/build
# environments
.env.local
.env.development.local
.env.test.local
.env.production.local
# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# misc
*~
.DS_Store
[submodule "eslint-config"]
path = eslint-config
url = git@git.unl.edu:soft-core/soft-260/eslint-config.git
Subproject commit 24df42fb655d234b83c93b0fb24d012e4d9ecb58
This diff is collapsed.
{
"name": "@unlsoft/trees-lab",
"version": "1.0.0",
"description": "Starter code for the lab on trees.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd trees && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd trees && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:insertion": "cd trees && npm run test-once:insertion",
"test-once:membership": "cd trees && npm run test-once:membership",
"test-once:multiple-insertion": "cd trees && npm run test-once:multiple-insertion",
"test-once:removal": "cd trees && npm run test-once:removal",
"test-once:multiple-removal": "cd trees && npm run test-once:multiple-removal",
"test-once:enumeration": "cd trees && npm run test-once:enumeration",
"test-once": "cd trees && npm run test-once",
"test": "run-s test-once",
"start": "cd trees && npm run start",
"build:app": "cd trees && npm run build",
"build": "run-s build:**"
},
"devDependencies": {
"ghooks": "^2.0.4",
"npm-run-all": "^4.1.5"
},
"config": {
"ghooks": {
"pre-commit": "npm run lint"
}
}
}
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.eol": "LF",
"files.exclude": {
"**/node_modules": true
},
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
}
# dependencies
/node_modules
# testing
/coverage
# production
/build
# environments
.env.local
.env.development.local
.env.test.local
.env.production.local
# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# misc
*~
.DS_Store
This diff is collapsed.
{
"name": "@unlsoft/trees",
"version": "1.0.0",
"description": "Starter code for the lab on trees.",
"type": "module",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**",
"test-once:insertion": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"insertion sorts\"",
"test-once:membership": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"membership\"",
"test-once:multiple-insertion": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"insertion ignores\"",
"test-once:removal": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"removal retains\"",
"test-once:multiple-removal": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"removal ignores\"",
"test-once:enumeration": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"enumeration\"",
"test-once": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watchAll --coverage"
},
"dependencies": {
"npm-run-all": "^4.1.5"
},
"devDependencies": {
"@unlsoft/eslint-config": "file:../eslint-config",
"eslint": "^7.30.0",
"jest": "^27.0.6",
"jest-environment-node": "^27.0.6"
},
"eslintConfig": {
"extends": "@unlsoft"
},
"jest": {
"clearMocks": true,
"collectCoverageFrom": [
"src/**/*.js",
"!src/testing/**/*.js"
],
"resetMocks": false,
"restoreMocks": false,
"testEnvironment": "./src/testing/failFast.js",
"transform": {}
},
"//": [
"See https://github.com/facebook/jest/issues/9430 for information on Jest+ES6."
]
}
export const LEFT = 0;
export const RIGHT = 1;
function opposite(side) {
return 1 - side;
}
class BSTNode {
constructor(element) {
this.element = element;
this.parent = undefined;
this.children = [undefined, undefined];
}
isLeaf() {
return this.children.every((child) => child === undefined);
}
isBranch() {
return this.children.every((child) => child !== undefined);
}
getSide(element) {
return element < this.element ? LEFT : RIGHT;
}
getDescendant(side) {
let [result, child] = [undefined, this];
while (child !== undefined) {
result = child;
child = result.children[side];
}
return result;
}
getAdjacent(side) {
let [result, parent] = [this.children[side], this];
if (result !== undefined) {
return result.getDescendant(opposite(side));
}
while (parent !== undefined && parent.children[side] === result) {
result = parent;
parent = result.parent;
}
return parent;
}
addChild(element) {
const side = this.getSide(element);
console.assert(
this.children[side] === undefined,
`Tried to add ${element} as a child of ${this.element} when a child on that side already exists.`,
);
const result = new BSTNode(element);
this.children[side] = result;
result.parent = this;
return result;
}
swap(other) {
const swap = this.element;
this.element = other.element;
other.element = swap;
}
disconnect() {
let survivor = undefined;
for (const child of this.children) {
if (child !== undefined) {
console.assert(survivor === undefined, `Tried to disconnect ${this.element} when it has multiple children.`);
survivor = child;
}
}
if (this.parent !== undefined) {
const siblings = this.parent.children;
siblings[siblings.indexOf(this)] = survivor;
if (survivor !== undefined) {
survivor.parent = this.parent;
}
this.parent = undefined;
}
return survivor;
}
}
export class BinarySearchTree {
constructor(elements = []) {
this.root = undefined;
for (const element of elements) {
this.add(element);
}
}
_find(element) {
let [vertex, child] = [undefined, this.root];
while (child !== undefined) {
if (child.element === element) {
return child;
}
vertex = child;
child = vertex.children[vertex.getSide(element)];
}
if (vertex !== undefined && vertex.element < element) {
vertex = vertex.getAdjacent(RIGHT);
}
return vertex;
}
_findFringe(element) {
let [vertex, child] = [undefined, this.root];
while (child !== undefined) {
vertex = child;
child = vertex.children[vertex.getSide(element)];
}
return vertex;
}
add(element) {
// TODO: stub
}
has(element) {
return false; // TODO: stub
}
delete(element) {
let moribund = this._find(element);
if (moribund.isBranch()) {
const original = moribund;
// TODO: choose a vertex to swap with
original.swap(moribund);
}
// TODO: remove the moribund vertex
if (this.root === moribund) {
// TODO: restore the root
}
}
enumerate(inclusiveMinimum, exclusiveMaximum) {
const result = [];
// TODO: stub
// for (let vertex = …, end = …;
// vertex !== end;
// vertex = vertex.getAdjacent(RIGHT)) {
// result.push(vertex.element);
// }
return result;
}
toList() {
const result = [];
if (this.root !== undefined) {
const left = this.root.getDescendant(LEFT);
for (let vertex = left; vertex !== undefined; vertex = vertex.getAdjacent(RIGHT)) {
result.push(vertex.element);
}
}
return result;
}
}
This diff is collapsed.
/* eslint-disable no-magic-numbers */
import { BinarySearchTree } from './binarySearchTree.js';
describe('insertion', () => {
test('sorts permutation #0', () => {
expect(new BinarySearchTree([0, 1, 2, 3, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #1', () => {
expect(new BinarySearchTree([0, 1, 2, 4, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #2', () => {
expect(new BinarySearchTree([0, 1, 3, 2, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #3', () => {
expect(new BinarySearchTree([0, 1, 3, 4, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #4', () => {
expect(new BinarySearchTree([0, 1, 4, 2, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #5', () => {
expect(new BinarySearchTree([0, 1, 4, 3, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #6', () => {
expect(new BinarySearchTree([0, 2, 1, 3, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #7', () => {
expect(new BinarySearchTree([0, 2, 1, 4, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #8', () => {
expect(new BinarySearchTree([0, 2, 3, 1, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #9', () => {
expect(new BinarySearchTree([0, 2, 3, 4, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #10', () => {
expect(new BinarySearchTree([0, 2, 4, 1, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #11', () => {
expect(new BinarySearchTree([0, 2, 4, 3, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #12', () => {
expect(new BinarySearchTree([0, 3, 1, 2, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #13', () => {
expect(new BinarySearchTree([0, 3, 1, 4, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #14', () => {
expect(new BinarySearchTree([0, 3, 2, 1, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #15', () => {
expect(new BinarySearchTree([0, 3, 2, 4, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #16', () => {
expect(new BinarySearchTree([0, 3, 4, 1, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #17', () => {
expect(new BinarySearchTree([0, 3, 4, 2, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #18', () => {
expect(new BinarySearchTree([0, 4, 1, 2, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #19', () => {
expect(new BinarySearchTree([0, 4, 1, 3, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #20', () => {
expect(new BinarySearchTree([0, 4, 2, 1, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #21', () => {
expect(new BinarySearchTree([0, 4, 2, 3, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #22', () => {
expect(new BinarySearchTree([0, 4, 3, 1, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #23', () => {
expect(new BinarySearchTree([0, 4, 3, 2, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #24', () => {
expect(new BinarySearchTree([1, 0, 2, 3, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #25', () => {
expect(new BinarySearchTree([1, 0, 2, 4, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #26', () => {
expect(new BinarySearchTree([1, 0, 3, 2, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #27', () => {
expect(new BinarySearchTree([1, 0, 3, 4, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #28', () => {
expect(new BinarySearchTree([1, 0, 4, 2, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #29', () => {
expect(new BinarySearchTree([1, 0, 4, 3, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #30', () => {
expect(new BinarySearchTree([1, 2, 0, 3, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #31', () => {
expect(new BinarySearchTree([1, 2, 0, 4, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #32', () => {
expect(new BinarySearchTree([1, 2, 3, 0, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #33', () => {
expect(new BinarySearchTree([1, 2, 3, 4, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #34', () => {
expect(new BinarySearchTree([1, 2, 4, 0, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #35', () => {
expect(new BinarySearchTree([1, 2, 4, 3, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #36', () => {
expect(new BinarySearchTree([1, 3, 0, 2, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #37', () => {
expect(new BinarySearchTree([1, 3, 0, 4, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #38', () => {
expect(new BinarySearchTree([1, 3, 2, 0, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #39', () => {
expect(new BinarySearchTree([1, 3, 2, 4, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #40', () => {
expect(new BinarySearchTree([1, 3, 4, 0, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #41', () => {
expect(new BinarySearchTree([1, 3, 4, 2, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #42', () => {
expect(new BinarySearchTree([1, 4, 0, 2, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #43', () => {
expect(new BinarySearchTree([1, 4, 0, 3, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #44', () => {
expect(new BinarySearchTree([1, 4, 2, 0, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #45', () => {
expect(new BinarySearchTree([1, 4, 2, 3, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #46', () => {
expect(new BinarySearchTree([1, 4, 3, 0, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #47', () => {
expect(new BinarySearchTree([1, 4, 3, 2, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #48', () => {
expect(new BinarySearchTree([2, 0, 1, 3, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #49', () => {
expect(new BinarySearchTree([2, 0, 1, 4, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #50', () => {
expect(new BinarySearchTree([2, 0, 3, 1, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #51', () => {
expect(new BinarySearchTree([2, 0, 3, 4, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #52', () => {
expect(new BinarySearchTree([2, 0, 4, 1, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #53', () => {
expect(new BinarySearchTree([2, 0, 4, 3, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #54', () => {
expect(new BinarySearchTree([2, 1, 0, 3, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #55', () => {
expect(new BinarySearchTree([2, 1, 0, 4, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #56', () => {
expect(new BinarySearchTree([2, 1, 3, 0, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #57', () => {
expect(new BinarySearchTree([2, 1, 3, 4, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #58', () => {
expect(new BinarySearchTree([2, 1, 4, 0, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #59', () => {
expect(new BinarySearchTree([2, 1, 4, 3, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #60', () => {
expect(new BinarySearchTree([2, 3, 0, 1, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #61', () => {
expect(new BinarySearchTree([2, 3, 0, 4, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #62', () => {
expect(new BinarySearchTree([2, 3, 1, 0, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #63', () => {
expect(new BinarySearchTree([2, 3, 1, 4, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #64', () => {
expect(new BinarySearchTree([2, 3, 4, 0, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #65', () => {
expect(new BinarySearchTree([2, 3, 4, 1, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #66', () => {
expect(new BinarySearchTree([2, 4, 0, 1, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #67', () => {
expect(new BinarySearchTree([2, 4, 0, 3, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #68', () => {
expect(new BinarySearchTree([2, 4, 1, 0, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #69', () => {
expect(new BinarySearchTree([2, 4, 1, 3, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #70', () => {
expect(new BinarySearchTree([2, 4, 3, 0, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #71', () => {
expect(new BinarySearchTree([2, 4, 3, 1, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #72', () => {
expect(new BinarySearchTree([3, 0, 1, 2, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #73', () => {
expect(new BinarySearchTree([3, 0, 1, 4, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #74', () => {
expect(new BinarySearchTree([3, 0, 2, 1, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #75', () => {
expect(new BinarySearchTree([3, 0, 2, 4, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #76', () => {
expect(new BinarySearchTree([3, 0, 4, 1, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #77', () => {
expect(new BinarySearchTree([3, 0, 4, 2, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #78', () => {
expect(new BinarySearchTree([3, 1, 0, 2, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #79', () => {
expect(new BinarySearchTree([3, 1, 0, 4, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #80', () => {
expect(new BinarySearchTree([3, 1, 2, 0, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #81', () => {
expect(new BinarySearchTree([3, 1, 2, 4, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #82', () => {
expect(new BinarySearchTree([3, 1, 4, 0, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #83', () => {
expect(new BinarySearchTree([3, 1, 4, 2, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #84', () => {
expect(new BinarySearchTree([3, 2, 0, 1, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #85', () => {
expect(new BinarySearchTree([3, 2, 0, 4, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #86', () => {
expect(new BinarySearchTree([3, 2, 1, 0, 4]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #87', () => {
expect(new BinarySearchTree([3, 2, 1, 4, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #88', () => {
expect(new BinarySearchTree([3, 2, 4, 0, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #89', () => {
expect(new BinarySearchTree([3, 2, 4, 1, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #90', () => {
expect(new BinarySearchTree([3, 4, 0, 1, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #91', () => {
expect(new BinarySearchTree([3, 4, 0, 2, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #92', () => {
expect(new BinarySearchTree([3, 4, 1, 0, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #93', () => {
expect(new BinarySearchTree([3, 4, 1, 2, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #94', () => {
expect(new BinarySearchTree([3, 4, 2, 0, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #95', () => {
expect(new BinarySearchTree([3, 4, 2, 1, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #96', () => {
expect(new BinarySearchTree([4, 0, 1, 2, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #97', () => {
expect(new BinarySearchTree([4, 0, 1, 3, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #98', () => {
expect(new BinarySearchTree([4, 0, 2, 1, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #99', () => {
expect(new BinarySearchTree([4, 0, 2, 3, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #100', () => {
expect(new BinarySearchTree([4, 0, 3, 1, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #101', () => {
expect(new BinarySearchTree([4, 0, 3, 2, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #102', () => {
expect(new BinarySearchTree([4, 1, 0, 2, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #103', () => {
expect(new BinarySearchTree([4, 1, 0, 3, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #104', () => {
expect(new BinarySearchTree([4, 1, 2, 0, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #105', () => {
expect(new BinarySearchTree([4, 1, 2, 3, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #106', () => {
expect(new BinarySearchTree([4, 1, 3, 0, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #107', () => {
expect(new BinarySearchTree([4, 1, 3, 2, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #108', () => {
expect(new BinarySearchTree([4, 2, 0, 1, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #109', () => {
expect(new BinarySearchTree([4, 2, 0, 3, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #110', () => {
expect(new BinarySearchTree([4, 2, 1, 0, 3]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #111', () => {
expect(new BinarySearchTree([4, 2, 1, 3, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #112', () => {
expect(new BinarySearchTree([4, 2, 3, 0, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #113', () => {
expect(new BinarySearchTree([4, 2, 3, 1, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #114', () => {
expect(new BinarySearchTree([4, 3, 0, 1, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #115', () => {
expect(new BinarySearchTree([4, 3, 0, 2, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #116', () => {
expect(new BinarySearchTree([4, 3, 1, 0, 2]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #117', () => {
expect(new BinarySearchTree([4, 3, 1, 2, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #118', () => {
expect(new BinarySearchTree([4, 3, 2, 0, 1]).toList()).toEqual([0, 1, 2, 3, 4]);
});
test('sorts permutation #119', () => {
expect(new BinarySearchTree([4, 3, 2, 1, 0]).toList()).toEqual([0, 1, 2, 3, 4]);
});
});
This diff is collapsed.
/* eslint-disable no-magic-numbers */
import { BinarySearchTree } from './binarySearchTree.js';
describe('insertion', () => {
test('ignores the repeats in insertion sequence #0', () => {
expect(new BinarySearchTree([0, 1, 2, 3, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #1', () => {
expect(new BinarySearchTree([0, 1, 2, 3, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #2', () => {
expect(new BinarySearchTree([0, 1, 2, 3, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #3', () => {
expect(new BinarySearchTree([0, 1, 2, 3, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #4', () => {
expect(new BinarySearchTree([0, 1, 3, 2, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #5', () => {
expect(new BinarySearchTree([0, 1, 3, 2, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #6', () => {
expect(new BinarySearchTree([0, 1, 3, 2, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #7', () => {
expect(new BinarySearchTree([0, 1, 3, 2, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #8', () => {
expect(new BinarySearchTree([0, 2, 1, 3, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #9', () => {
expect(new BinarySearchTree([0, 2, 1, 3, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #10', () => {
expect(new BinarySearchTree([0, 2, 1, 3, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #11', () => {
expect(new BinarySearchTree([0, 2, 1, 3, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #12', () => {
expect(new BinarySearchTree([0, 2, 3, 1, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #13', () => {
expect(new BinarySearchTree([0, 2, 3, 1, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #14', () => {
expect(new BinarySearchTree([0, 2, 3, 1, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #15', () => {
expect(new BinarySearchTree([0, 2, 3, 1, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #16', () => {
expect(new BinarySearchTree([0, 3, 1, 2, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #17', () => {
expect(new BinarySearchTree([0, 3, 1, 2, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #18', () => {
expect(new BinarySearchTree([0, 3, 1, 2, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #19', () => {
expect(new BinarySearchTree([0, 3, 1, 2, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #20', () => {
expect(new BinarySearchTree([0, 3, 2, 1, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #21', () => {
expect(new BinarySearchTree([0, 3, 2, 1, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #22', () => {
expect(new BinarySearchTree([0, 3, 2, 1, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #23', () => {
expect(new BinarySearchTree([0, 3, 2, 1, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #24', () => {
expect(new BinarySearchTree([1, 0, 2, 3, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #25', () => {
expect(new BinarySearchTree([1, 0, 2, 3, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #26', () => {
expect(new BinarySearchTree([1, 0, 2, 3, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #27', () => {
expect(new BinarySearchTree([1, 0, 2, 3, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #28', () => {
expect(new BinarySearchTree([1, 0, 3, 2, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #29', () => {
expect(new BinarySearchTree([1, 0, 3, 2, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #30', () => {
expect(new BinarySearchTree([1, 0, 3, 2, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #31', () => {
expect(new BinarySearchTree([1, 0, 3, 2, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #32', () => {
expect(new BinarySearchTree([1, 2, 0, 3, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #33', () => {
expect(new BinarySearchTree([1, 2, 0, 3, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #34', () => {
expect(new BinarySearchTree([1, 2, 0, 3, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #35', () => {
expect(new BinarySearchTree([1, 2, 0, 3, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #36', () => {
expect(new BinarySearchTree([1, 2, 3, 0, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #37', () => {
expect(new BinarySearchTree([1, 2, 3, 0, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #38', () => {
expect(new BinarySearchTree([1, 2, 3, 0, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #39', () => {
expect(new BinarySearchTree([1, 2, 3, 0, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #40', () => {
expect(new BinarySearchTree([1, 3, 0, 2, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #41', () => {
expect(new BinarySearchTree([1, 3, 0, 2, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #42', () => {
expect(new BinarySearchTree([1, 3, 0, 2, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #43', () => {
expect(new BinarySearchTree([1, 3, 0, 2, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #44', () => {
expect(new BinarySearchTree([1, 3, 2, 0, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #45', () => {
expect(new BinarySearchTree([1, 3, 2, 0, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #46', () => {
expect(new BinarySearchTree([1, 3, 2, 0, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #47', () => {
expect(new BinarySearchTree([1, 3, 2, 0, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #48', () => {
expect(new BinarySearchTree([2, 0, 1, 3, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #49', () => {
expect(new BinarySearchTree([2, 0, 1, 3, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #50', () => {
expect(new BinarySearchTree([2, 0, 1, 3, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #51', () => {
expect(new BinarySearchTree([2, 0, 1, 3, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #52', () => {
expect(new BinarySearchTree([2, 0, 3, 1, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #53', () => {
expect(new BinarySearchTree([2, 0, 3, 1, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #54', () => {
expect(new BinarySearchTree([2, 0, 3, 1, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #55', () => {
expect(new BinarySearchTree([2, 0, 3, 1, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #56', () => {
expect(new BinarySearchTree([2, 1, 0, 3, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #57', () => {
expect(new BinarySearchTree([2, 1, 0, 3, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #58', () => {
expect(new BinarySearchTree([2, 1, 0, 3, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #59', () => {
expect(new BinarySearchTree([2, 1, 0, 3, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #60', () => {
expect(new BinarySearchTree([2, 1, 3, 0, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #61', () => {
expect(new BinarySearchTree([2, 1, 3, 0, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #62', () => {
expect(new BinarySearchTree([2, 1, 3, 0, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #63', () => {
expect(new BinarySearchTree([2, 1, 3, 0, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #64', () => {
expect(new BinarySearchTree([2, 3, 0, 1, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #65', () => {
expect(new BinarySearchTree([2, 3, 0, 1, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #66', () => {
expect(new BinarySearchTree([2, 3, 0, 1, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #67', () => {
expect(new BinarySearchTree([2, 3, 0, 1, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #68', () => {
expect(new BinarySearchTree([2, 3, 1, 0, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #69', () => {
expect(new BinarySearchTree([2, 3, 1, 0, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #70', () => {
expect(new BinarySearchTree([2, 3, 1, 0, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #71', () => {
expect(new BinarySearchTree([2, 3, 1, 0, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #72', () => {
expect(new BinarySearchTree([3, 0, 1, 2, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #73', () => {
expect(new BinarySearchTree([3, 0, 1, 2, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #74', () => {
expect(new BinarySearchTree([3, 0, 1, 2, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #75', () => {
expect(new BinarySearchTree([3, 0, 1, 2, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #76', () => {
expect(new BinarySearchTree([3, 0, 2, 1, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #77', () => {
expect(new BinarySearchTree([3, 0, 2, 1, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #78', () => {
expect(new BinarySearchTree([3, 0, 2, 1, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #79', () => {
expect(new BinarySearchTree([3, 0, 2, 1, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #80', () => {
expect(new BinarySearchTree([3, 1, 0, 2, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #81', () => {
expect(new BinarySearchTree([3, 1, 0, 2, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #82', () => {
expect(new BinarySearchTree([3, 1, 0, 2, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #83', () => {
expect(new BinarySearchTree([3, 1, 0, 2, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #84', () => {
expect(new BinarySearchTree([3, 1, 2, 0, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #85', () => {
expect(new BinarySearchTree([3, 1, 2, 0, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #86', () => {
expect(new BinarySearchTree([3, 1, 2, 0, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #87', () => {
expect(new BinarySearchTree([3, 1, 2, 0, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #88', () => {
expect(new BinarySearchTree([3, 2, 0, 1, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #89', () => {
expect(new BinarySearchTree([3, 2, 0, 1, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #90', () => {
expect(new BinarySearchTree([3, 2, 0, 1, 0]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #91', () => {
expect(new BinarySearchTree([3, 2, 0, 1, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #92', () => {
expect(new BinarySearchTree([3, 2, 1, 0, 3]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #93', () => {
expect(new BinarySearchTree([3, 2, 1, 0, 2]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #94', () => {
expect(new BinarySearchTree([3, 2, 1, 0, 1]).toList()).toEqual([0, 1, 2, 3]);
});
test('ignores the repeats in insertion sequence #95', () => {
expect(new BinarySearchTree([3, 2, 1, 0, 0]).toList()).toEqual([0, 1, 2, 3]);
});
});
This diff is collapsed.
This diff is collapsed.
import NodeEnvironment from 'jest-environment-node';
export default class FailFastEnvironment extends NodeEnvironment {
constructor(...rest) {
super(...rest);
this.failed = false;
}
async handleTestEvent(event, state) {
switch (event.name) {
case 'hook_failure':
case 'test_fn_failure':
this.failed = true;
break;
case 'test_start':
if (this.failed) {
event.test.mode = 'skip';
}
break;
default:
}
if (super.handleTestEvent !== undefined) {
await super.handleTestEvent(event, state);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment