Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenca committed Jul 21, 2017
1 parent 9bccd66 commit e087b3a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 21 deletions.
11 changes: 7 additions & 4 deletions build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/main.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<i class="fa fa-arrow-circle-up" id="N-up"></i>
<i class="fa fa-arrow-circle-right" id="N-right"></i>
</div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell" style="text-align: center"><i class="fa fa-cab"></i></div>
<div class="divTableCell">&nbsp;</div>
</div>
<div class="divTableRow">
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell" style="text-align: right"><i class="fa fa-bicycle"></i></div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell" style="text-align:left">
Expand All @@ -39,11 +39,11 @@
</div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell"><i class="fa fa-truck"></i></div>
</div>
<div class="divTableRow">
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell">&nbsp;</div>
<div class="divTableCell" style="text-align:center"><i class="fa fa-bus"></i></div>
<div class="divTableCell" style="text-align:center">
<i class="fa fa-arrow-circle-left" id="S-left"></i>
<i class="fa fa-arrow-circle-down" id="S-down"></i>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test mocha --compilers js:babel-core/register --reporter spec -d tests",
"test": "NODE_ENV=test mocha --compilers js:babel-core/register --reporter list -d tests",
"dev": "node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"webpack": "webpack",
"start": "babel-node src/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TRAFFIC_LIGHTS = {
};

const GREEN_LIGHT_DURATION = 270000; //270000; 60 * 1000 * 4.5; // 4mins30sec
const YELLOW_LIGHT_DURATION = 30000; //270000; 30 * 1000; // 30sec
const YELLOW_LIGHT_DURATION = 30000; //30000; 30 * 1000; // 30sec
const DURATION_OF_SIMULATION = 1800000; //1800000; 60 * 30 * 1000 // 30mins
const LOG_TYPE = 'simple';

Expand Down
2 changes: 1 addition & 1 deletion src/Flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Flow {
}

setDirectionIndex(directionIndex) {
if (directionIndex >= this.config.getDirections().length) {
if (directionIndex < 0 || directionIndex >= this.config.getDirections().length) {
throw new Error(`directionIndex is out of range`);
}
this.directionIndex = directionIndex;
Expand Down
3 changes: 3 additions & 0 deletions src/Lights.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Lights {
}

setDirectionIndex(directionIndex) {
if (directionIndex < 0 || directionIndex >= this.config.getDirections().length) {
throw new Error(`directionIndex is out of range`);
}
this.directionIndex = directionIndex;
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const logger = new Logger();
const flow = new Flow(config);

const doIt = () => {
logger.write(`The program will only run for ${config.getDurationOfSimulation()/1000}s`);
logger.write(`The program will run for ${config.getDurationOfSimulation()/1000}s`);
flow.start();
setTimeout(()=>{
flow.hold();
Expand Down
14 changes: 6 additions & 8 deletions tests/Flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,25 @@ describe('Flow', () => {
assert.equal(2, flow.getDirectionIndex());
});

it('Should get a false status after x amount of time', async () => {
it('Should get a false status after when flow stopped running', async () => {
const flow = new Flow(config);
flow.start();
setTimeout(()=>{
flow.hold();
}, 5000);
}, 2000);

assert.equal(true, flow.getStatus());
await flow.sleep(5000);
await flow.sleep(2000);
assert.equal(false, flow.getStatus());
});

it('Should fail to get a true status after x amount of time', async () => {
it('Should get a true status while flow is still running', async () => {
const flow = new Flow(config);
flow.start();
setTimeout(()=>{
flow.hold();
}, 5000);
}, 2000);

await flow.sleep(1000);
assert.equal(true, flow.getStatus());
await flow.sleep(5000);
assert.notEqual(true, flow.getStatus());
});
});
4 changes: 4 additions & 0 deletions tests/Lights.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('Lights', () => {
assert.equal(1, lights.getDirectionIndex());
});

it('Should throw error when setting out of range directionIndex', () => {
assert.throws(()=>{lights.setDirectionIndex(5)}, Error, 'directionIndex is out of range');
});

it('Should set green lights', () => {
let directionIndex = 0;
lights.setDirectionIndex(directionIndex);
Expand Down

0 comments on commit e087b3a

Please sign in to comment.