-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test cases added with minor improvements
- Loading branch information
Showing
7 changed files
with
334 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var assert = require('chai').assert; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
const { ColorSensor } = require('../'); | ||
|
||
var s; | ||
var updated; | ||
|
||
const SAMPLE_ID = 1; | ||
const INITIAL_VALUES = [0, 0, 0]; | ||
const SAMPLE_VALUES_1 = [123, 231, 19]; | ||
const SAMPLE_VALUES_2 = [1, 150, 121]; | ||
|
||
beforeEach(function () { | ||
s = new ColorSensor(SAMPLE_ID); | ||
updated = s.getReading().updated; | ||
}); | ||
|
||
describe('Color Sensor', function () { | ||
describe('#getReading()', function () { | ||
it('should get the sensor readings', function () { | ||
expect(s.getReading()).to.be.a('object').to.haveOwnProperty('id'); | ||
expect(s.getReading()).to.be.a('object').to.haveOwnProperty('value'); | ||
expect(s.getReading()).to.be.a('object').to.haveOwnProperty('updated'); | ||
expect(s.getReading()).to.not.null; | ||
expect(s.getReading()).to.not.be.empty; | ||
expect(s.getReading()).to.not.undefined; | ||
assert.typeOf(s.getReading(), 'object'); | ||
assert.typeOf(s.getReading().id, 'number'); | ||
assert.typeOf(s.getReading().value, 'array'); | ||
assert.typeOf(s.getReading().updated, 'number'); | ||
}); | ||
}); | ||
|
||
describe('#setReading()', function () { | ||
it('should set the sensor values', function () { | ||
assert.deepEqual(s.getReading().value, INITIAL_VALUES); | ||
s.setReading(SAMPLE_VALUES_1); | ||
assert.notEqual(s.getReading().value, INITIAL_VALUES); | ||
assert.deepEqual(s.getReading().value, SAMPLE_VALUES_1); | ||
expect(s.updated).gte(updated); | ||
s.setReading(SAMPLE_VALUES_2); | ||
assert.notEqual(s.getReading().value, INITIAL_VALUES); | ||
assert.deepEqual(s.getReading().value, SAMPLE_VALUES_2); | ||
expect(s.updated).gte(updated); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var assert = require('chai').assert; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
const { DistanceSensor } = require('../'); | ||
|
||
var s; | ||
var updated; | ||
|
||
const SAMPLE_ID = 1; | ||
const INITIAL_VALUE = 0; | ||
const SAMPLE_VALUE_1 = 123; | ||
const SAMPLE_VALUE_2 = 126; | ||
|
||
beforeEach(function () { | ||
s = new DistanceSensor(SAMPLE_ID); | ||
updated = s.getReading().updated; | ||
}); | ||
|
||
describe('Distance Sensor', function () { | ||
describe('#getReading()', function () { | ||
it('should get the sensor reading', function () { | ||
expect(s.getReading()).to.be.a('object').to.haveOwnProperty('id'); | ||
expect(s.getReading()).to.be.a('object').to.haveOwnProperty('value'); | ||
expect(s.getReading()).to.be.a('object').to.haveOwnProperty('updated'); | ||
expect(s.getReading()).to.not.null; | ||
expect(s.getReading()).to.not.be.empty; | ||
expect(s.getReading()).to.not.undefined; | ||
assert.typeOf(s.getReading(), 'object'); | ||
assert.typeOf(s.getReading().id, 'number'); | ||
assert.typeOf(s.getReading().value, 'number'); | ||
assert.typeOf(s.getReading().updated, 'number'); | ||
}); | ||
}); | ||
|
||
describe('#setReading()', function () { | ||
it('should set the sensor value', function () { | ||
assert.equal(s.getReading().value, INITIAL_VALUE); | ||
s.setReading(SAMPLE_VALUE_1); | ||
assert.notEqual(s.getReading().value, INITIAL_VALUE); | ||
assert.equal(s.getReading().value, SAMPLE_VALUE_1); | ||
expect(s.updated).gte(updated); | ||
s.setReading(SAMPLE_VALUE_2); | ||
assert.notEqual(s.getReading().value, INITIAL_VALUE); | ||
assert.equal(s.getReading().value, SAMPLE_VALUE_2); | ||
expect(s.updated).gte(updated); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
var assert = require('chai').assert; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
const { VRobot, sensorModuleTypes, Coordinate } = require('../'); | ||
// const sensors = require('../../modules/sensors'); | ||
|
||
var r; | ||
var updated; | ||
var created; | ||
var timestamp; | ||
|
||
const SAMPLE_ID_1 = 1; | ||
const SAMPLE_ID_2 = 2; | ||
|
||
const INITIAL_HEADING = 0; | ||
const INITIAL_X = 0; | ||
const INITIAL_Y = 0; | ||
const INITIAL_Z = undefined; | ||
|
||
const SAMPLE_HEADING_1 = 5; | ||
const SAMPLE_X_1 = 6; | ||
const SAMPLE_Y_1 = 7; | ||
const SAMPLE_Z_1 = 8; | ||
|
||
const SAMPLE_HEADING_2 = 10; | ||
const SAMPLE_X_2 = 11; | ||
const SAMPLE_Y_2 = 12; | ||
const SAMPLE_Z_2 = 13; | ||
|
||
beforeEach(function () { | ||
r = new VRobot(SAMPLE_ID_1); | ||
updated = r.updated; | ||
created = r.created; | ||
timestamp = r.timestamp; | ||
}); | ||
|
||
describe('VRobot', function () { | ||
describe('#VRobot()', function () { | ||
it('should create a VRobot instance', function () { | ||
// id | ||
expect(r).to.have.property('id'); | ||
assert.typeOf(r.id, 'number'); | ||
// coordinates | ||
expect(r).to.have.property('coordinates'); | ||
assert.typeOf(r.coordinates, 'object'); | ||
// created | ||
expect(r).to.have.property('created'); | ||
assert.typeOf(r.created, 'date'); | ||
expect(r.created).to.equal(created); | ||
// updated | ||
expect(r).to.have.property('updated'); | ||
assert.typeOf(r.updated, 'number'); | ||
expect(r.updated).to.equal(updated); | ||
// timestamp | ||
expect(r).to.have.property('timestamp'); | ||
assert.typeOf(r.timestamp, 'number'); | ||
expect(r.timestamp).to.equal(timestamp); | ||
}); | ||
}); | ||
|
||
describe('#coordinates', function () { | ||
it('should return the coordinates of the robot instance', function () { | ||
const coordinates = r.coordinates; | ||
assert.typeOf(coordinates, 'object'); | ||
// id | ||
expect(coordinates).to.haveOwnProperty('id'); | ||
assert.typeOf(coordinates.id, 'number'); | ||
expect(coordinates.id).to.be.equal(SAMPLE_ID_1); | ||
// heading | ||
expect(coordinates).to.haveOwnProperty('heading'); | ||
assert.typeOf(coordinates.heading, 'number'); | ||
expect(coordinates.heading).to.be.equal(INITIAL_HEADING); | ||
// x | ||
expect(coordinates).to.haveOwnProperty('x'); | ||
assert.typeOf(coordinates.x, 'number'); | ||
expect(coordinates.x).to.be.equal(INITIAL_X); | ||
// y | ||
expect(coordinates).to.haveOwnProperty('y'); | ||
assert.typeOf(coordinates.y, 'number'); | ||
expect(coordinates.y).to.be.equal(INITIAL_Y); | ||
// z | ||
expect(coordinates).to.not.haveOwnProperty('z'); | ||
assert.typeOf(coordinates.z, 'undefined'); | ||
expect(coordinates.z).to.be.equal(INITIAL_Z); | ||
}); | ||
}); | ||
|
||
describe('#setCoordinates()', function () { | ||
it('should set the coordinates of the robot instance', function () { | ||
r.setCoordinates({ heading: SAMPLE_HEADING_1, x: SAMPLE_X_1, y: SAMPLE_Y_1 }); | ||
expect(r.updated).gte(updated); | ||
const coordinates = r.coordinates; | ||
assert.typeOf(coordinates, 'object'); | ||
// id | ||
expect(coordinates).to.haveOwnProperty('id'); | ||
assert.typeOf(coordinates.id, 'number'); | ||
expect(coordinates.id).to.be.equal(SAMPLE_ID_1); | ||
// heading | ||
expect(coordinates).to.haveOwnProperty('heading'); | ||
assert.typeOf(coordinates.heading, 'number'); | ||
expect(coordinates.heading).to.be.equal(SAMPLE_HEADING_1); | ||
// x | ||
expect(coordinates).to.haveOwnProperty('x'); | ||
assert.typeOf(coordinates.x, 'number'); | ||
expect(coordinates.x).to.be.equal(SAMPLE_X_1); | ||
// y | ||
expect(coordinates).to.haveOwnProperty('y'); | ||
assert.typeOf(coordinates.y, 'number'); | ||
expect(coordinates.y).to.be.equal(SAMPLE_Y_1); | ||
// z | ||
expect(coordinates).to.not.haveOwnProperty('z'); | ||
assert.typeOf(coordinates.z, 'undefined'); | ||
expect(coordinates.z).to.be.equal(INITIAL_Z); | ||
}); | ||
}); | ||
|
||
describe('#sensors()', function () { | ||
it('should return the sensors module of the robot instance', function () { | ||
const sensors = r.sensors; | ||
assert.typeOf(sensors, 'object'); | ||
sensorModuleTypes.map((type) => { | ||
expect(sensors).to.haveOwnProperty(type); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#getSensorReadings()', function () { | ||
it('should return the sensor readings of the robot instance', function () { | ||
expect(r.getSensorReadings).to.throw(TypeError); | ||
const sensorReadings = r.getSensorReadings(sensorModuleTypes); | ||
assert.typeOf(sensorReadings, 'array'); | ||
}); | ||
}); | ||
|
||
describe('#created', function () { | ||
it('should return the created value of the robot instance', function () { | ||
const createdValue = r.created; | ||
assert.typeOf(createdValue, 'date'); | ||
expect(createdValue).to.equal(created); | ||
}); | ||
}); | ||
|
||
describe('#timestamp', function () { | ||
it('should return the timestamp value of the robot instance', function () { | ||
const timestampValue = r.timestamp; | ||
assert.typeOf(timestampValue, 'number'); | ||
expect(timestampValue).to.equal(timestamp); | ||
}); | ||
}); | ||
|
||
describe('#updateHeartbeat()', function () { | ||
it('should update and return the updated timestamp of the robot instance', function () { | ||
const heartbeat = r.updateHeartbeat(); | ||
assert.typeOf(heartbeat, 'number'); | ||
expect(heartbeat).gte(timestamp); | ||
expect(r.updated).gte(updated); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var assert = require('chai').assert; | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
const { sensors, ColorSensor, DistanceSensor } = require('../'); | ||
|
||
var s; | ||
var updated; | ||
|
||
const SAMPLE_ID = 1; | ||
|
||
const INITIAL_COLOR_SENSOR_VALUES = [0, 0, 0]; | ||
const SAMPLE_COLOR_SENSOR_VALUES_1 = [123, 231, 19]; | ||
const SAMPLE_COLOR_SENSOR_VALUES_2 = [1, 150, 121]; | ||
|
||
const INITIAL_DISTANCE_SENSOR_VALUE = 0; | ||
const SAMPLE_DISTANCE_SENSOR_VALUE_1 = 123; | ||
const SAMPLE_DISTANCE_SENSOR_VALUE_2 = 150; | ||
|
||
beforeEach(function () { | ||
s = sensors(SAMPLE_ID); | ||
updated = s.updated; | ||
}); | ||
|
||
describe('Sensors', function () { | ||
describe('#sensors()', function () { | ||
it('should create a sensor instance', function () { | ||
expect(sensors).to.throw(TypeError); | ||
s = sensors(SAMPLE_ID); | ||
// updated | ||
expect(s).to.haveOwnProperty('updated'); | ||
assert.typeOf(s.updated, 'number'); | ||
expect(s.updated).to.gte(updated); | ||
// color | ||
expect(s).to.haveOwnProperty('color'); | ||
expect(s.color).to.be.instanceOf(ColorSensor); | ||
assert.typeOf(s.color, 'object'); | ||
expect(s.color.id).to.equal(SAMPLE_ID); | ||
expect(s.color.value).to.deep.equal(INITIAL_COLOR_SENSOR_VALUES); | ||
// distance | ||
expect(s).to.haveOwnProperty('distance'); | ||
expect(s.distance).to.be.instanceOf(DistanceSensor); | ||
assert.typeOf(s.distance, 'object'); | ||
expect(s.distance.id).to.equal(SAMPLE_ID); | ||
expect(s.distance.value).to.deep.equal(INITIAL_DISTANCE_SENSOR_VALUE); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters