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

Initial commit.

parents
Branches
No related tags found
No related merge requests found
.eslintrc 0 → 100755
{
"env": {
"es6": true,
"browser": true,
"jquery": true,
},
"rules": {
"no-await-in-loop": "warn",
"no-compare-neg-zero": "warn",
"no-cond-assign": "warn",
"no-console": "off",
"no-constant-condition": "warn",
"no-control-regex": "warn",
"no-debugger": "warn",
"no-dupe-args": "warn",
"no-dupe-keys": "warn",
"no-duplicate-case": "warn",
"no-empty": "warn",
"no-empty-character-class": "warn",
"no-ex-assign": "warn",
"no-extra-boolean-cast": "warn",
"no-extra-parens": ["warn", "all", {
"nestedBinaryExpressions": false,
}],
"no-extra-semi": "warn",
"no-func-assign": "warn",
"no-inner-declarations": "warn",
"no-invalid-regexp": "warn",
"no-irregular-whitespace": "warn",
"no-obj-calls": "warn",
"no-prototype-builtins": "warn",
"no-regex-spaces": "warn",
"no-sparse-arrays": "warn",
"no-template-curly-in-string": "warn",
"no-unexpected-multiline": "warn",
"no-unreachable": "warn",
"no-unsafe-finally": "warn",
"no-unsafe-negation": "warn",
"use-isnan": "warn",
"valid-jsdoc": "warn",
"valid-typeof": "warn",
"accessor-pairs": "warn",
"array-callback-return": "warn",
"block-scoped-var": "warn",
"class-methods-use-this": "warn",
"complexity": "off",
"consistent-return": "warn",
"curly": "warn",
"default-case": "off",
"dot-location": "warn",
"dot-notation": "warn",
"eqeqeq": "warn",
"guard-for-in": "off", // see no-restricted-syntax
"no-alert": "warn",
"no-caller": "warn",
"no-case-declarations": "warn",
"no-div-regex": "warn",
"no-else-return": "warn",
"no-empty-function": "warn",
"no-empty-pattern": "warn",
"no-eq-null": "warn",
"no-eval": "warn",
"no-extend-native": "off",
"no-extra-bind": "warn",
"no-extra-label": "warn",
"no-fallthrough": "warn",
"no-floating-decimal": "warn",
"no-global-assign": "warn",
"no-implicit-coercion": "warn",
"no-implicit-globals": "off",
"no-implied-eval": "warn",
"no-invalid-this": "off",
"no-iterator": "warn",
"no-labels": "off",
"no-lone-blocks": "off",
"no-loop-func": "warn",
"no-magic-numbers": ["warn", {
"ignore": [-1, 0, 0.001, 0.5, 1, 2, 10, 100, 180, 360, 1000],
"detectObjects": true,
}],
"no-multi-spaces": "warn",
"no-multi-str": "warn",
"no-new": "warn",
"no-new-func": "warn",
"no-new-wrappers": "warn",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-param-reassign": "warn",
"no-proto": "warn",
"no-redeclare": "warn",
"no-restricted-properties": "warn",
"no-return-assign": "warn",
"no-return-await": "warn",
"no-script-url": "warn",
"no-self-assign": "warn",
"no-self-compare": "warn",
"no-sequences": "warn",
"no-throw-literal": "warn",
"no-unmodified-loop-condition": "warn",
"no-unused-expressions": "warn",
"no-unused-labels": "warn",
"no-useless-call": "warn",
"no-useless-concat": "warn",
"no-useless-escape": "warn",
"no-useless-return": "warn",
"no-void": "warn",
"no-warning-comments": "warn",
"no-with": "warn",
"prefer-promise-reject-errors": "warn",
"radix": "warn",
"require-await": "warn",
"vars-on-top": "off",
"wrap-iife": "warn",
"yoda": "warn",
"strict": ["warn", "never"],
"init-declarations": "warn",
"no-catch-shadow": "warn",
"no-delete-var": "warn",
"no-label-var": "warn",
"no-restricted-globals": "warn",
"no-shadow": "warn",
"no-shadow-restricted-names": "warn",
"no-undef": "warn",
"no-undef-init": "off",
"no-undefined": "off",
"no-unused-vars": ["warn", {
"varsIgnorePattern": "_+",
}],
"no-use-before-define": "warn",
"array-bracket-spacing": "warn",
"block-spacing": "warn",
"brace-style": "warn",
"camelcase": "warn",
"capitalized-comments": "off",
"comma-dangle": ["warn", "always-multiline"],
"comma-spacing": "warn",
"comma-style": "warn",
"computed-property-spacing": "warn",
"consistent-this": "warn",
"eol-last": "warn",
"func-call-spacing": "warn",
"func-name-matching": "warn",
"func-names": ["warn", "as-needed"],
"func-style": "off",
"id-blacklist": ["warn", "temp"],
"id-length": "off",
"id-match": "off",
"indent": ["warn", 2],
"jsx-quotes": "warn",
"key-spacing": "warn",
"keyword-spacing": "warn",
"line-comment-position": "off",
"linebreak-style": "warn",
"lines-around-comment": "off",
"lines-around-directive": "warn",
"max-depth": "off",
"max-len": "off",
"max-lines": "off",
"max-nested-callbacks": "off",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "warn",
"multiline-ternary": "off",
"new-cap": "warn",
"new-parens": "warn",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-array-constructor": "warn",
"no-bitwise": "off",
"no-continue": "off",
"no-inline-comments": "off",
"no-lonely-if": "warn",
"no-mixed-operators": "off",
"no-mixed-spaces-and-tabs": "warn",
"no-multi-assign": "warn",
"no-multiple-empty-lines": ["warn", {
"maxBOF": 0,
"max": 1,
"maxEOF": 0,
}],
"no-negated-condition": "off",
"no-nested-ternary": "off",
"no-new-object": "warn",
"no-plusplus": "off",
"no-restricted-syntax": ["warn", {
"selector": "ForInStatement",
"message": "for-in loop used (did you mean to write a for-of loop?)",
}, {
"selector": "BinaryExpression[operator='in']",
"message": "in operator used (did you mean to call a membership-testing method?)",
}],
"no-tabs": "warn",
"no-ternary": "off",
"no-trailing-spaces": "warn",
"no-underscore-dangle": ["warn", {
"allowAfterThis": true,
"allowAfterSuper": true,
}],
"no-unneeded-ternary": "warn",
"no-whitespace-before-property": "warn",
"nonblock-statement-body-position": "off", // see curly
"object-curly-newline": "warn",
"object-curly-spacing": "warn",
"object-property-newline": "warn",
"one-var": ["warn", "never"],
"one-var-declaration-per-line": "warn",
"operator-assignment": "warn",
"operator-linebreak": "warn",
"padded-blocks": ["warn", "never"],
"quote-props": ["warn", "as-needed"],
"quotes": ["warn", "single"],
"require-jsdoc": "off",
"semi": "warn",
"semi-spacing": "warn",
"sort-keys": "off",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": ["warn", "never"],
"space-in-parens": "warn",
"space-infix-ops": "warn",
"space-unary-ops": "warn",
"spaced-comment": "warn",
"template-tag-spacing": "off",
"unicode-bom": "warn",
"wrap-regex": "off",
"arrow-body-style": "warn",
"arrow-parens": "warn",
"arrow-spacing": "warn",
"constructor-super": "warn",
"generator-star-spacing": ["warn", "neither"],
"no-class-assign": "warn",
"no-confusing-arrow": "off",
"no-const-assign": "warn",
"no-dupe-class-members": "warn",
"no-duplicate-imports": "warn",
"no-new-symbol": "warn",
"no-restricted-imports": "off",
"no-this-before-super": "warn",
"no-useless-computed-key": "warn",
"no-useless-constructor": "warn",
"no-useless-rename": "warn",
"no-var": "warn",
"object-shorthand": "warn",
"prefer-arrow-callback": "warn",
"prefer-const": "warn",
"prefer-destructuring": "off",
"prefer-numeric-literals": "warn",
"prefer-rest-params": "warn",
"prefer-spread": "warn",
"prefer-template": "warn",
"require-yield": "warn",
"rest-spread-spacing": "warn",
"sort-imports": "off",
"symbol-description": "warn",
"template-curly-spacing": "warn",
"yield-star-spacing": "warn",
},
}
*~
.idea
{
"defaultSeverity": "warning",
"rules": {
"at-rule-empty-line-before": [ "always", {
except: [
"blockless-after-same-name-blockless",
"first-nested",
],
ignore: ["after-comment"],
} ],
"at-rule-name-case": "lower",
"at-rule-name-space-after": "always-single-line",
"at-rule-semicolon-newline-after": "always",
"block-closing-brace-empty-line-before": "never",
"block-closing-brace-newline-after": "always",
"block-closing-brace-newline-before": "always-multi-line",
"block-closing-brace-space-before": "always-single-line",
"block-no-empty": true,
"block-opening-brace-newline-after": "always-multi-line",
"block-opening-brace-space-after": "always-single-line",
"block-opening-brace-space-before": "always",
"color-hex-case": "lower",
"color-hex-length": "short",
"color-no-invalid-hex": true,
"comment-empty-line-before": [ "always", {
except: ["first-nested"],
ignore: ["stylelint-commands"],
} ],
"comment-no-empty": true,
"comment-whitespace-inside": "always",
"custom-property-empty-line-before": [ "always", {
except: [
"after-custom-property",
"first-nested",
],
ignore: [
"after-comment",
"inside-single-line-block",
],
} ],
"declaration-bang-space-after": "never",
"declaration-bang-space-before": "always",
"declaration-block-no-duplicate-properties": [ true, {
ignore: ["consecutive-duplicates-with-different-values"],
} ],
"declaration-block-no-redundant-longhand-properties": true,
"declaration-block-no-shorthand-property-overrides": true,
"declaration-block-semicolon-newline-after": "always-multi-line",
"declaration-block-semicolon-space-after": "always-single-line",
"declaration-block-semicolon-space-before": "never",
"declaration-block-single-line-max-declarations": 1,
"declaration-block-trailing-semicolon": "always",
"declaration-colon-newline-after": "always-multi-line",
"declaration-colon-space-after": "always-single-line",
"declaration-colon-space-before": "never",
"declaration-empty-line-before": [ "always", {
except: [
"after-declaration",
"first-nested",
],
ignore: [
"after-comment",
"inside-single-line-block",
],
} ],
"font-family-no-duplicate-names": true,
"function-calc-no-unspaced-operator": true,
"function-comma-newline-after": "always-multi-line",
"function-comma-space-after": "always-single-line",
"function-comma-space-before": "never",
"function-linear-gradient-no-nonstandard-direction": true,
"function-max-empty-lines": 0,
"function-name-case": "lower",
"function-parentheses-newline-inside": "always-multi-line",
"function-parentheses-space-inside": "never-single-line",
"function-whitespace-after": "always",
"indentation": 2,
"keyframe-declaration-no-important": true,
"length-zero-no-unit": true,
"max-empty-lines": 1,
"media-feature-colon-space-after": "always",
"media-feature-colon-space-before": "never",
"media-feature-name-case": "lower",
"media-feature-name-no-unknown": true,
"media-feature-parentheses-space-inside": "never",
"media-feature-range-operator-space-after": "always",
"media-feature-range-operator-space-before": "always",
"media-query-list-comma-newline-after": "always-multi-line",
"media-query-list-comma-space-after": "always-single-line",
"media-query-list-comma-space-before": "never",
"no-empty-source": true,
"no-eol-whitespace": true,
"no-extra-semicolons": true,
"no-invalid-double-slash-comments": true,
"no-missing-end-of-source-newline": true,
"number-leading-zero": "always",
"property-case": "lower",
"property-no-unknown": true,
"rule-empty-line-before": [ "always-multi-line", {
except: ["first-nested"],
ignore: ["after-comment"],
} ],
"selector-attribute-brackets-space-inside": "never",
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
"selector-combinator-space-after": "always",
"selector-combinator-space-before": "always",
"selector-descendant-combinator-no-non-space": true,
"selector-list-comma-newline-after": "always",
"selector-list-comma-space-before": "never",
"selector-max-empty-lines": 0,
"selector-pseudo-class-case": "lower",
"selector-pseudo-class-no-unknown": true,
"selector-pseudo-class-parentheses-space-inside": "never",
"selector-pseudo-element-case": "lower",
"selector-pseudo-element-colon-notation": "double",
"selector-pseudo-element-no-unknown": true,
"selector-type-case": "lower",
"selector-type-no-unknown": true,
"shorthand-property-no-redundant-values": true,
"string-no-newline": true,
"unit-case": "lower",
"unit-no-unknown": true,
"value-list-comma-newline-after": "always-multi-line",
"value-list-comma-space-after": "always-single-line",
"value-list-comma-space-before": "never",
"value-list-max-empty-lines": 0,
},
}
{
"ecmaVersion": 6,
"libs": [
"browser",
"jquery"
],
"loadEagerly": [],
"dontLoad": [
"node_module/**"
],
"plugins": {
"doc_comment": true,
"complete_strings": {
"maxLength": 15
}
}
}
\ No newline at end of file
/* exported Path computeAllPairsShortestPaths */
class Path {
constructor(vertices, weight) {
console.assert(vertices.length > 0, 'Tried to construct a path with no vertices.');
console.assert(vertices.length > 1 || weight === 0, `Tried to construct a trivial path at ${vertices[0]} with nontrivial weight ${weight}.`);
this.vertices = vertices;
this.weight = weight;
}
concat(other) {
console.assert(this.vertices[this.vertices.length - 1] === other.vertices[0], `Tried to concatenate the incompatible paths ${this} and ${other}.`);
const result = new Path([undefined], 0);
result.vertices = this.vertices.concat(other.vertices.slice(1));
result.weight = this.weight + other.weight;
return result;
}
toString() {
return `${this.vertices} (weight ${this.weight})`;
}
}
function createTrivialMatrix(size) {
const result = [];
for (let source = 0; source < size; ++source) {
const row = [];
for (let destination = 0; destination < size; ++destination) {
row.push(source === destination ? 0 : Infinity);
}
result.push(row);
}
return result;
}
function computeAllPairsShortestPaths(graph) {
console.log(`Computing all shortest paths for ${graph}.`);
let result = createTrivialMatrix(graph.size);
for (const edge of graph.edges) {
result[edge.source][edge.destination] = edge.weight;
}
for (let intermediate = 0; intermediate < graph.size; ++intermediate) {
const nextResult = createTrivialMatrix(graph.size);
for (let source = 0; source < graph.size; ++source) {
for (let destination = 0; destination < graph.size; ++destination) {
nextResult[source][destination] = Math.min(result[source][destination], result[source][intermediate] + result[intermediate][destination]);
}
}
result = nextResult;
}
return result;
}
/* exported nCr */
function nCr(pool, chosen) {
if (chosen < 0 || chosen > pool) {
return 0;
}
let row = [1];
console.log(row);
for (let i = 0; i < pool; ++i) {
const newRow = [];
// TODO
row = newRow;
console.log(row);
}
return row[chosen];
}
/*!
* QUnit 2.3.2
* https://qunitjs.com/
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2017-04-18T02:19Z
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
/** Header (excluding toolbar) */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699A4;
background-color: #0D3349;
font-size: 1.5em;
line-height: 1em;
font-weight: 400;
border-radius: 5px 5px 0 0;
}
#qunit-header a {
text-decoration: none;
color: #C2CCD1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #FFF;
}
#qunit-banner {
height: 5px;
}
#qunit-filteredTest {
padding: 0.5em 1em 0.5em 1em;
color: #366097;
background-color: #F4FF77;
}
#qunit-userAgent {
padding: 0.5em 1em 0.5em 1em;
color: #FFF;
background-color: #2B81AF;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
/** Toolbar */
#qunit-testrunner-toolbar {
padding: 0.5em 1em 0.5em 1em;
color: #5E740B;
background-color: #EEE;
}
#qunit-testrunner-toolbar .clearfix {
height: 0;
clear: both;
}
#qunit-testrunner-toolbar label {
display: inline-block;
}
#qunit-testrunner-toolbar input[type=checkbox],
#qunit-testrunner-toolbar input[type=radio] {
margin: 3px;
vertical-align: -2px;
}
#qunit-testrunner-toolbar input[type=text] {
box-sizing: border-box;
height: 1.6em;
}
.qunit-url-config,
.qunit-filter,
#qunit-modulefilter {
display: inline-block;
line-height: 2.1em;
}
.qunit-filter,
#qunit-modulefilter {
float: right;
position: relative;
margin-left: 1em;
}
.qunit-url-config label {
margin-right: 0.5em;
}
#qunit-modulefilter-search {
box-sizing: border-box;
width: 400px;
}
#qunit-modulefilter-search-container:after {
position: absolute;
right: 0.3em;
content: "\25bc";
color: black;
}
#qunit-modulefilter-dropdown {
/* align with #qunit-modulefilter-search */
box-sizing: border-box;
width: 400px;
position: absolute;
right: 0;
top: 50%;
margin-top: 0.8em;
border: 1px solid #D3D3D3;
border-top: none;
border-radius: 0 0 .25em .25em;
color: #000;
background-color: #F5F5F5;
z-index: 99;
}
#qunit-modulefilter-dropdown a {
color: inherit;
text-decoration: none;
}
#qunit-modulefilter-dropdown .clickable.checked {
font-weight: bold;
color: #000;
background-color: #D2E0E6;
}
#qunit-modulefilter-dropdown .clickable:hover {
color: #FFF;
background-color: #0D3349;
}
#qunit-modulefilter-actions {
display: block;
overflow: auto;
/* align with #qunit-modulefilter-dropdown-list */
font: smaller/1.5em sans-serif;
}
#qunit-modulefilter-dropdown #qunit-modulefilter-actions > * {
box-sizing: border-box;
max-height: 2.8em;
display: block;
padding: 0.4em;
}
#qunit-modulefilter-dropdown #qunit-modulefilter-actions > button {
float: right;
font: inherit;
}
#qunit-modulefilter-dropdown #qunit-modulefilter-actions > :last-child {
/* insert padding to align with checkbox margins */
padding-left: 3px;
}
#qunit-modulefilter-dropdown-list {
max-height: 200px;
overflow-y: auto;
margin: 0;
border-top: 2px groove threedhighlight;
padding: 0.4em 0 0;
font: smaller/1.5em sans-serif;
}
#qunit-modulefilter-dropdown-list li {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#qunit-modulefilter-dropdown-list .clickable {
display: block;
padding-left: 0.15em;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 1em 0.4em 1em;
border-bottom: 1px solid #FFF;
list-style-position: inside;
}
#qunit-tests > li {
display: none;
}
#qunit-tests li.running,
#qunit-tests li.pass,
#qunit-tests li.fail,
#qunit-tests li.skipped,
#qunit-tests li.aborted {
display: list-item;
}
#qunit-tests.hidepass {
position: relative;
}
#qunit-tests.hidepass li.running,
#qunit-tests.hidepass li.pass:not(.todo) {
visibility: hidden;
position: absolute;
width: 0;
height: 0;
padding: 0;
border: 0;
margin: 0;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li.skipped strong {
cursor: default;
}
#qunit-tests li a {
padding: 0.5em;
color: #C2CCD1;
text-decoration: none;
}
#qunit-tests li p a {
padding: 0.25em;
color: #6B6464;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests li .runtime {
float: right;
font-size: smaller;
}
.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;
background-color: #FFF;
border-radius: 5px;
}
.qunit-source {
margin: 0.6em 0 0.3em;
}
.qunit-collapsed {
display: none;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: 0.2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 0.5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
color: #374E0C;
background-color: #E0F2BE;
text-decoration: none;
}
#qunit-tests ins {
color: #500;
background-color: #FFCACA;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: #000; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
padding: 5px;
background-color: #FFF;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #3C510C;
background-color: #FFF;
border-left: 10px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #FFF;
border-left: 10px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
}
#qunit-tests .fail { color: #000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: #008000; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/*** Aborted tests */
#qunit-tests .aborted { color: #000; background-color: orange; }
/*** Skipped tests */
#qunit-tests .skipped {
background-color: #EBECE9;
}
#qunit-tests .qunit-todo-label,
#qunit-tests .qunit-skipped-label {
background-color: #F4FF77;
display: inline-block;
font-style: normal;
color: #366097;
line-height: 1.8em;
padding: 0 0.5em;
margin: -0.4em 0.4em -0.4em 0;
}
#qunit-tests .qunit-todo-label {
background-color: #EEE;
}
/** Result */
#qunit-testresult {
color: #2B81AF;
background-color: #D2E0E6;
border-bottom: 1px solid #FFF;
}
#qunit-testresult .clearfix {
height: 0;
clear: both;
}
#qunit-testresult .module-name {
font-weight: 700;
}
#qunit-testresult-display {
padding: 0.5em 1em 0.5em 1em;
width: 85%;
float:left;
}
#qunit-testresult-controls {
padding: 0.5em 1em 0.5em 1em;
width: 10%;
float:left;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}
This diff is collapsed.
class AssertionError extends Error {}
const builtinAssert = console.assert;
console.assert = function assert(assertion, text = 'Assertion Error') {
builtinAssert(assertion, text);
if (!assertion) {
throw new AssertionError(text);
}
};
QUnit.module('all_pairs_shortest_paths');
/* globals QUnit Path computeAllPairsShortestPaths */
/* eslint-disable no-magic-numbers */
class Edge {
constructor(source, weight, destination) {
this.source = source;
this.weight = weight;
this.destination = destination;
}
toString() {
return `${this.source}${this.destination} (weight ${this.weight})`;
}
}
class ScrambleGraph {
constructor(size, parameters) {
this.size = size;
this.edges = new Set();
for (let source = 0; source < size; ++source) {
const destinations = new Set();
for (const parameter of parameters) {
const a = (source + parameter) % size;
const b = a > 0 ? (size + parameter) % a : size - 1;
const destination = (b + parameter) % size;
if (destination !== source && !destinations.has(destination)) {
const weight = b > 0 ? (size + parameter) % b : size - 1;
this.edges.add(new Edge(source, weight, destination));
destinations.add(destination);
}
}
}
}
toString() {
let result = '';
for (const edge of this.edges) {
if (result.length > 0) {
result += ', ';
}
result += `${edge}`;
}
return `{ ${result} }`;
}
}
QUnit.test('Check shortest paths for ScrambleGraph(1, [])', (assert) => {
const graph = new ScrambleGraph(1, []);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(2, [0])', (assert) => {
const graph = new ScrambleGraph(2, [0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 0)], [new Path([1, 0], 1), new Path([1], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(2, [0, 1])', (assert) => {
const graph = new ScrambleGraph(2, [0, 1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 0)], [new Path([1, 0], 1), new Path([1], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(2, [1, 0])', (assert) => {
const graph = new ScrambleGraph(2, [1, 0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 1)], [new Path([1, 0], 0), new Path([1], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(2, [1])', (assert) => {
const graph = new ScrambleGraph(2, [1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 1)], [new Path([1, 0], 0), new Path([1], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [0])', (assert) => {
const graph = new ScrambleGraph(3, [0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 1), new Path([0, 2], 1)], [new Path([1, 0], 2), new Path([1], 0), new Path([1, 0, 2], 3)], [new Path([2, 1, 0], 2), new Path([2, 1], 0), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [0, 1])', (assert) => {
const graph = new ScrambleGraph(3, [0, 1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 1), new Path([0, 2], 1)], [new Path([1, 0], 2), new Path([1], 0), new Path([1, 0, 2], 3)], [new Path([2, 0], 0), new Path([2, 1], 0), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [0, 2])', (assert) => {
const graph = new ScrambleGraph(3, [0, 2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 1), new Path([0, 2], 1)], [new Path([1, 0], 2), new Path([1], 0), new Path([1, 0, 2], 3)], [new Path([2, 1, 0], 2), new Path([2, 1], 0), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [1, 0])', (assert) => {
const graph = new ScrambleGraph(3, [1, 0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 1), new Path([0, 2], 1)], [new Path([1, 0], 2), new Path([1], 0), new Path([1, 0, 2], 3)], [new Path([2, 0], 0), new Path([2, 1], 0), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [1])', (assert) => {
const graph = new ScrambleGraph(3, [1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 2), new Path([0, 2], Infinity)], [new Path([1, 0], Infinity), new Path([1], 0), new Path([1, 2], Infinity)], [new Path([2, 0], 0), new Path([2, 0, 1], 2), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [1, 2])', (assert) => {
const graph = new ScrambleGraph(3, [1, 2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 2), new Path([0, 2], Infinity)], [new Path([1, 0], Infinity), new Path([1], 0), new Path([1, 2], Infinity)], [new Path([2, 0], 0), new Path([2, 0, 1], 2), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [2, 0])', (assert) => {
const graph = new ScrambleGraph(3, [2, 0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 1), new Path([0, 2], 1)], [new Path([1, 0], 2), new Path([1], 0), new Path([1, 0, 2], 3)], [new Path([2, 1, 0], 2), new Path([2, 1], 0), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [2, 1])', (assert) => {
const graph = new ScrambleGraph(3, [2, 1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 2), new Path([0, 2], Infinity)], [new Path([1, 0], Infinity), new Path([1], 0), new Path([1, 2], Infinity)], [new Path([2, 0], 0), new Path([2, 0, 1], 2), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(3, [2])', (assert) => {
const graph = new ScrambleGraph(3, [2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], Infinity), new Path([0, 2], Infinity)], [new Path([1, 0], Infinity), new Path([1], 0), new Path([1, 2], Infinity)], [new Path([2, 0], Infinity), new Path([2, 1], Infinity), new Path([2], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [0])', (assert) => {
const graph = new ScrambleGraph(4, [0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 2], Infinity), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], Infinity), new Path([1, 0, 3], 4)], [new Path([2, 0], 3), new Path([2, 0, 3, 1], 4), new Path([2], 0), new Path([2, 0, 3], 4)], [new Path([3, 1, 0], 3), new Path([3, 1], 0), new Path([3, 2], Infinity), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [0, 1])', (assert) => {
const graph = new ScrambleGraph(4, [0, 1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 3, 1, 2], 1), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], 0), new Path([1, 2, 3], 1)], [new Path([2, 0], 3), new Path([2, 3, 1], 1), new Path([2], 0), new Path([2, 3], 1)], [new Path([3, 0], 2), new Path([3, 1], 0), new Path([3, 1, 2], 0), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [0, 2])', (assert) => {
const graph = new ScrambleGraph(4, [0, 2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 2], 3), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], 3), new Path([1, 0, 3], 4)], [new Path([2, 0], 3), new Path([2, 1], 0), new Path([2], 0), new Path([2, 0, 3], 4)], [new Path([3, 1, 0], 3), new Path([3, 1], 0), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [0, 3])', (assert) => {
const graph = new ScrambleGraph(4, [0, 3]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 3, 1, 2], 2), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], 1), new Path([1, 0, 3], 4)], [new Path([2, 0], 3), new Path([2, 3, 1], 3), new Path([2], 0), new Path([2, 3], 3)], [new Path([3, 0], 0), new Path([3, 1], 0), new Path([3, 1, 2], 1), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [1, 0])', (assert) => {
const graph = new ScrambleGraph(4, [1, 0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 3, 1, 2], 1), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], 0), new Path([1, 2, 3], 1)], [new Path([2, 0], 3), new Path([2, 3, 1], 1), new Path([2], 0), new Path([2, 3], 1)], [new Path([3, 0], 2), new Path([3, 1], 0), new Path([3, 1, 2], 0), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [1])', (assert) => {
const graph = new ScrambleGraph(4, [1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 3), new Path([0, 1, 2], 3), new Path([0, 1, 2, 3], 4)], [new Path([1, 2, 3, 0], 3), new Path([1], 0), new Path([1, 2], 0), new Path([1, 2, 3], 1)], [new Path([2, 3, 0], 3), new Path([2, 3, 0, 1], 6), new Path([2], 0), new Path([2, 3], 1)], [new Path([3, 0], 2), new Path([3, 0, 1], 5), new Path([3, 0, 1, 2], 5), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [1, 2])', (assert) => {
const graph = new ScrambleGraph(4, [1, 2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 3), new Path([0, 2], 3), new Path([0, 2, 3], 4)], [new Path([1, 2, 3, 0], 3), new Path([1], 0), new Path([1, 2], 0), new Path([1, 2, 3], 1)], [new Path([2, 3, 0], 3), new Path([2, 1], 0), new Path([2], 0), new Path([2, 3], 1)], [new Path([3, 0], 2), new Path([3, 2, 1], 3), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [1, 3])', (assert) => {
const graph = new ScrambleGraph(4, [1, 3]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 3), new Path([0, 1, 2], 3), new Path([0, 1, 2, 3], 4)], [new Path([1, 2, 3, 0], 3), new Path([1], 0), new Path([1, 2], 0), new Path([1, 2, 3], 1)], [new Path([2, 3, 0], 3), new Path([2, 3, 0, 1], 6), new Path([2], 0), new Path([2, 3], 1)], [new Path([3, 0], 2), new Path([3, 0, 1], 5), new Path([3, 0, 1, 2], 5), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [2, 0])', (assert) => {
const graph = new ScrambleGraph(4, [2, 0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 2], 3), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], 3), new Path([1, 0, 3], 4)], [new Path([2, 0], 3), new Path([2, 1], 0), new Path([2], 0), new Path([2, 0, 3], 4)], [new Path([3, 1, 0], 3), new Path([3, 1], 0), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [2, 1])', (assert) => {
const graph = new ScrambleGraph(4, [2, 1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 3), new Path([0, 2], 3), new Path([0, 2, 3], 4)], [new Path([1, 2, 3, 0], 6), new Path([1], 0), new Path([1, 2], 3), new Path([1, 2, 3], 4)], [new Path([2, 3, 0], 3), new Path([2, 1], 0), new Path([2], 0), new Path([2, 3], 1)], [new Path([3, 0], 2), new Path([3, 2, 1], 3), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [2])', (assert) => {
const graph = new ScrambleGraph(4, [2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 3), new Path([0, 2], 3), new Path([0, 3], Infinity)], [new Path([1, 0], Infinity), new Path([1], 0), new Path([1, 2], 3), new Path([1, 3], Infinity)], [new Path([2, 0], Infinity), new Path([2, 1], 0), new Path([2], 0), new Path([2, 3], Infinity)], [new Path([3, 0], Infinity), new Path([3, 2, 1], 3), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [2, 3])', (assert) => {
const graph = new ScrambleGraph(4, [2, 3]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 3), new Path([0, 2], 3), new Path([0, 2, 3], 6)], [new Path([1, 2, 3, 0], 6), new Path([1], 0), new Path([1, 2], 3), new Path([1, 2, 3], 6)], [new Path([2, 3, 0], 3), new Path([2, 1], 0), new Path([2], 0), new Path([2, 3], 3)], [new Path([3, 0], 0), new Path([3, 2, 1], 3), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [3, 0])', (assert) => {
const graph = new ScrambleGraph(4, [3, 0]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 3, 1], 1), new Path([0, 3, 1, 2], 2), new Path([0, 3], 1)], [new Path([1, 0], 3), new Path([1], 0), new Path([1, 2], 1), new Path([1, 0, 3], 4)], [new Path([2, 0], 3), new Path([2, 3, 1], 3), new Path([2], 0), new Path([2, 3], 3)], [new Path([3, 0], 0), new Path([3, 1], 0), new Path([3, 1, 2], 1), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [3, 1])', (assert) => {
const graph = new ScrambleGraph(4, [3, 1]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], 3), new Path([0, 1, 2], 4), new Path([0, 1, 2, 3], 7)], [new Path([1, 2, 3, 0], 4), new Path([1], 0), new Path([1, 2], 1), new Path([1, 2, 3], 4)], [new Path([2, 3, 0], 3), new Path([2, 3, 0, 1], 6), new Path([2], 0), new Path([2, 3], 3)], [new Path([3, 0], 0), new Path([3, 0, 1], 3), new Path([3, 0, 1, 2], 4), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [3, 2])', (assert) => {
const graph = new ScrambleGraph(4, [3, 2]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 2, 1], 3), new Path([0, 2], 3), new Path([0, 2, 3], 6)], [new Path([1, 2, 3, 0], 4), new Path([1], 0), new Path([1, 2], 1), new Path([1, 2, 3], 4)], [new Path([2, 3, 0], 3), new Path([2, 1], 0), new Path([2], 0), new Path([2, 3], 3)], [new Path([3, 0], 0), new Path([3, 2, 1], 3), new Path([3, 2], 3), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
QUnit.test('Check shortest paths for ScrambleGraph(4, [3])', (assert) => {
const graph = new ScrambleGraph(4, [3]);
const paths = computeAllPairsShortestPaths(graph);
const expected = [[new Path([0], 0), new Path([0, 1], Infinity), new Path([0, 2], Infinity), new Path([0, 3], Infinity)], [new Path([1, 2, 3, 0], 4), new Path([1], 0), new Path([1, 2], 1), new Path([1, 2, 3], 4)], [new Path([2, 3, 0], 3), new Path([2, 1], Infinity), new Path([2], 0), new Path([2, 3], 3)], [new Path([3, 0], 0), new Path([3, 1], Infinity), new Path([3, 2], Infinity), new Path([3], 0)]];
assert.deepEqual(paths, expected);
});
This diff is collapsed.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="../libraries/qunit/qunit.css">
<title>Unit Tests: Dynamic Programming</title>
</head>
<body>
<div id="qunit"></div>
<script src="../libraries/qunit/qunit.js"></script>
<script src="overrides.js"></script>
<script src="../js/pascals_triangle.js"></script>
<script src="test_pascals_triangle.js"></script>
<script src="../js/all_pairs_shortest_paths.js"></script>
<script src="test_all_pairs_shortest_paths.js"></script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment