Commit 82ef770e authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
# 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:csce-310/eslint-config.git
# Tests-Only Starter Code
A minimal project to be used as starter code for Homework 5 in the 250 section
of the CSCE 310 course at UNL.
# Quick Start
Recursively clone this repository and `cd` into the root folder:
```
$ git clone --recursive git@git.unl.edu:csce-310/2021-fall-homework-5.git
$ cd 2021-fall-homework-5
```
(If you forget `--recursive` when cloning, you can `cd` into your clone and run
`git submodule update --init --recursive` instead.)
Install dependencies:
```
$ npm install
```
# Instructions
See <https://canvas.unl.edu/courses/114253/assignments/1116786>.
Subproject commit 24df42fb655d234b83c93b0fb24d012e4d9ecb58
{
"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/homework-5-implementation",
"version": "1.0.0",
"description": "A minimal project to be used as starter code for Homework 5.",
"type": "module",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**",
"test-once:add": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"correctly inserts values\"",
"test-once:addAndDelete": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"correctly inserts and removes values\"",
"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."
]
}
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);
}
}
async teardown() {
// Preserve the VM context so that we can use `import` in async tests (the
// fact that we have to do this is almost certainly a bug in Jest).
const preservedContext = this.context;
await super.teardown();
this.context = preservedContext;
}
}
// INSTRUCTIONS: An unbalanced ternary leafy tree is a tree data structure where:
//
// * all elements are stored in leaves,
//
// * every branch has at most three children, and every branch also tracks the
// greatest element from among its descendants, and
//
// * no code is included to keep the tree balanced.
//
// It has five invariants that must be maintained in order to be valid:
//
// 1. Every branch must have either two or three children (`aritiesOkay`),
//
// 2. The root vertex, if it exists, must not have a parent (`rootOkay`),
//
// 3. The child of any vertex must know that that vertex is its parent
// (`linksOkay`),
//
// 4. The memoized greatest element in a branch must be the greatest element
// from that branch's descendants (`greatestsOkay`), and
//
// 5. The tree's elements must be sorted from left to right
// (`childrenOrderOkay`).
//
// Starter code for an unbalanced ternary leafy tree is provided below.
// Complete that JavaScript, in particular the `add` and `delete` methods, so
// that the data structure can insert and remove elements while maintaining the
// invariants listed above. (You may also find it helpful to break some of your
// logic out into helper methods.)
//
// Unit tests are provided to check functional correctness by comparing string
// representations of the tree to expected strings as elements are added and
// removed. The tests also contain extra statements like
// `expect(tree.aritiesOkay).toBe(true);` to warn you as soon as any of the five
// invariants listed above are violated—they can help you spot problems early,
// without having to wait for them to affect later insertions or deletions.
// INSTRUCTIONS: While normally it is a bad idea to turn off linter warnings, in
// code for linked data structures you may safely disable the following checks
// if they are triggering false positives:
// /* eslint-disable consistent-this */
// /* eslint-disable no-use-before-define */
const ARITY = 3;
function byGreatest(left, right) {
return left.greatest - right.greatest;
}
// eslint-disable-next-line no-unused-vars -- INSTRUCTIONS: Remove this comment once you use the Leaf class.
class Leaf {
constructor(element) {
this.parent = undefined;
this.element = element;
}
get greatest() {
return this.element;
}
get aritiesOkay() {
return true;
}
get linksOkay() {
return true;
}
get greatestsOkay() {
return true;
}
get childrenOrderOkay() {
return true;
}
toString() {
return `${this.element}`;
}
}
// eslint-disable-next-line no-unused-vars -- INSTRUCTIONS: Remove this comment once you use the Branch class.
class Branch {
constructor(parent, children) {
this.parent = parent;
this.children = children.sort(byGreatest);
this.greatest = this.lastChild.greatest;
}
get full() {
return this.children.length >= ARITY;
}
get lastChild() {
return this.children[this.children.length - 1];
}
get aritiesOkay() {
return this.children.length > 1 && this.children.length <= ARITY &&
this.children.every((child) => child.aritiesOkay);
}
get linksOkay() {
return this.children.every((child) => child.parent === this && child.linksOkay);
}
get greatestsOkay() {
return this.greatest === this.lastChild.greatest && this.children.every((child) => child.greatestsOkay);
}
get childrenOrderOkay() {
for (let i = 0; i < this.children.length - 1; ++i) {
if (this.children[i].greatest > this.children[i + 1].greatest) {
return false;
}
}
return this.children.every((child) => child.childrenOrderOkay);
}
toString() {
const contents = this.children.map((child) => `${child}`);
return `max(${contents.join(', ')}) = ${this.greatest}`;
}
}
export class LeafyTree {
constructor() {
this.root = undefined;
}
add(element) {
// INSTRUCTIONS: Complete this JavaScript method (and any other helper
// methods you deem necessary) so that it will add an element to the tree.
// The current code is just a placeholder and should be replaced.
}
delete(element) {
// INSTRUCTIONS: Complete this JavaScript method (and any other helper
// methods you deem necessary) so that it will remove an element from the
// tree.
}
get aritiesOkay() {
return this.root === undefined || this.root.aritiesOkay;
}
get rootOkay() {
return this.root === undefined || this.root.parent === undefined;
}
get linksOkay() {
return this.root === undefined || this.root.linksOkay;
}
get greatestsOkay() {
return this.root === undefined || this.root.greatestsOkay;
}
get childrenOrderOkay() {
return this.root === undefined || this.root.childrenOrderOkay;
}
toString() {
return this.root !== undefined ? `${this.root}` : '';
}
}
This diff is collapsed.
This diff is collapsed.
{
"name": "@unlsoft/homework-5",
"version": "1.0.0",
"description": "A project skeleton to be used as starter code for Homework 5.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd homework-5 && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd homework-5 && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:add": "cd homework-5 && npm run test-once:add",
"test-once:addAndDelete": "cd homework-5 && npm run test-once:addAndDelete",
"test-once": "cd homework-5 && npm run test-once",
"test": "run-s test-once",
"start": "cd homework-5 && npm run start",
"build:app": "cd homework-5 && 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"
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment