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

Initial commit.

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1214 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:csce-310/eslint-config.git
# Homework 1
Starter code for Homework 1 in 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/homework-1.git
$ cd homework-1
```
(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/136556/assignments/1303209>.
Subproject commit 16524f5ac58d4b13378261f1ab29bc1acc2a2099
{
"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": "@unlcsce/development-environment-homework",
"version": "1.0.0",
"description": "Starter code for Homework 1.",
"type": "module",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**",
"test-once:knead": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"\\`knead\\` function\"",
"test-once:closure": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"\\`closure\\` function\"",
"test-once:representatives": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage -t \"\\`countChoicesOfRepresentatives\\` function\"",
"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": {
"@unlcsce/eslint-config": "file:../eslint-config",
"eslint": "^8.20.0",
"jest": "^28.1.3",
"jest-environment-node": "^28.1.3"
},
"eslintConfig": {
"extends": "@unlcsce"
},
"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 function closure(set, unaryOperation) {
return set; // Implement this function per the assignment instructions.
}
import { closure } from './closure.js';
function f(x) {
return Math.floor(x / 2);
}
function bitsum(value) {
console.assert(Number.isInteger(value));
console.assert(value >= 0);
let result = 0;
for (let bits = value; bits > 0;) {
const bit = bits & ~(bits - 1);
++result;
bits -= bit;
}
return result;
}
function g(x) {
return bitsum(x * x);
}
function numerically(left, right) {
return left - right;
}
describe('the `closure` function', () => {
test('finds the closure under f of an empty set', () => {
expect([...closure(new Set(), f)].sort(numerically)).toEqual([]);
});
test('finds the closure under g of an empty set', () => {
expect([...closure(new Set(), g)].sort(numerically)).toEqual([]);
});
test('finds the closure under f of a singleton holding 0', () => {
expect([...closure(new Set([0]), f)].sort(numerically)).toEqual([0]);
});
test('finds the closure under g of a singleton holding 0', () => {
expect([...closure(new Set([0]), g)].sort(numerically)).toEqual([0]);
});
test('finds the closure under f of a singleton holding 1', () => {
expect([...closure(new Set([1]), f)].sort(numerically)).toEqual([0, 1]);
});
test('finds the closure under g of a singleton holding 1', () => {
expect([...closure(new Set([1]), g)].sort(numerically)).toEqual([1]);
});
test('finds the closure under f of a singleton holding 2', () => {
expect([...closure(new Set([2]), f)].sort(numerically)).toEqual([0, 1, 2]);
});
test('finds the closure under g of a singleton holding 2', () => {
expect([...closure(new Set([2]), g)].sort(numerically)).toEqual([1, 2]);
});
test('finds the closure under f of a singleton holding 3', () => {
expect([...closure(new Set([3]), f)].sort(numerically)).toEqual([0, 1, 3]);
});
test('finds the closure under g of a singleton holding 3', () => {
expect([...closure(new Set([3]), g)].sort(numerically)).toEqual([1, 2, 3]);
});
test('finds the closure under g of a singleton holding 4', () => {
expect([...closure(new Set([4]), g)].sort(numerically)).toEqual([1, 4]);
});
test('finds the closure under g of a singleton holding 5', () => {
expect([...closure(new Set([5]), g)].sort(numerically)).toEqual([1, 2, 3, 5]);
});
test('finds the closure under g of a singleton holding 6', () => {
expect([...closure(new Set([6]), g)].sort(numerically)).toEqual([1, 2, 6]);
});
test('finds the closure under g of a singleton holding 7', () => {
expect([...closure(new Set([7]), g)].sort(numerically)).toEqual([1, 2, 3, 7]);
});
test('finds the closure under g of a singleton holding 8', () => {
expect([...closure(new Set([8]), g)].sort(numerically)).toEqual([1, 8]);
});
test('finds the closure under g of a singleton holding 9', () => {
expect([...closure(new Set([9]), g)].sort(numerically)).toEqual([1, 2, 3, 9]);
});
test('finds the closure under g of a singleton holding 10', () => {
expect([...closure(new Set([10]), g)].sort(numerically)).toEqual([1, 2, 3, 10]);
});
test('finds the closure under g of a singleton holding 11', () => {
expect([...closure(new Set([11]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 11]);
});
test('finds the closure under g of a singleton holding 12', () => {
expect([...closure(new Set([12]), g)].sort(numerically)).toEqual([1, 2, 12]);
});
test('finds the closure under g of a singleton holding 13', () => {
expect([...closure(new Set([13]), g)].sort(numerically)).toEqual([1, 4, 13]);
});
test('finds the closure under g of a singleton holding 14', () => {
expect([...closure(new Set([14]), g)].sort(numerically)).toEqual([1, 2, 3, 14]);
});
test('finds the closure under g of a singleton holding 15', () => {
expect([...closure(new Set([15]), g)].sort(numerically)).toEqual([1, 4, 15]);
});
test('finds the closure under g of a singleton holding 16', () => {
expect([...closure(new Set([16]), g)].sort(numerically)).toEqual([1, 16]);
});
test('finds the closure under g of a singleton holding 17', () => {
expect([...closure(new Set([17]), g)].sort(numerically)).toEqual([1, 2, 3, 17]);
});
test('finds the closure under g of a singleton holding 18', () => {
expect([...closure(new Set([18]), g)].sort(numerically)).toEqual([1, 2, 3, 18]);
});
test('finds the closure under g of a singleton holding 19', () => {
expect([...closure(new Set([19]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 19]);
});
test('finds the closure under g of a singleton holding 20', () => {
expect([...closure(new Set([20]), g)].sort(numerically)).toEqual([1, 2, 3, 20]);
});
test('finds the closure under g of a singleton holding 21', () => {
expect([...closure(new Set([21]), g)].sort(numerically)).toEqual([1, 2, 6, 21]);
});
test('finds the closure under g of a singleton holding 22', () => {
expect([...closure(new Set([22]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 22]);
});
test('finds the closure under g of a singleton holding 23', () => {
expect([...closure(new Set([23]), g)].sort(numerically)).toEqual([1, 2, 3, 23]);
});
test('finds the closure under g of a singleton holding 24', () => {
expect([...closure(new Set([24]), g)].sort(numerically)).toEqual([1, 2, 24]);
});
test('finds the closure under g of a singleton holding 25', () => {
expect([...closure(new Set([25]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 25]);
});
test('finds the closure under g of a singleton holding 26', () => {
expect([...closure(new Set([26]), g)].sort(numerically)).toEqual([1, 4, 26]);
});
test('finds the closure under g of a singleton holding 27', () => {
expect([...closure(new Set([27]), g)].sort(numerically)).toEqual([1, 2, 6, 27]);
});
test('finds the closure under g of a singleton holding 28', () => {
expect([...closure(new Set([28]), g)].sort(numerically)).toEqual([1, 2, 3, 28]);
});
test('finds the closure under g of a singleton holding 29', () => {
expect([...closure(new Set([29]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 29]);
});
test('finds the closure under g of a singleton holding 30', () => {
expect([...closure(new Set([30]), g)].sort(numerically)).toEqual([1, 4, 30]);
});
test('finds the closure under g of a singleton holding 31', () => {
expect([...closure(new Set([31]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 31]);
});
test('finds the closure under f of a singleton holding a much larger value', () => {
expect([...closure(new Set([193]), f)].sort(numerically)).toEqual([0, 1, 3, 6, 12, 24, 48, 96, 193]);
});
test('finds the closure under g of a singleton holding a much larger value', () => {
expect([...closure(new Set([193]), g)].sort(numerically)).toEqual([1, 2, 3, 5, 193]);
});
test('finds the closure under f of a size-2 set', () => {
expect([...closure(new Set([
72, 193,
]), f)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 6, 9, 12, 18, 24, 36, 48, 72, 96, 193,
]);
});
test('finds the closure under g of a size-2 set', () => {
expect([...closure(new Set([
72, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 72, 193,
]);
});
test('finds the closure under f of a size-3 set', () => {
expect([...closure(new Set([
72, 160, 193,
]), f)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 9, 10, 12, 18, 20, 24, 36, 40, 48, 72, 80, 96, 160, 193,
]);
});
test('finds the closure under g of a size-3 set', () => {
expect([...closure(new Set([
72, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 72, 160, 193,
]);
});
test('finds the closure under f of a size-4 set', () => {
expect([...closure(new Set([
62, 72, 160, 193,
]), f)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 12, 15, 18, 20, 24, 31, 36, 40, 48, 62, 72, 80, 96, 160, 193,
]);
});
test('finds the closure under g of a size-4 set', () => {
expect([...closure(new Set([
62, 72, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 62, 72, 160, 193,
]);
});
test('finds the closure under g of a size-5 set', () => {
expect([...closure(new Set([
62, 65, 72, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 62, 65, 72, 160, 193,
]);
});
test('finds the closure under g of a size-6 set', () => {
expect([...closure(new Set([
62, 65, 72, 123, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 8, 62, 65, 72, 123, 160, 193,
]);
});
test('finds the closure under g of a size-7 set', () => {
expect([...closure(new Set([
24, 62, 65, 72, 123, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 8, 24, 62, 65, 72, 123, 160, 193,
]);
});
test('finds the closure under g of a size-8 set', () => {
expect([...closure(new Set([
24, 62, 65, 72, 91, 123, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 8, 24, 62, 65, 72, 91, 123, 160, 193,
]);
});
test('finds the closure under g of a size-9 set', () => {
expect([...closure(new Set([
24, 62, 65, 67, 72, 91, 123, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 8, 24, 62, 65, 67, 72, 91, 123, 160, 193,
]);
});
test('finds the closure under g of a size-10 set', () => {
expect([...closure(new Set([
24, 62, 65, 67, 72, 91, 123, 153, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 5, 8, 9, 24, 62, 65, 67, 72, 91, 123, 153, 160, 193,
]);
});
test('finds the closure under g of a size-11 set', () => {
expect([...closure(new Set([
24, 30, 62, 65, 67, 72, 91, 123, 153, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 4, 5, 8, 9, 24, 30, 62, 65, 67, 72, 91, 123, 153, 160, 193,
]);
});
test('finds the closure under g of a size-12 set', () => {
expect([...closure(new Set([
4, 24, 30, 62, 65, 67, 72, 91, 123, 153, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 4, 5, 8, 9, 24, 30, 62, 65, 67, 72, 91, 123, 153, 160, 193,
]);
});
test('finds the closure under g of a size-13 set', () => {
expect([...closure(new Set([
4, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 160, 193,
]), g)].sort(numerically)).toEqual([
1, 2, 3, 4, 5, 8, 9, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 160, 193,
]);
});
test('finds the closure under g of a size-14 set', () => {
expect([...closure(new Set([
0, 4, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 160, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 8, 9, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 160, 193,
]);
});
test('finds the closure under g of a size-15 set', () => {
expect([...closure(new Set([
0, 4, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 8, 9, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 160, 179, 193,
]);
});
test('finds the closure under g of a size-16 set', () => {
expect([...closure(new Set([
0, 4, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 7, 8, 9, 24, 30, 62, 65, 66, 67, 72, 91, 123, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-17 set', () => {
expect([...closure(new Set([
0, 4, 24, 30, 62, 65, 66, 67, 72, 91, 123, 151, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 24, 30, 62, 65, 66, 67, 72, 91, 123, 151, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-18 set', () => {
expect([...closure(new Set([
0, 4, 24, 30, 62, 65, 66, 67, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 24, 30, 62, 65, 66, 67, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-19 set', () => {
expect([...closure(new Set([
0, 4, 24, 27, 30, 62, 65, 66, 67, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 24, 27, 30, 62, 65, 66, 67, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-20 set', () => {
expect([...closure(new Set([
0, 4, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-21 set', () => {
expect([...closure(new Set([
0, 4, 5, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-22 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 179, 193,
]);
});
test('finds the closure under g of a size-23 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 62, 65, 66,
67, 71, 72, 74, 91, 123, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-24 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 62, 65, 66, 67, 71, 72, 74, 91, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 62, 65, 66, 67,
71, 72, 74, 91, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-25 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 62, 65, 66, 67, 71, 72, 74, 91, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 62, 65, 66,
67, 71, 72, 74, 91, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-26 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 62, 65, 66, 67, 71, 72, 74, 91, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 62, 65, 66, 67,
71, 72, 74, 91, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-27 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71, 72, 74, 91, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 49, 62, 65, 66,
67, 71, 72, 74, 91, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-28 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71, 72,
74, 90, 91, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67,
71, 72, 74, 90, 91, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-29 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71, 72, 74,
90, 91, 92, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67,
71, 72, 74, 90, 91, 92, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193,
]);
});
test('finds the closure under g of a size-30 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71, 72, 74, 90,
91, 92, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193, 195,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71,
72, 74, 90, 91, 92, 93, 123, 131, 151, 153, 154, 160, 172, 179, 193, 195,
]);
});
test('finds the closure under g of a size-31 set', () => {
expect([...closure(new Set([
0, 4, 5, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71, 72, 74, 90,
91, 92, 93, 123, 128, 131, 151, 153, 154, 160, 172, 179, 193, 195,
]), g)].sort(numerically)).toEqual([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 24, 27, 30, 45, 49, 62, 65, 66, 67, 71, 72,
74, 90, 91, 92, 93, 123, 128, 131, 151, 153, 154, 160, 172, 179, 193, 195,
]);
});
});
export function knead(point, list) {
return list; // Implement this function per the assignment instructions.
}
import { knead } from './knead.js';
describe('the `knead` function', () => {
test('correctly rearranges an empty list with a fold point at index -1', () => {
expect(knead(-1, [])).toEqual([]);
});
test('correctly rearranges an empty list with a fold point at index 0', () => {
expect(knead(0, [])).toEqual([]);
});
test('correctly rearranges an empty list with a fold point at index 1', () => {
expect(knead(1, [])).toEqual([]);
});
test('correctly rearranges a simple length-1 list with a fold point at index -2', () => {
expect(knead(-2, [0])).toEqual([0]);
});
test('correctly rearranges a simple length-1 list with a fold point at index -1', () => {
expect(knead(-1, [0])).toEqual([0]);
});
test('correctly rearranges a simple length-1 list with a fold point at index 0', () => {
expect(knead(0, [0])).toEqual([0]);
});
test('correctly rearranges a simple length-1 list with a fold point at index 1', () => {
expect(knead(1, [0])).toEqual([0]);
});
test('correctly rearranges a simple length-1 list with a fold point at index 2', () => {
expect(knead(2, [0])).toEqual([0]);
});
test('correctly rearranges a simple length-2 list with a fold point at index -2', () => {
expect(knead(-2, [0, 1])).toEqual([0, 1]);
});
test('correctly rearranges a simple length-2 list with a fold point at index -1', () => {
expect(knead(-1, [0, 1])).toEqual([0, 1]);
});
test('correctly rearranges a simple length-2 list with a fold point at index 0', () => {
expect(knead(0, [0, 1])).toEqual([0, 1]);
});
test('correctly rearranges a simple length-2 list with a fold point at index 1', () => {
expect(knead(1, [0, 1])).toEqual([1, 0]);
});
test('correctly rearranges a simple length-2 list with a fold point at index 2', () => {
expect(knead(2, [0, 1])).toEqual([1, 0]);
});
test('correctly rearranges a simple length-2 list with a fold point at index 3', () => {
expect(knead(3, [0, 1])).toEqual([1, 0]);
});
test('correctly rearranges a simple length-3 list with a fold point at index -2', () => {
expect(knead(-2, [0, 1, 2])).toEqual([0, 1, 2]);
});
test('correctly rearranges a simple length-3 list with a fold point at index -1', () => {
expect(knead(-1, [0, 1, 2])).toEqual([0, 1, 2]);
});
test('correctly rearranges a simple length-3 list with a fold point at index 0', () => {
expect(knead(0, [0, 1, 2])).toEqual([0, 1, 2]);
});
test('correctly rearranges a simple length-3 list with a fold point at index 1', () => {
expect(knead(1, [0, 1, 2])).toEqual([1, 0, 2]);
});
test('correctly rearranges a simple length-3 list with a fold point at index 2', () => {
expect(knead(2, [0, 1, 2])).toEqual([2, 1, 0]);
});
test('correctly rearranges a simple length-3 list with a fold point at index 3', () => {
expect(knead(3, [0, 1, 2])).toEqual([2, 1, 0]);
});
test('correctly rearranges a simple length-3 list with a fold point at index 4', () => {
expect(knead(4, [0, 1, 2])).toEqual([2, 1, 0]);
});
test('correctly rearranges a simple length-4 list with a fold point at index -2', () => {
expect(knead(-2, [0, 1, 2, 3])).toEqual([0, 1, 2, 3]);
});
test('correctly rearranges a simple length-4 list with a fold point at index -1', () => {
expect(knead(-1, [0, 1, 2, 3])).toEqual([0, 1, 2, 3]);
});
test('correctly rearranges a simple length-4 list with a fold point at index 0', () => {
expect(knead(0, [0, 1, 2, 3])).toEqual([0, 1, 2, 3]);
});
test('correctly rearranges a simple length-4 list with a fold point at index 1', () => {
expect(knead(1, [0, 1, 2, 3])).toEqual([1, 0, 2, 3]);
});
test('correctly rearranges a simple length-4 list with a fold point at index 2', () => {
expect(knead(2, [0, 1, 2, 3])).toEqual([2, 1, 3, 0]);
});
test('correctly rearranges a simple length-4 list with a fold point at index 3', () => {
expect(knead(3, [0, 1, 2, 3])).toEqual([3, 2, 1, 0]);
});
test('correctly rearranges a simple length-4 list with a fold point at index 4', () => {
expect(knead(4, [0, 1, 2, 3])).toEqual([3, 2, 1, 0]);
});
test('correctly rearranges a simple length-4 list with a fold point at index 5', () => {
expect(knead(5, [0, 1, 2, 3])).toEqual([3, 2, 1, 0]);
});
test('correctly rearranges a simple length-5 list with a fold point at index -2', () => {
expect(knead(-2, [0, 1, 2, 3, 4])).toEqual([0, 1, 2, 3, 4]);
});
test('correctly rearranges a simple length-5 list with a fold point at index -1', () => {
expect(knead(-1, [0, 1, 2, 3, 4])).toEqual([0, 1, 2, 3, 4]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 0', () => {
expect(knead(0, [0, 1, 2, 3, 4])).toEqual([0, 1, 2, 3, 4]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 1', () => {
expect(knead(1, [0, 1, 2, 3, 4])).toEqual([1, 0, 2, 3, 4]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 2', () => {
expect(knead(2, [0, 1, 2, 3, 4])).toEqual([2, 1, 3, 0, 4]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 3', () => {
expect(knead(3, [0, 1, 2, 3, 4])).toEqual([3, 2, 4, 1, 0]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 4', () => {
expect(knead(4, [0, 1, 2, 3, 4])).toEqual([4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 5', () => {
expect(knead(5, [0, 1, 2, 3, 4])).toEqual([4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-5 list with a fold point at index 6', () => {
expect(knead(6, [0, 1, 2, 3, 4])).toEqual([4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-6 list with a fold point at index -2', () => {
expect(knead(-2, [0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5]);
});
test('correctly rearranges a simple length-6 list with a fold point at index -1', () => {
expect(knead(-1, [0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 0', () => {
expect(knead(0, [0, 1, 2, 3, 4, 5])).toEqual([0, 1, 2, 3, 4, 5]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 1', () => {
expect(knead(1, [0, 1, 2, 3, 4, 5])).toEqual([1, 0, 2, 3, 4, 5]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 2', () => {
expect(knead(2, [0, 1, 2, 3, 4, 5])).toEqual([2, 1, 3, 0, 4, 5]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 3', () => {
expect(knead(3, [0, 1, 2, 3, 4, 5])).toEqual([3, 2, 4, 1, 5, 0]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 4', () => {
expect(knead(4, [0, 1, 2, 3, 4, 5])).toEqual([4, 3, 5, 2, 1, 0]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 5', () => {
expect(knead(5, [0, 1, 2, 3, 4, 5])).toEqual([5, 4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 6', () => {
expect(knead(6, [0, 1, 2, 3, 4, 5])).toEqual([5, 4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-6 list with a fold point at index 7', () => {
expect(knead(7, [0, 1, 2, 3, 4, 5])).toEqual([5, 4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-7 list with a fold point at index -2', () => {
expect(knead(-2, [0, 1, 2, 3, 4, 5, 6])).toEqual([0, 1, 2, 3, 4, 5, 6]);
});
test('correctly rearranges a simple length-7 list with a fold point at index -1', () => {
expect(knead(-1, [0, 1, 2, 3, 4, 5, 6])).toEqual([0, 1, 2, 3, 4, 5, 6]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 0', () => {
expect(knead(0, [0, 1, 2, 3, 4, 5, 6])).toEqual([0, 1, 2, 3, 4, 5, 6]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 1', () => {
expect(knead(1, [0, 1, 2, 3, 4, 5, 6])).toEqual([1, 0, 2, 3, 4, 5, 6]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 2', () => {
expect(knead(2, [0, 1, 2, 3, 4, 5, 6])).toEqual([2, 1, 3, 0, 4, 5, 6]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 3', () => {
expect(knead(3, [0, 1, 2, 3, 4, 5, 6])).toEqual([3, 2, 4, 1, 5, 0, 6]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 4', () => {
expect(knead(4, [0, 1, 2, 3, 4, 5, 6])).toEqual([4, 3, 5, 2, 6, 1, 0]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 5', () => {
expect(knead(5, [0, 1, 2, 3, 4, 5, 6])).toEqual([5, 4, 6, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 6', () => {
expect(knead(6, [0, 1, 2, 3, 4, 5, 6])).toEqual([6, 5, 4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 7', () => {
expect(knead(7, [0, 1, 2, 3, 4, 5, 6])).toEqual([6, 5, 4, 3, 2, 1, 0]);
});
test('correctly rearranges a simple length-7 list with a fold point at index 8', () => {
expect(knead(8, [0, 1, 2, 3, 4, 5, 6])).toEqual([6, 5, 4, 3, 2, 1, 0]);
});
test('correctly rearranges an interesting length-1 list with a fold point at index -2', () => {
expect(knead(-2, [12])).toEqual([12]);
});
test('correctly rearranges an interesting length-1 list with a fold point at index -1', () => {
expect(knead(-1, [12])).toEqual([12]);
});
test('correctly rearranges an interesting length-1 list with a fold point at index 0', () => {
expect(knead(0, [12])).toEqual([12]);
});
test('correctly rearranges an interesting length-1 list with a fold point at index 1', () => {
expect(knead(1, [12])).toEqual([12]);
});
test('correctly rearranges an interesting length-1 list with a fold point at index 2', () => {
expect(knead(2, [12])).toEqual([12]);
});
test('correctly rearranges an interesting length-2 list with a fold point at index -2', () => {
expect(knead(-2, [12, 8])).toEqual([12, 8]);
});
test('correctly rearranges an interesting length-2 list with a fold point at index -1', () => {
expect(knead(-1, [12, 8])).toEqual([12, 8]);
});
test('correctly rearranges an interesting length-2 list with a fold point at index 0', () => {
expect(knead(0, [12, 8])).toEqual([12, 8]);
});
test('correctly rearranges an interesting length-2 list with a fold point at index 1', () => {
expect(knead(1, [12, 8])).toEqual([8, 12]);
});
test('correctly rearranges an interesting length-2 list with a fold point at index 2', () => {
expect(knead(2, [12, 8])).toEqual([8, 12]);
});
test('correctly rearranges an interesting length-2 list with a fold point at index 3', () => {
expect(knead(3, [12, 8])).toEqual([8, 12]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index -2', () => {
expect(knead(-2, [12, 8, 41])).toEqual([12, 8, 41]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index -1', () => {
expect(knead(-1, [12, 8, 41])).toEqual([12, 8, 41]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index 0', () => {
expect(knead(0, [12, 8, 41])).toEqual([12, 8, 41]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index 1', () => {
expect(knead(1, [12, 8, 41])).toEqual([8, 12, 41]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index 2', () => {
expect(knead(2, [12, 8, 41])).toEqual([41, 8, 12]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index 3', () => {
expect(knead(3, [12, 8, 41])).toEqual([41, 8, 12]);
});
test('correctly rearranges an interesting length-3 list with a fold point at index 4', () => {
expect(knead(4, [12, 8, 41])).toEqual([41, 8, 12]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index -2', () => {
expect(knead(-2, [12, 8, 41, 18])).toEqual([12, 8, 41, 18]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index -1', () => {
expect(knead(-1, [12, 8, 41, 18])).toEqual([12, 8, 41, 18]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index 0', () => {
expect(knead(0, [12, 8, 41, 18])).toEqual([12, 8, 41, 18]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index 1', () => {
expect(knead(1, [12, 8, 41, 18])).toEqual([8, 12, 41, 18]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index 2', () => {
expect(knead(2, [12, 8, 41, 18])).toEqual([41, 8, 18, 12]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index 3', () => {
expect(knead(3, [12, 8, 41, 18])).toEqual([18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index 4', () => {
expect(knead(4, [12, 8, 41, 18])).toEqual([18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-4 list with a fold point at index 5', () => {
expect(knead(5, [12, 8, 41, 18])).toEqual([18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index -2', () => {
expect(knead(-2, [12, 8, 41, 18, 87])).toEqual([12, 8, 41, 18, 87]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index -1', () => {
expect(knead(-1, [12, 8, 41, 18, 87])).toEqual([12, 8, 41, 18, 87]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 0', () => {
expect(knead(0, [12, 8, 41, 18, 87])).toEqual([12, 8, 41, 18, 87]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 1', () => {
expect(knead(1, [12, 8, 41, 18, 87])).toEqual([8, 12, 41, 18, 87]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 2', () => {
expect(knead(2, [12, 8, 41, 18, 87])).toEqual([41, 8, 18, 12, 87]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 3', () => {
expect(knead(3, [12, 8, 41, 18, 87])).toEqual([18, 41, 87, 8, 12]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 4', () => {
expect(knead(4, [12, 8, 41, 18, 87])).toEqual([87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 5', () => {
expect(knead(5, [12, 8, 41, 18, 87])).toEqual([87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-5 list with a fold point at index 6', () => {
expect(knead(6, [12, 8, 41, 18, 87])).toEqual([87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index -2', () => {
expect(knead(-2, [12, 8, 41, 18, 87, 19])).toEqual([12, 8, 41, 18, 87, 19]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index -1', () => {
expect(knead(-1, [12, 8, 41, 18, 87, 19])).toEqual([12, 8, 41, 18, 87, 19]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 0', () => {
expect(knead(0, [12, 8, 41, 18, 87, 19])).toEqual([12, 8, 41, 18, 87, 19]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 1', () => {
expect(knead(1, [12, 8, 41, 18, 87, 19])).toEqual([8, 12, 41, 18, 87, 19]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 2', () => {
expect(knead(2, [12, 8, 41, 18, 87, 19])).toEqual([41, 8, 18, 12, 87, 19]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 3', () => {
expect(knead(3, [12, 8, 41, 18, 87, 19])).toEqual([18, 41, 87, 8, 19, 12]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 4', () => {
expect(knead(4, [12, 8, 41, 18, 87, 19])).toEqual([87, 18, 19, 41, 8, 12]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 5', () => {
expect(knead(5, [12, 8, 41, 18, 87, 19])).toEqual([19, 87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 6', () => {
expect(knead(6, [12, 8, 41, 18, 87, 19])).toEqual([19, 87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-6 list with a fold point at index 7', () => {
expect(knead(7, [12, 8, 41, 18, 87, 19])).toEqual([19, 87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index -2', () => {
expect(knead(-2, [12, 8, 41, 18, 87, 19, 74])).toEqual([12, 8, 41, 18, 87, 19, 74]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index -1', () => {
expect(knead(-1, [12, 8, 41, 18, 87, 19, 74])).toEqual([12, 8, 41, 18, 87, 19, 74]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 0', () => {
expect(knead(0, [12, 8, 41, 18, 87, 19, 74])).toEqual([12, 8, 41, 18, 87, 19, 74]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 1', () => {
expect(knead(1, [12, 8, 41, 18, 87, 19, 74])).toEqual([8, 12, 41, 18, 87, 19, 74]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 2', () => {
expect(knead(2, [12, 8, 41, 18, 87, 19, 74])).toEqual([41, 8, 18, 12, 87, 19, 74]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 3', () => {
expect(knead(3, [12, 8, 41, 18, 87, 19, 74])).toEqual([18, 41, 87, 8, 19, 12, 74]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 4', () => {
expect(knead(4, [12, 8, 41, 18, 87, 19, 74])).toEqual([87, 18, 19, 41, 74, 8, 12]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 5', () => {
expect(knead(5, [12, 8, 41, 18, 87, 19, 74])).toEqual([19, 87, 74, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 6', () => {
expect(knead(6, [12, 8, 41, 18, 87, 19, 74])).toEqual([74, 19, 87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 7', () => {
expect(knead(7, [12, 8, 41, 18, 87, 19, 74])).toEqual([74, 19, 87, 18, 41, 8, 12]);
});
test('correctly rearranges an interesting length-7 list with a fold point at index 8', () => {
expect(knead(8, [12, 8, 41, 18, 87, 19, 74])).toEqual([74, 19, 87, 18, 41, 8, 12]);
});
});
export function countChoicesOfRepresentatives(labeling) {
return 0; // Implement this function per the assignment instructions.
}
import { countChoicesOfRepresentatives } from './representatives.js';
const MAP_SAFETY_CHECK = true;
class Element {
constructor(name) {
this.name = name;
}
toString() {
if (MAP_SAFETY_CHECK) {
throw new Error(`
Tried to convert an element to a string inside of \`countChoicesOfRepresentatives\`. This probably means that you are
incorrectly using the [] operator with a JavaScript map. If so, use one of the \`.has\`, \`.get\`, or \`.set\` methods
instead. If you are just trying to debug with a template string in a logging function like \`console.log\`, then
disable this check by setting \`MAP_SAFETY_CHECK\` to \`false\` in \`representatives.test.js\`, but remember to turn it
back on when you are done debugging.`.replaceAll('\n', ' ').trim());
}
return this.name;
}
}
const [
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p,
] = [...'abcdefghijklmnop'].map((name) => new Element(name));
describe('the `countChoicesOfRepresentatives` function', () => {
test('identifies one way to choose representatives from zero equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map())).toBe(1);
});
test('identifies one way to choose representatives from one singleton equivalence class', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
]))).toBe(1);
});
test('identifies one way to choose representatives from two singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
]))).toBe(1);
});
test('identifies one way to choose representatives from three singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
]))).toBe(1);
});
test('identifies one way to choose representatives from four singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, d],
]))).toBe(1);
});
test('identifies one way to choose representatives from five singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, d],
[m, e],
]))).toBe(1);
});
test('identifies one way to choose representatives from six singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, d],
[m, e],
[n, f],
]))).toBe(1);
});
test('identifies one way to choose representatives from seven singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, d],
[m, e],
[n, f],
[o, g],
]))).toBe(1);
});
test('identifies one way to choose representatives from eight singleton equivalence classes', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, d],
[m, e],
[n, f],
[o, g],
[p, h],
]))).toBe(1);
});
test('identifies two ways to choose representatives when one equivalence class offers two options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, c],
[l, d],
[m, e],
[n, f],
[o, g],
[p, h],
]))).toBe(2);
});
test('identifies three ways to choose representatives when one equivalence class offers three options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, c],
[l, d],
[m, e],
[n, f],
[o, g],
[p, a],
]))).toBe(3);
});
test('identifies four ways to choose representatives when one equivalence class offers four options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, c],
[l, d],
[m, e],
[n, a],
[o, g],
[p, a],
]))).toBe(4);
});
test('identifies five ways to choose representatives when one equivalence class offers five options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, c],
[l, a],
[m, e],
[n, a],
[o, g],
[p, a],
]))).toBe(5);
});
test('identifies six ways to choose representatives when one equivalence class offers six options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, c],
[l, a],
[m, a],
[n, a],
[o, g],
[p, a],
]))).toBe(6);
});
test('identifies seven ways to choose representatives when one equivalence class offers seven options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, a],
[l, a],
[m, a],
[n, a],
[o, g],
[p, a],
]))).toBe(7);
});
test('identifies eight ways to choose representatives when one equivalence class offers eight options', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, a],
[l, a],
[m, a],
[n, a],
[o, a],
[p, a],
]))).toBe(8);
});
test('identifies four ways to choose representatives when there are two binary choices', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, c],
[l, d],
[m, b],
[n, f],
[o, b],
[p, h],
]))).toBe(4);
});
test('identifies nine ways to choose representatives when there are two ternary choices', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, b],
[l, d],
[m, b],
[n, a],
[o, b],
[p, h],
]))).toBe(9);
});
test('identifies 16 ways to choose representatives when there are two quaternary choices', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, a],
[k, b],
[l, b],
[m, b],
[n, a],
[o, b],
[p, a],
]))).toBe(16);
});
test('identifies 8 ways to choose representatives when there are three binary choices', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, d],
[m, a],
[n, b],
[o, c],
[p, h],
]))).toBe(8);
});
test('identifies 12 ways to choose representatives when there are two binary choices and one ternary choice', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, c],
[m, a],
[n, b],
[o, c],
[p, h],
]))).toBe(12);
});
test('identifies 18 ways to choose representatives when there are two ternary choices and one binary choice', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, a],
[j, b],
[k, c],
[l, c],
[m, a],
[n, b],
[o, c],
[p, b],
]))).toBe(18);
});
test('identifies 12 ways to choose representatives when there is a ternary choices and a quaternary choice', () => {
expect(countChoicesOfRepresentatives(new Map([
[i, e],
[j, b],
[k, e],
[l, e],
[m, e],
[n, f],
[o, f],
[p, f],
]))).toBe(12);
});
});
import jestEnvironmentNode from 'jest-environment-node';
export default class FailFastEnvironment extends jestEnvironmentNode.default {
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);
}
}
}
This diff is collapsed.
{
"name": "@unlcsce/homework-1",
"version": "1.0.0",
"description": "Starter code for Homework 1.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd homework-1 && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd homework-1 && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:knead": "cd homework-1 && npm run test-once:knead",
"test-once:closure": "cd homework-1 && npm run test-once:closure",
"test-once:representatives": "cd homework-1 && npm run test-once:representatives",
"test-once": "cd homework-1 && npm run test-once",
"test": "run-s test-once"
},
"devDependencies": {
"ghooks": "^2.0.4",
"npm-run-all": "^4.1.5"
},
"config": {
"ghooks": {
"pre-commit": "npm run lint"
}
}
}
*~
*.aux
*.toc
*.out
*.fdb_latexmk
*.fls
*.log
*.synctex.gz
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment