Skip to content
Snippets Groups Projects
Commit 856d75e6 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
/* IMPORTANT: Remove these directives when you start working on the code so that
* the linter will warn you about code style issues. */
/* eslint-disable no-useless-constructor */
class MonoidElement {
constructor() {
// Implement this constructor per the assignment instructions.
}
get valid() {
return false; // Implement this getter per the assignment instructions.
}
}
export const IDENTITY_ELEMENT = new MonoidElement(); // Define this object per the assignment instructions.
export function encodeAsMonoidElement(character) {
return IDENTITY_ELEMENT; // Implement this function per the assignment instructions.
}
export function combineMonoidElements(left, right) {
return IDENTITY_ELEMENT; // Implement this function per the assignment instructions.
}
import { parallelMapReduce } from './mapReduce.js';
describe('map-reduce with the TeX math monoid', () => {
test('validates the empty string with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '', 1);
expect(result.valid).toBe(true);
});
test('validates no math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', 'xyz', 1);
expect(result.valid).toBe(true);
});
test('validates inline math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$y$z', 1);
expect(result.valid).toBe(true);
});
test('does not validate broken inline math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$y$z$', 1);
expect(result.valid).toBe(false);
});
test('validates consecutive inline math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$y$', 1);
expect(result.valid).toBe(true);
});
test('validates display math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$$y$$z', 1);
expect(result.valid).toBe(true);
});
test('does not validate broken display math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$$y$$z$$', 1);
expect(result.valid).toBe(false);
});
test('validates consecutive display math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$$$$y$$', 1);
expect(result.valid).toBe(true);
});
test('validates inline math followed by display math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$$y$$', 1);
expect(result.valid).toBe(true);
});
test('validates display math followed by inline math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$$$y$', 1);
expect(result.valid).toBe(true);
});
test('does not validate a lone dollar sign ending display math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$', 1);
expect(result.valid).toBe(false);
});
test('does not validate a lone dollar sign inside display math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$y$$', 1);
expect(result.valid).toBe(false);
});
test('does not validate a double dollar sign ending inline math with one thread', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$y$$', 1);
expect(result.valid).toBe(false);
});
test('validates the empty string with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '', 2);
expect(result.valid).toBe(true);
});
test('validates no math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'xyz', 2);
expect(result.valid).toBe(true);
});
test('validates inline math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$y$z', 2);
expect(result.valid).toBe(true);
});
test('does not validate broken inline math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$y$z$', 2);
expect(result.valid).toBe(false);
});
test('validates consecutive inline math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$y$', 2);
expect(result.valid).toBe(true);
});
test('validates display math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$$y$$z', 2);
expect(result.valid).toBe(true);
});
test('does not validate broken display math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$$y$$z$$', 2);
expect(result.valid).toBe(false);
});
test('validates consecutive display math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$$$$y$$', 2);
expect(result.valid).toBe(true);
});
test('validates inline math followed by display math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$$y$$', 2);
expect(result.valid).toBe(true);
});
test('validates display math followed by inline math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$$$y$', 2);
expect(result.valid).toBe(true);
});
test('does not validate a lone dollar sign ending display math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$', 2);
expect(result.valid).toBe(false);
});
test('does not validate a lone dollar sign inside display math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$y$$', 2);
expect(result.valid).toBe(false);
});
test('does not validate a double dollar sign ending inline math with two threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$y$$', 2);
expect(result.valid).toBe(false);
});
test('validates the empty string with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '', 3);
expect(result.valid).toBe(true);
});
test('validates no math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'xyz', 3);
expect(result.valid).toBe(true);
});
test('validates inline math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$y$z', 3);
expect(result.valid).toBe(true);
});
test('does not validate broken inline math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$y$z$', 3);
expect(result.valid).toBe(false);
});
test('validates consecutive inline math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$y$', 3);
expect(result.valid).toBe(true);
});
test('validates display math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$$y$$z', 3);
expect(result.valid).toBe(true);
});
test('does not validate broken display math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', 'x$$y$$z$$', 3);
expect(result.valid).toBe(false);
});
test('validates consecutive display math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$$$$y$$', 3);
expect(result.valid).toBe(true);
});
test('validates inline math followed by display math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$$y$$', 3);
expect(result.valid).toBe(true);
});
test('validates display math followed by inline math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$$$y$', 3);
expect(result.valid).toBe(true);
});
test('does not validate a lone dollar sign ending display math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$', 3);
expect(result.valid).toBe(false);
});
test('does not validate a lone dollar sign inside display math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$$x$y$$', 3);
expect(result.valid).toBe(false);
});
test('does not validate a double dollar sign ending inline math with three threads', async() => {
const result = await parallelMapReduce('./texMath.js', '$x$$y$$', 3);
expect(result.valid).toBe(false);
});
});
/* IMPORTANT: Remove these directives when you start working on the code so that
* the linter will warn you about code style issues. */
/* eslint-disable no-useless-constructor */
const MAXIMUM_VOLUME = 15;
class MonoidElement {
constructor() {
// Implement this constructor per the assignment instructions.
}
get minimum() {
return 0; // Implement this getter per the assignment instructions.
}
get maximum() {
return MAXIMUM_VOLUME; // Implement this getter per the assignment instructions.
}
}
export const IDENTITY_ELEMENT = new MonoidElement(); // Define this object per the assignment instructions.
export function encodeAsMonoidElement(button) {
// Implement this function per the assignment instructions.
switch (button) {
case '':
return IDENTITY_ELEMENT;
case '':
return IDENTITY_ELEMENT;
default:
return IDENTITY_ELEMENT;
}
}
export function combineMonoidElements(left, right) {
return IDENTITY_ELEMENT; // Implement this function per the assignment instructions.
}
import { parallelMapReduce } from './mapReduce.js';
describe('map-reduce with the volume monoid', () => {
test('finds the range from no button presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '', 1);
expect([result.minimum, result.maximum]).toEqual([0, 15]);
});
test('finds the range from one down button press with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '', 1);
expect([result.minimum, result.maximum]).toEqual([0, 14]);
});
test('finds the range from one up button press with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '', 1);
expect([result.minimum, result.maximum]).toEqual([1, 15]);
});
test('finds the range from several down button presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([0, 9]);
});
test('finds the range from several up button presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑', 1);
expect([result.minimum, result.maximum]).toEqual([6, 15]);
});
test('finds the range from down presses then more up presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↑↑↑↑↑↑', 1);
expect([result.minimum, result.maximum]).toEqual([6, 15]);
});
test('finds the range from down presses then fewer up presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓↑↑↑', 1);
expect([result.minimum, result.maximum]).toEqual([3, 12]);
});
test('finds the range from up presses then more down presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↓↓↓↓↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([0, 9]);
});
test('finds the range from up presses then fewer down presses with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑↓↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([3, 12]);
});
test('finds the range from an extreme button press sequence with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↓↓↓↓↓↓↓↓↓↓↓↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([2, 2]);
});
test('finds the range from random sequence #0 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↓↓↓↓↓↑↑↓↑↑↑↓', 1);
expect([result.minimum, result.maximum]).toEqual([3, 13]);
});
test('finds the range from random sequence #1 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↑↓↓↓↑↓↑↓↑↑↑↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([1, 11]);
});
test('finds the range from random sequence #2 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↑↓↑↑↓↑↑↓↑↑↑↑', 1);
expect([result.minimum, result.maximum]).toEqual([8, 15]);
});
test('finds the range from random sequence #3 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↓↑↑↓↓↑↓↑↓↓↑↓↑↑', 1);
expect([result.minimum, result.maximum]).toEqual([2, 14]);
});
test('finds the range from random sequence #4 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↑↓↓↓↓↑↓↑↑↑↑↓↑↑↑↓', 1);
expect([result.minimum, result.maximum]).toEqual([5, 14]);
});
test('finds the range from random sequence #5 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↓↑↓↓↑↓↑↑↑↓↓↑', 1);
expect([result.minimum, result.maximum]).toEqual([2, 14]);
});
test('finds the range from random sequence #6 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↓↑↓↑↓↓↑↓↑↓↓↑↑↑↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([1, 13]);
});
test('finds the range from random sequence #7 with one thread', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑↑↓↓↑↑↑↓↓↓↓', 1);
expect([result.minimum, result.maximum]).toEqual([4, 11]);
});
test('finds the range from no button presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '', 2);
expect([result.minimum, result.maximum]).toEqual([0, 15]);
});
test('finds the range from one down button press with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '', 2);
expect([result.minimum, result.maximum]).toEqual([0, 14]);
});
test('finds the range from one up button press with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '', 2);
expect([result.minimum, result.maximum]).toEqual([1, 15]);
});
test('finds the range from several down button presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([0, 9]);
});
test('finds the range from several up button presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑', 2);
expect([result.minimum, result.maximum]).toEqual([6, 15]);
});
test('finds the range from down presses then more up presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↑↑↑↑↑↑', 2);
expect([result.minimum, result.maximum]).toEqual([6, 15]);
});
test('finds the range from down presses then fewer up presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓↑↑↑', 2);
expect([result.minimum, result.maximum]).toEqual([3, 12]);
});
test('finds the range from up presses then more down presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↓↓↓↓↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([0, 9]);
});
test('finds the range from up presses then fewer down presses with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑↓↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([3, 12]);
});
test('finds the range from an extreme button press sequence with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↓↓↓↓↓↓↓↓↓↓↓↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([2, 2]);
});
test('finds the range from random sequence #0 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↓↓↓↓↓↑↑↓↑↑↑↓', 2);
expect([result.minimum, result.maximum]).toEqual([3, 13]);
});
test('finds the range from random sequence #1 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↑↓↓↓↑↓↑↓↑↑↑↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([1, 11]);
});
test('finds the range from random sequence #2 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↑↓↑↑↓↑↑↓↑↑↑↑', 2);
expect([result.minimum, result.maximum]).toEqual([8, 15]);
});
test('finds the range from random sequence #3 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↓↑↑↓↓↑↓↑↓↓↑↓↑↑', 2);
expect([result.minimum, result.maximum]).toEqual([2, 14]);
});
test('finds the range from random sequence #4 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↓↓↓↓↑↓↑↑↑↑↓↑↑↑↓', 2);
expect([result.minimum, result.maximum]).toEqual([5, 14]);
});
test('finds the range from random sequence #5 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↓↑↓↓↑↓↑↑↑↓↓↑', 2);
expect([result.minimum, result.maximum]).toEqual([2, 14]);
});
test('finds the range from random sequence #6 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↑↓↑↓↓↑↓↑↓↓↑↑↑↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([1, 13]);
});
test('finds the range from random sequence #7 with two threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑↑↓↓↑↑↑↓↓↓↓', 2);
expect([result.minimum, result.maximum]).toEqual([4, 11]);
});
test('finds the range from no button presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '', 3);
expect([result.minimum, result.maximum]).toEqual([0, 15]);
});
test('finds the range from one down button press with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '', 3);
expect([result.minimum, result.maximum]).toEqual([0, 14]);
});
test('finds the range from one up button press with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '', 3);
expect([result.minimum, result.maximum]).toEqual([1, 15]);
});
test('finds the range from several down button presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([0, 9]);
});
test('finds the range from several up button presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑', 3);
expect([result.minimum, result.maximum]).toEqual([6, 15]);
});
test('finds the range from down presses then more up presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↑↑↑↑↑↑', 3);
expect([result.minimum, result.maximum]).toEqual([6, 15]);
});
test('finds the range from down presses then fewer up presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓↑↑↑', 3);
expect([result.minimum, result.maximum]).toEqual([3, 12]);
});
test('finds the range from up presses then more down presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↓↓↓↓↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([0, 9]);
});
test('finds the range from up presses then fewer down presses with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑↓↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([3, 12]);
});
test('finds the range from an extreme button press sequence with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↓↓↓↓↓↓↓↓↓↓↓↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([2, 2]);
});
test('finds the range from random sequence #0 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↓↓↓↓↓↑↑↓↑↑↑↓', 3);
expect([result.minimum, result.maximum]).toEqual([3, 13]);
});
test('finds the range from random sequence #1 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↓↑↓↓↓↑↓↑↓↑↑↑↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([1, 11]);
});
test('finds the range from random sequence #2 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↑↓↑↑↓↑↑↓↑↑↑↑', 3);
expect([result.minimum, result.maximum]).toEqual([8, 15]);
});
test('finds the range from random sequence #3 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↓↑↑↓↓↑↓↑↓↓↑↓↑↑', 3);
expect([result.minimum, result.maximum]).toEqual([2, 14]);
});
test('finds the range from random sequence #4 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↓↓↓↓↑↓↑↑↑↑↓↑↑↑↓', 3);
expect([result.minimum, result.maximum]).toEqual([5, 14]);
});
test('finds the range from random sequence #5 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↓↑↑↓↑↓↓↑↓↑↑↑↓↓↑', 3);
expect([result.minimum, result.maximum]).toEqual([2, 14]);
});
test('finds the range from random sequence #6 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↓↑↓↑↓↓↑↓↑↓↓↑↑↑↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([1, 13]);
});
test('finds the range from random sequence #7 with three threads', async() => {
const result = await parallelMapReduce('./volume.js', '↑↑↑↑↑↑↑↓↓↑↑↑↓↓↓↓', 3);
expect([result.minimum, result.maximum]).toEqual([4, 11]);
});
});
import { parentPort } from 'worker_threads';
function iterativeReduce(identityElement, combineMonoidElements, sequence) {
let result = identityElement;
for (const element of sequence) {
result = combineMonoidElements(result, element);
}
return result;
}
parentPort.on('message', async({ proceduresURL, data }) => {
const {
IDENTITY_ELEMENT,
encodeAsMonoidElement,
combineMonoidElements,
} = await import(proceduresURL);
parentPort.postMessage(iterativeReduce(IDENTITY_ELEMENT, combineMonoidElements, data.map(encodeAsMonoidElement)));
});
This diff is collapsed.
{
"name": "@unlcsce/homework-4",
"version": "1.0.0",
"description": "Starter code for Homework 4.",
"private": true,
"license": "UNLICENSED",
"scripts": {
"postinstall:eslint-config": "cd eslint-config && npm install",
"postinstall:app": "cd homework-4 && npm install",
"postinstall": "run-s postinstall:**",
"lint:app": "cd homework-4 && npm run lint",
"lint": "run-s --continue-on-error lint:**",
"test-once:search": "cd homework-4 && npm run test-once:search",
"test-once:texMath": "cd homework-4 && npm run test-once:texMath",
"test-once:volume": "cd homework-4 && npm run test-once:volume",
"test-once:downtime": "cd homework-4 && npm run test-once:downtime",
"test-once:calculator": "cd homework-4 && npm run test-once:calculator",
"test-once": "cd homework-4 && 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"
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment