Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lab-dalton/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
39 changes: 39 additions & 0 deletions lab-dalton/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true,
"__API_URI__": false,
"__TITLE__": false,
"__DEBUG__": false
},
"extends": ["eslint:recommended", "plugin:react/recommended"],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"module": true,
"jsx": true
}
},
"rules": {
"no-console": "off",
"no-unused-vars": "off",
"indent": [ "error", 2, { "SwitchCase": 1 } ],
"react/prop-types": [0],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"space-infix-ops": ["error", {"int32Hint": false}],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
},
"plugins": ["react"]
}
115 changes: 115 additions & 0 deletions lab-dalton/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Created by https://www.gitignore.io/api/node,macos,visualstudiocode

db
build

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### VisualStudioCode ###
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

# End of https://www.gitignore.io/api/node,macos,visualstudiocode
© 2017 GitHub, Inc.
Terms
Privacy
Security
Status
Help
Contact GitHub
API
Training
Shop
Blog
About
File renamed without changes.
54 changes: 54 additions & 0 deletions lab-dalton/__test__/heap-sort.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const heapSort = require('../src/heap-sort');
const testFunction = require('./test-function');

describe('testing heap-sort.js', () => {

describe('testing that heapSort is functioning properly', () => {
test('testing that heapSort returns a sorted array', () => {
let arrayToSort = [5,7,1,3,4,9,8,2,6];
expect(heapSort(arrayToSort)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
});

test('testing that heapSort returns a sorted array even when there are duplicate values in the array', () => {
let arrayToSort = [8, 7, 1, 5, 5, 7, 4, 9, 2, 3, 6];
expect(heapSort(arrayToSort)).toEqual([1, 2, 3, 4, 5, 5, 6, 7, 7, 8, 9]);
});

test('testing that heapSort will return an array with one value if one value is passed in', () => {
let arrayToSort = [8];
expect(heapSort(arrayToSort)).toEqual([8]);
});

test('testing that heapSort will return an empty array if the array is empty', () => {
let arrayToSort = [];
expect(heapSort(arrayToSort)).toEqual([]);
});

test('testing that heapSort will return the correct order with multi-digit integers', () => {
let arrayToSort = [8, 1, 25, 7, 11, 9, 2, 3, 6, 10];
expect(heapSort(arrayToSort)).toEqual([1, 2, 3, 6, 7, 8, 9, 10, 11, 25]);
});
});

describe('testing random arrays', () => {
test('testing that small array will be sorted', () => {
let arrayToSort = testFunction.generateRandomArray(8, 3);
let arrayToValidate = testFunction.validateArray(heapSort(arrayToSort));
expect(arrayToValidate).toEqual(true);
});

test('testing that medium array will be sorted', () => {
let arrayToSort = testFunction.generateRandomArray(100, 100);
let arrayToValidate = testFunction.validateArray(heapSort(arrayToSort));
expect(arrayToValidate).toEqual(true);
});

test('testing that large array will be sorted', () => {
let arrayToSort = testFunction.generateRandomArray(10000, 10000);
let arrayToValidate = testFunction.validateArray(heapSort(arrayToSort));
expect(arrayToValidate).toEqual(true);
});
});
});
38 changes: 38 additions & 0 deletions lab-dalton/__test__/max-heap.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const MaxHeap = require('../src/max-heap');

describe('max-heap.js', () => {
test('insert method should throw an error if value is not a number', () => {
const testMaxHeap = new MaxHeap();
expect(() => {
testMaxHeap.insert('invalidValue');
}).toThrow();
});

test('testing that insert method is functioning properly and that peek returns max value', () => {
const testMaxHeap = new MaxHeap();

testMaxHeap.insert(6);
expect(testMaxHeap.peek()).toEqual(6);
testMaxHeap.insert(10);
expect(testMaxHeap.peek()).toEqual(10);
testMaxHeap.insert(15);
expect(testMaxHeap.peek()).toEqual(15);
});

test('testing that extractMaximum method is functioning properly', () => {
const testMaxHeap = new MaxHeap();

testMaxHeap.insert(10);
testMaxHeap.insert(7);
testMaxHeap.insert(8);
testMaxHeap.insert(5);
testMaxHeap.insert(9);
expect(testMaxHeap.extractMaximum()).toEqual(10);
expect(testMaxHeap.extractMaximum()).toEqual(9);
expect(testMaxHeap.extractMaximum()).toEqual(8);
expect(testMaxHeap.extractMaximum()).toEqual(7);
expect(testMaxHeap.extractMaximum()).toEqual(5);
});
});
54 changes: 54 additions & 0 deletions lab-dalton/__test__/merge-sort.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const mergeSort = require('../src/merge-sort');
const testFunction = require('./test-function');

describe('testing merge-sort.js', () => {

describe('testing that mergeSort is functioning properly', () => {
test('testing that mergeSort returns a sorted array', () => {
let arrayToSort = [8, 1, 5, 7, 4, 9, 2, 3, 6];
expect(mergeSort(arrayToSort)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]);
});

test('testing that mergeSort returns a sorted array even when there are duplicate values in the array', () => {
let arrayToSort = [8, 8, 1, 5, 5, 7, 4, 9, 2, 3, 6];
expect(mergeSort(arrayToSort)).toEqual([1, 2, 3, 4, 5, 5, 6, 7, 8, 8, 9]);
});

test('testing that mergeSort will return an array with one value if one value is passed in', () => {
let arrayToSort = [8];
expect(mergeSort(arrayToSort)).toEqual([8]);
});

test('testing that mergeSort will return an empty array if the array is empty', () => {
let arrayToSort = [];
expect(mergeSort(arrayToSort)).toEqual([]);
});

test('testing that mergeSort will return the correct order with multi-digit integers', () => {
let arrayToSort = [20, 1, 25, 7, 11, 9, 2, 3, 6, 10];
expect(mergeSort(arrayToSort)).toEqual([1, 2, 3, 6, 7, 9, 10, 11, 20, 25]);
});
});

describe('testing random arrays', () => {
test('testing that small array will be sorted', () => {
let arrayToSort = testFunction.generateRandomArray(8, 3);
let arrayToValidate = testFunction.validateArray(mergeSort(arrayToSort));
expect(arrayToValidate).toEqual(true);
});

test('testing that medium array will be sorted', () => {
let arrayToSort = testFunction.generateRandomArray(100, 100);
let arrayToValidate = testFunction.validateArray(mergeSort(arrayToSort));
expect(arrayToValidate).toEqual(true);
});

test('testing that large array will be sorted', () => {
let arrayToSort = testFunction.generateRandomArray(10000, 10000);
let arrayToValidate = testFunction.validateArray(mergeSort(arrayToSort));
expect(arrayToValidate).toEqual(true);
});
});
});
15 changes: 15 additions & 0 deletions lab-dalton/__test__/test-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const testFunction = module.exports = {};

testFunction.generateRandomArray = (length, max) => {
return [...new Array(length)]
.map(() => Math.round(Math.random() * max));
};

testFunction.validateArray = (array) => {
for(let i = 0; i < array.length - 1; i++) {
if(array[i] < array[i + 1])
return true;
}
};
Loading