Skip to content
Snippets Groups Projects
Commit 173a4482 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
# 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
{
"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/dynamic-programming",
"version": "1.0.0",
"description": "Starter code for the lab on dynamic programming.",
"type": "module",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**",
"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."
]
}
class Backpointer {
constructor() {
// TODO: stub
}
}
const IMPOSSIBLE = new Backpointer(/* TODO: arguments needed */);
function chooseBackpointer(coins, backpointers) {
const currentAmount = backpointers.length;
let best = IMPOSSIBLE;
// TODO: stub
console.assert(
best !== IMPOSSIBLE,
`Found no coin small enough for making change for ${currentAmount}, ` +
'even though makeChange should guarantee that there is always such a coin.',
);
return best;
}
export function makeChange(coins, amount) {
console.assert(coins.every((coin) => coin > 0), 'Tried to make change with nonpositive denominations.');
console.assert(coins.every(Number.isInteger), 'Tried to make change with nonintegral denominations.');
console.assert(coins.includes(1), 'Tried to make change without a 1¢ coin available.');
console.assert(Number.isInteger(amount), `Tried to make change for the nonintegral amount ${amount}¢.`);
console.assert(amount >= 0, `Tried to make change for the negative amount ${amount}¢.`);
const backpointers = [/* TODO: initial backpointers */];
while (false /* TODO: condition */) {
backpointers.push(chooseBackpointer(coins, backpointers));
}
const results = [];
// TODO: stub
return results.reverse();
}
/* eslint-disable no-magic-numbers */
import { makeChange } from './makeChange.js';
describe('makeChange makes change using the fewest possible number of coins', () => {
test('when the amount is 7¢ and the coins are {1¢, 3¢, 4¢, 5¢}', () => {
expect(makeChange([1, 3, 4, 5], 7)).toEqual([4, 3]);
});
test('when the amount is 8¢ and the coins are {1¢, 2¢, 4¢, 5¢}', () => {
expect(makeChange([1, 2, 4, 5], 8)).toEqual([4, 4]);
});
test('when the amount is 8¢ and the coins are {1¢, 3¢, 4¢, 6¢}', () => {
expect(makeChange([1, 3, 4, 6], 8)).toEqual([4, 4]);
});
test('when the amount is 8¢ and the coins are {1¢, 3¢, 5¢, 6¢}', () => {
expect(makeChange([1, 3, 5, 6], 8)).toEqual([5, 3]);
});
test('when the amount is 8¢ and the coins are {1¢, 4¢, 5¢, 6¢}', () => {
expect(makeChange([1, 4, 5, 6], 8)).toEqual([4, 4]);
});
test('when the amount is 9¢ and the coins are {1¢, 3¢, 6¢, 7¢}', () => {
expect(makeChange([1, 3, 6, 7], 9)).toEqual([6, 3]);
});
test('when the amount is 9¢ and the coins are {1¢, 4¢, 5¢, 6¢}', () => {
expect(makeChange([1, 4, 5, 6], 9)).toEqual([5, 4]);
});
test('when the amount is 9¢ and the coins are {1¢, 4¢, 5¢, 7¢}', () => {
expect(makeChange([1, 4, 5, 7], 9)).toEqual([5, 4]);
});
test('when the amount is 10¢ and the coins are {1¢, 2¢, 5¢, 6¢}', () => {
expect(makeChange([1, 2, 5, 6], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 2¢, 5¢, 7¢}', () => {
expect(makeChange([1, 2, 5, 7], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 3¢, 5¢, 6¢}', () => {
expect(makeChange([1, 3, 5, 6], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 3¢, 5¢, 8¢}', () => {
expect(makeChange([1, 3, 5, 8], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 3¢, 7¢, 8¢}', () => {
expect(makeChange([1, 3, 7, 8], 10)).toEqual([7, 3]);
});
test('when the amount is 10¢ and the coins are {1¢, 4¢, 5¢, 7¢}', () => {
expect(makeChange([1, 4, 5, 7], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 4¢, 5¢, 8¢}', () => {
expect(makeChange([1, 4, 5, 8], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 4¢, 6¢, 7¢}', () => {
expect(makeChange([1, 4, 6, 7], 10)).toEqual([6, 4]);
});
test('when the amount is 10¢ and the coins are {1¢, 4¢, 6¢, 8¢}', () => {
expect(makeChange([1, 4, 6, 8], 10)).toEqual([6, 4]);
});
test('when the amount is 10¢ and the coins are {1¢, 5¢, 6¢, 7¢}', () => {
expect(makeChange([1, 5, 6, 7], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 5¢, 6¢, 8¢}', () => {
expect(makeChange([1, 5, 6, 8], 10)).toEqual([5, 5]);
});
test('when the amount is 10¢ and the coins are {1¢, 5¢, 7¢, 8¢}', () => {
expect(makeChange([1, 5, 7, 8], 10)).toEqual([5, 5]);
});
test('when the amount is 11¢ and the coins are {1¢, 2¢, 5¢, 7¢}', () => {
expect(makeChange([1, 2, 5, 7], 11)).toEqual([5, 5, 1]);
});
test('when the amount is 11¢ and the coins are {1¢, 3¢, 8¢, 9¢}', () => {
expect(makeChange([1, 3, 8, 9], 11)).toEqual([8, 3]);
});
test('when the amount is 11¢ and the coins are {1¢, 4¢, 5¢, 8¢}', () => {
expect(makeChange([1, 4, 5, 8], 11)).toEqual([5, 5, 1]);
});
test('when the amount is 11¢ and the coins are {1¢, 4¢, 6¢, 8¢}', () => {
expect(makeChange([1, 4, 6, 8], 11)).toEqual([6, 4, 1]);
});
test('when the amount is 11¢ and the coins are {1¢, 4¢, 7¢, 8¢}', () => {
expect(makeChange([1, 4, 7, 8], 11)).toEqual([7, 4]);
});
test('when the amount is 11¢ and the coins are {1¢, 4¢, 7¢, 9¢}', () => {
expect(makeChange([1, 4, 7, 9], 11)).toEqual([7, 4]);
});
test('when the amount is 11¢ and the coins are {1¢, 5¢, 6¢, 7¢}', () => {
expect(makeChange([1, 5, 6, 7], 11)).toEqual([6, 5]);
});
test('when the amount is 11¢ and the coins are {1¢, 5¢, 6¢, 8¢}', () => {
expect(makeChange([1, 5, 6, 8], 11)).toEqual([6, 5]);
});
test('when the amount is 11¢ and the coins are {1¢, 5¢, 6¢, 9¢}', () => {
expect(makeChange([1, 5, 6, 9], 11)).toEqual([6, 5]);
});
test('when the amount is 11¢ and the coins are {1¢, 5¢, 7¢, 8¢}', () => {
expect(makeChange([1, 5, 7, 8], 11)).toEqual([5, 5, 1]);
});
test('when the amount is 12¢ and the coins are {1¢, 2¢, 6¢, 7¢}', () => {
expect(makeChange([1, 2, 6, 7], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 2¢, 6¢, 8¢}', () => {
expect(makeChange([1, 2, 6, 8], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 2¢, 6¢, 9¢}', () => {
expect(makeChange([1, 2, 6, 9], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 3¢, 4¢, 5¢}', () => {
expect(makeChange([1, 3, 4, 5], 12)).toEqual([5, 4, 3]);
});
test('when the amount is 12¢ and the coins are {1¢, 3¢, 6¢, 7¢}', () => {
expect(makeChange([1, 3, 6, 7], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 3¢, 6¢, 8¢}', () => {
expect(makeChange([1, 3, 6, 8], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 3¢, 6¢, 10¢}', () => {
expect(makeChange([1, 3, 6, 10], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 3¢, 9¢, 10¢}', () => {
expect(makeChange([1, 3, 9, 10], 12)).toEqual([9, 3]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 5¢, 9¢}', () => {
expect(makeChange([1, 4, 5, 9], 12)).toEqual([4, 4, 4]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 6¢, 7¢}', () => {
expect(makeChange([1, 4, 6, 7], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 6¢, 9¢}', () => {
expect(makeChange([1, 4, 6, 9], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 6¢, 10¢}', () => {
expect(makeChange([1, 4, 6, 10], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 7¢, 9¢}', () => {
expect(makeChange([1, 4, 7, 9], 12)).toEqual([7, 4, 1]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 8¢, 9¢}', () => {
expect(makeChange([1, 4, 8, 9], 12)).toEqual([8, 4]);
});
test('when the amount is 12¢ and the coins are {1¢, 4¢, 8¢, 10¢}', () => {
expect(makeChange([1, 4, 8, 10], 12)).toEqual([8, 4]);
});
test('when the amount is 12¢ and the coins are {1¢, 5¢, 6¢, 8¢}', () => {
expect(makeChange([1, 5, 6, 8], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 5¢, 6¢, 9¢}', () => {
expect(makeChange([1, 5, 6, 9], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 5¢, 6¢, 10¢}', () => {
expect(makeChange([1, 5, 6, 10], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 5¢, 7¢, 8¢}', () => {
expect(makeChange([1, 5, 7, 8], 12)).toEqual([7, 5]);
});
test('when the amount is 12¢ and the coins are {1¢, 5¢, 7¢, 9¢}', () => {
expect(makeChange([1, 5, 7, 9], 12)).toEqual([7, 5]);
});
test('when the amount is 12¢ and the coins are {1¢, 5¢, 7¢, 10¢}', () => {
expect(makeChange([1, 5, 7, 10], 12)).toEqual([7, 5]);
});
test('when the amount is 12¢ and the coins are {1¢, 6¢, 7¢, 8¢}', () => {
expect(makeChange([1, 6, 7, 8], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 6¢, 7¢, 9¢}', () => {
expect(makeChange([1, 6, 7, 9], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 6¢, 7¢, 10¢}', () => {
expect(makeChange([1, 6, 7, 10], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 6¢, 8¢, 9¢}', () => {
expect(makeChange([1, 6, 8, 9], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 6¢, 8¢, 10¢}', () => {
expect(makeChange([1, 6, 8, 10], 12)).toEqual([6, 6]);
});
test('when the amount is 12¢ and the coins are {1¢, 6¢, 9¢, 10¢}', () => {
expect(makeChange([1, 6, 9, 10], 12)).toEqual([6, 6]);
});
test('when the amount is 13¢ and the coins are {1¢, 2¢, 4¢, 5¢}', () => {
expect(makeChange([1, 2, 4, 5], 13)).toEqual([5, 4, 4]);
});
test('when the amount is 13¢ and the coins are {1¢, 2¢, 6¢, 8¢}', () => {
expect(makeChange([1, 2, 6, 8], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 2¢, 6¢, 9¢}', () => {
expect(makeChange([1, 2, 6, 9], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 3¢, 4¢, 7¢}', () => {
expect(makeChange([1, 3, 4, 7], 13)).toEqual([7, 3, 3]);
});
test('when the amount is 13¢ and the coins are {1¢, 3¢, 6¢, 8¢}', () => {
expect(makeChange([1, 3, 6, 8], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 3¢, 7¢, 8¢}', () => {
expect(makeChange([1, 3, 7, 8], 13)).toEqual([7, 3, 3]);
});
test('when the amount is 13¢ and the coins are {1¢, 3¢, 10¢, 11¢}', () => {
expect(makeChange([1, 3, 10, 11], 13)).toEqual([10, 3]);
});
test('when the amount is 13¢ and the coins are {1¢, 4¢, 5¢, 10¢}', () => {
expect(makeChange([1, 4, 5, 10], 13)).toEqual([5, 4, 4]);
});
test('when the amount is 13¢ and the coins are {1¢, 4¢, 6¢, 10¢}', () => {
expect(makeChange([1, 4, 6, 10], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 4¢, 8¢, 10¢}', () => {
expect(makeChange([1, 4, 8, 10], 13)).toEqual([8, 4, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 4¢, 9¢, 10¢}', () => {
expect(makeChange([1, 4, 9, 10], 13)).toEqual([9, 4]);
});
test('when the amount is 13¢ and the coins are {1¢, 4¢, 9¢, 11¢}', () => {
expect(makeChange([1, 4, 9, 11], 13)).toEqual([9, 4]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 6¢, 9¢}', () => {
expect(makeChange([1, 5, 6, 9], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 6¢, 10¢}', () => {
expect(makeChange([1, 5, 6, 10], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 7¢, 9¢}', () => {
expect(makeChange([1, 5, 7, 9], 13)).toEqual([7, 5, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 7¢, 10¢}', () => {
expect(makeChange([1, 5, 7, 10], 13)).toEqual([7, 5, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 8¢, 9¢}', () => {
expect(makeChange([1, 5, 8, 9], 13)).toEqual([8, 5]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 8¢, 10¢}', () => {
expect(makeChange([1, 5, 8, 10], 13)).toEqual([8, 5]);
});
test('when the amount is 13¢ and the coins are {1¢, 5¢, 8¢, 11¢}', () => {
expect(makeChange([1, 5, 8, 11], 13)).toEqual([8, 5]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 7¢, 8¢}', () => {
expect(makeChange([1, 6, 7, 8], 13)).toEqual([7, 6]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 7¢, 9¢}', () => {
expect(makeChange([1, 6, 7, 9], 13)).toEqual([7, 6]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 7¢, 10¢}', () => {
expect(makeChange([1, 6, 7, 10], 13)).toEqual([7, 6]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 7¢, 11¢}', () => {
expect(makeChange([1, 6, 7, 11], 13)).toEqual([7, 6]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 8¢, 9¢}', () => {
expect(makeChange([1, 6, 8, 9], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 8¢, 10¢}', () => {
expect(makeChange([1, 6, 8, 10], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 13¢ and the coins are {1¢, 6¢, 9¢, 10¢}', () => {
expect(makeChange([1, 6, 9, 10], 13)).toEqual([6, 6, 1]);
});
test('when the amount is 14¢ and the coins are {1¢, 2¢, 6¢, 9¢}', () => {
expect(makeChange([1, 2, 6, 9], 14)).toEqual([6, 6, 2]);
});
test('when the amount is 14¢ and the coins are {1¢, 2¢, 7¢, 8¢}', () => {
expect(makeChange([1, 2, 7, 8], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 2¢, 7¢, 9¢}', () => {
expect(makeChange([1, 2, 7, 9], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 2¢, 7¢, 10¢}', () => {
expect(makeChange([1, 2, 7, 10], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 2¢, 7¢, 11¢}', () => {
expect(makeChange([1, 2, 7, 11], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 4¢, 6¢}', () => {
expect(makeChange([1, 3, 4, 6], 14)).toEqual([6, 4, 4]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 4¢, 8¢}', () => {
expect(makeChange([1, 3, 4, 8], 14)).toEqual([8, 3, 3]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 5¢, 6¢}', () => {
expect(makeChange([1, 3, 5, 6], 14)).toEqual([6, 5, 3]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 7¢, 8¢}', () => {
expect(makeChange([1, 3, 7, 8], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 7¢, 9¢}', () => {
expect(makeChange([1, 3, 7, 9], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 7¢, 10¢}', () => {
expect(makeChange([1, 3, 7, 10], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 7¢, 12¢}', () => {
expect(makeChange([1, 3, 7, 12], 14)).toEqual([7, 7]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 8¢, 9¢}', () => {
expect(makeChange([1, 3, 8, 9], 14)).toEqual([8, 3, 3]);
});
test('when the amount is 14¢ and the coins are {1¢, 3¢, 11¢, 12¢}', () => {
expect(makeChange([1, 3, 11, 12], 14)).toEqual([11, 3]);
});
test('when the amount is 14¢ and the coins are {1¢, 4¢, 5¢, 6¢}', () => {
expect(makeChange([1, 4, 5, 6], 14)).toEqual([6, 4, 4]);
});
test('when the amount is 14¢ and the coins are {1¢, 4¢, 5¢, 11¢}', () => {
expect(makeChange([1, 4, 5, 11], 14)).toEqual([5, 5, 4]);
});
test('when the amount is 14¢ and the coins are {1¢, 4¢, 6¢, 11¢}', () => {
expect(makeChange([1, 4, 6, 11], 14)).toEqual([6, 4, 4]);
});
});
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);
}
}
}
Subproject commit 24df42fb655d234b83c93b0fb24d012e4d9ecb58
This diff is collapsed.
{
"name": "@unlsoft/dynamic-programming-lab",
"version": "1.0.0",
"description": "Starter code for the lab on dynamic programming.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd dynamic-programming && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd dynamic-programming && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:app": "cd dynamic-programming && npm run test-once",
"test-once": "run-s --continue-on-error test-once:**",
"test": "run-s test-once",
"start": "cd dynamic-programming && npm run start",
"build:app": "cd dynamic-programming && 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"
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment