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

Initial commit.

parents
Branches
Tags
No related merge requests found
Showing
with 324 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 4
Starter code for Homework 4 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/2023-fall-homework-4.git
$ cd 2023-fall-homework-4
```
(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/158348/assignments/1576251>.
Subproject commit 16524f5ac58d4b13378261f1ab29bc1acc2a2099
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.eol": "\n",
"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/homework-4",
"version": "1.0.0",
"description": "Starter code for Homework 4.",
"type": "module",
"private": true,
"license": "UNLICENSED",
"scripts": {
"lint:js": "eslint --max-warnings 0 ./src",
"lint": "run-s --continue-on-error lint:**",
"test-once:sum": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the addition monoid\"",
"test-once:file": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the file-method monoid\"",
"test-once:simpleXML": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the simple-XML monoid\"",
"test-once:robot": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the robot-joint monoid\"",
"test-once:signal": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the periodic-signal monoid\"",
"test-once:minimaGap": "node --experimental-vm-modules node_modules/jest/bin/jest.js -t \"the narrowest-gap-between-minima monoid\"",
"test-once": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watchAll"
},
"dependencies": {
"npm-run-all": "^4.1.5"
},
"devDependencies": {
"@unlcsce/eslint-config": "file:../eslint-config",
"eslint": "^8.20.0",
"jest": "^29.5.0",
"jest-environment-node": "^29.5.0"
},
"eslintConfig": {
"extends": "@unlcsce"
},
"jest": {
"clearMocks": true,
"resetMocks": false,
"restoreMocks": false,
"setupFilesAfterEnv": [
"./src/setupTests.js"
],
"testEnvironment": "./src/testing/failFast.js",
"transform": {}
},
"//": [
"See https://github.com/facebook/jest/issues/9430 for information on Jest+ES6."
]
}
/* IMPORTANT: Remove this directive 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(method) {
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.
}
Source diff could not be displayed: it is too large. Options to address this: view the blob.
import { Worker } from 'worker_threads';
class ModuleWorker extends Worker {
constructor(path) {
const code = `import '${new URL(path, import.meta.url).href}';`;
super(new URL(`data:text/javascript,${encodeURIComponent(code)}`));
}
dispatch(data) {
this.postMessage(data);
return new Promise((resolve) => this.once('message', resolve));
}
}
function iterativeReduce(identityElement, combineMonoidElements, sequence) {
let result = identityElement;
for (const element of sequence) {
result = combineMonoidElements(result, element);
}
return result;
}
export async function parallelMapReduce(proceduresURL, sequence, workerCount) {
console.assert(workerCount > 0, `Cannot distribute work to a nonpositive (${workerCount}) number of threads.`);
const {
IDENTITY_ELEMENT,
combineMonoidElements,
} = await import(proceduresURL);
const workers = [...Array(workerCount)].map(() => new ModuleWorker('./worker.js'));
const jobs = workers.map((worker, workerIndex) => {
const low = Math.floor(workerIndex * sequence.length / workerCount);
const high = Math.floor((workerIndex + 1) * sequence.length / workerCount);
return worker.dispatch({
proceduresURL,
data: [...sequence.slice(low, high)],
});
});
const threadResults = (await Promise.all(jobs)).map(
(element) => Object.assign(Object.create(Object.getPrototypeOf(IDENTITY_ELEMENT)), element),
);
for (const worker of workers) {
worker.terminate();
}
return iterativeReduce(IDENTITY_ELEMENT, combineMonoidElements, threadResults);
}
class MonoidElement {
constructor() {
this.gap = Infinity; // Implement this constructor per the assignment instructions.
}
}
export const IDENTITY_ELEMENT = new MonoidElement(); // Define this object per the assignment instructions.
export function encodeAsMonoidElement(number) {
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.
}
This diff is collapsed.
/* 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-unused-vars */
/* eslint-disable no-useless-constructor */
const FULL_ROTATION = 360; // degrees
class MonoidElement {
constructor() {
// Implement this constructor per the assignment instructions.
}
isSafe(startingAngle, safetyMargin) {
return true; // Implement this method per the assignment instructions.
}
}
export const IDENTITY_ELEMENT = new MonoidElement(); // Define this object per the assignment instructions.
export function encodeAsMonoidElement(changeInAngle) {
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.
}
This diff is collapsed.
// Extra imports for working around a V8 bug; see below.
import { SourceTextModule } from 'vm';
import { fileURLToPath } from 'url';
import { resolve, dirname } from 'path';
import { readFileSync } from 'fs';
import { jest } from '@jest/globals';
// This is included for consistency with `create-react-app`. It may be become
// unnecessary in future versions of Jest (see
// https://github.com/facebook/jest/issues/9430#issuecomment-616232029), but
// Jest may also choose to move away from magic globals and use imports instead,
// which are already opt-in (see https://github.com/facebook/jest/issues/4473).
globalThis.jest = jest;
// Work around <https://bugs.chromium.org/p/chromium/issues/detail?id=1244145>,
// a rather nasty bug in V8 where source code dynamically imported with
// host-defined options (see, e.g., the `options` parameter to
// <https://nodejs.org/api/vm.html#class-vmsourcetextmodule>) will be cached
// with only its source text as key so that later imports with different options
// are incorrectly treated as cache hits.
//
// Since Jest uses different options (see, e.g., `loadEsmModule` in
// `…/node_modules/jest-runtime/build/index.js`) for each test file, that means
// that while processing any test file after the first, `mapReduce.js` is still
// associated with an old test environment, and any attempts by it to
// dynamically import a monoid go through an environment that has been torn
// down. They therefore fail.
//
// Since `mapReduce.js` is unmocked and code under test, we don't need any of
// Jest's special import handling (e.g., support for mocking) in it or any of
// its imports, so here we preload `mapReduce.js` into V8's cache without any
// host-defined options. There are still false cache hits, but at least none of
// the cache entries are associated with a test environment.
//
// eslint-disable-next-line no-new
new SourceTextModule(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), 'mapReduce.js'), 'utf8'));
export const UNKNOWN = 'UNKNOWN';
export const INCONSISTENT = 'INCONSISTENT';
class MonoidElement {
constructor() {
this.period = UNKNOWN; // Implement this constructor per the assignment instructions.
}
}
export const IDENTITY_ELEMENT = new MonoidElement(); // Define this object per the assignment instructions.
export function encodeAsMonoidElement(signal) {
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.
}
This diff is collapsed.
/* IMPORTANT: Remove this directive 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 true; // 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.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment