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

Updated lab for 2019.

parent 3d0802e3
Branches master
No related tags found
No related merge requests found
......@@ -4,6 +4,9 @@
"browser": true,
"jquery": true,
},
"parserOptions": {
"sourceType": "module",
},
"rules": {
"no-await-in-loop": "warn",
"no-compare-neg-zero": "warn",
......
/* exported determineBuyPrice */
function descendsThenAscends(prices) {
let previous = Infinity;
let recovering = false;
......@@ -16,7 +14,7 @@ function descendsThenAscends(prices) {
return true;
}
function determineBuyPrice(forecastPrices) {
export function determineBuyPrice(forecastPrices) {
console.assert(forecastPrices.length > 0, 'Tried to find a buy price with an empty forecast.');
console.assert(descendsThenAscends(forecastPrices), 'Tried to find a buy price with a forecast that does something other than descend and then ascend.');
if (forecastPrices.length === 1) {
......
/* exported BuySellPlan determineBuyAndSellPrices */
class BuySellPlan {
export class BuySellPlan {
constructor(buyPrice, sellPrice, minimumPrice, maximumPrice) {
this.buyPrice = buyPrice;
this.sellPrice = sellPrice;
......@@ -24,7 +22,7 @@ function combineBuySellPlans(firstPlan, secondPlan) {
return result;
}
function determineBuyAndSellPrices(forecastPrices) {
export function determineBuyAndSellPrices(forecastPrices) {
console.assert(forecastPrices.length > 0, 'Tried to find buy and sell prices with an empty forecast.');
if (forecastPrices.length === 1) {
return new BuySellPlan(forecastPrices[0], forecastPrices[0], forecastPrices[0], forecastPrices[0]);
......
/* exported SellPlan determineSellChange */
class SellPlan {
export class SellPlan {
constructor(sellChange, totalChange) {
this.sellChange = sellChange;
this.totalChange = totalChange;
......@@ -14,7 +12,7 @@ function combineSellPlans(firstPlan, secondPlan) {
);
}
function determineSellChange(forecastChanges) {
export function determineSellChange(forecastChanges) {
if (forecastChanges.length === 0) {
return new SellPlan(0, 0);
}
......
QUnit.module('buy.js');
/* globals QUnit determineBuyPrice */
import {determineBuyPrice} from '../js/buy.js';
/* globals QUnit */
QUnit.module('test_buy.js');
/* eslint-disable no-magic-numbers */
QUnit.test('find a buy price for a one-element forecast', (assert) => {
......
QUnit.module('buy_sell.js');
/* globals QUnit BuySellPlan determineBuyAndSellPrices */
import {BuySellPlan, determineBuyAndSellPrices} from '../js/buy_sell.js';
/* globals QUnit */
QUnit.module('test_buy_sell.js');
/* eslint-disable no-magic-numbers */
QUnit.test('find buy and sell prices for a one-element forecast', (assert) => {
......@@ -42,6 +44,14 @@ QUnit.test('find buy and sell prices for a four-element invereted zig-zag foreca
assert.deepEqual(determineBuyAndSellPrices([102, 103, 100, 101]), new BuySellPlan(102, 103, 100, 103));
});
QUnit.test('find buy and sell prices for a six-element leveling forecast', (assert) => {
assert.deepEqual(determineBuyAndSellPrices([101, 102, 100, 101, 101, 101]), new BuySellPlan(101, 102, 100, 102));
});
QUnit.test('find buy and sell prices for a six-element rotated leveling forecast', (assert) => {
assert.deepEqual(determineBuyAndSellPrices([101, 101, 101, 102, 100, 101]), new BuySellPlan(101, 102, 100, 102));
});
QUnit.test('find buy and sell prices for random forecast #0', (assert) => {
assert.deepEqual(determineBuyAndSellPrices([900, 865, 691, 580, 967, 480, 740, 936, 153, 371, 606, 901]), new BuySellPlan(153, 901, 153, 967));
});
......
QUnit.module('sell.js');
/* globals QUnit SellPlan determineSellChange */
import {SellPlan, determineSellChange} from '../js/sell.js';
/* globals QUnit */
QUnit.module('test_sell.js');
/* eslint-disable no-magic-numbers */
QUnit.test('find cumulative change at which to sell for a zero-element forecast', (assert) => {
......
......@@ -13,14 +13,9 @@
<script src="../libraries/qunit/qunit.js"></script>
<script src="overrides.js"></script>
<script src="../js/sell.js"></script>
<script src="test_sell.js"></script>
<script src="../js/buy_sell.js"></script>
<script src="test_buy_sell.js"></script>
<script src="../js/buy.js"></script>
<script src="test_buy.js"></script>
<script type="module" src="test_sell.js"></script>
<script type="module" src="test_buy_sell.js"></script>
<script type="module" src="test_buy.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