-
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.
Created some tests for the SrlPoint
- Loading branch information
Showing
7 changed files
with
166 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Created by dtracers on 5/17/2016. | ||
*/ | ||
(function (module) { | ||
var StackTrace = require('stacktrace-js'); | ||
var errback = function(err) { console.log(err.message); }; | ||
module.exports = function SketchLibraryException(message, cause) { | ||
|
||
this.name = 'SketchLibraryException'; | ||
/** | ||
* The level defines how bad it is. level 5 is the okayest exception | ||
* (with 6+ typically being ignored completely) and level 0 is the worst | ||
* exception (with <0 being treated as 0). | ||
*/ | ||
this.message = undefined; | ||
this.stackTrace = undefined; | ||
this.cause = undefined; | ||
|
||
/** | ||
* @returns {String} A string representation of the exception. | ||
*/ | ||
this.toString = function() { | ||
return this.name + ': ' + this.message + (this.specificMessage ? '\n' + this.specificMessage : '\n') + this.stackTrace.join('\n\n'); | ||
}; | ||
|
||
/** | ||
* Sets the message of the Exception. | ||
* | ||
* @param {messageValue} messageValue - is a string that contains the description | ||
* of the the exception that occurred. | ||
*/ | ||
this.setMessage = function(messageValue) { | ||
this.specificMessage = messageValue; | ||
}; | ||
|
||
/** | ||
* Used to access the stacktrace of the exception without modifying it. | ||
* @return {stackTrace} Returns a string that contains the entire stacktrace of the exception. | ||
*/ | ||
this.getStackTrace = function() { | ||
return this.stackTrace; | ||
}; | ||
|
||
/** | ||
* Used to log the stacktrace object in BaseException. | ||
*/ | ||
this.printStackTrace = function() { | ||
console.log(printStackTrace().join('\n\n')); | ||
}; | ||
|
||
/** | ||
* Assigns the stacktrace object to an existing stacktrace. | ||
*/ | ||
this.createStackTrace = function() { | ||
StackTrace.get().then(function (stackframes) { | ||
this.stackTrace = stackframes; | ||
}).catch(errback); | ||
}; | ||
|
||
/** | ||
* Sets the cause of baseException to the causeValue passed in. | ||
* | ||
* @param {causeValue} causeValue - Is the cause of the exception. | ||
*/ | ||
this.setCause = function(causeValue) { | ||
this.cause = causeValue; | ||
}; | ||
|
||
/** | ||
* A getter function used to access the cause of the stacktrace without the risk of manipulating it. | ||
*/ | ||
this.getCause = function() { | ||
return this.cause; | ||
}; | ||
|
||
this.setMessage(message); | ||
this.setCause(cause); | ||
this.createStackTrace(); | ||
}; | ||
})(module); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
var assert = require('chai').assert; | ||
var expect = require('chai').expect; | ||
|
||
var basePath = '../../../'; | ||
var srcPath = 'main/js/'; | ||
var SrlPoint = require(basePath + srcPath + 'sketchLibrary/SrlPoint'); | ||
var SketchException = require(basePath + srcPath + 'sketchLibrary/SketchLibraryException'); | ||
var ProtoPoint = require(basePath + srcPath + 'generated_proto/sketch').protobuf.srl.sketch.SrlPoint; | ||
|
||
describe('Point Tests', function () { | ||
var x = 10; | ||
var y = 25.6; | ||
var time = 80; | ||
var id = 'id'; | ||
describe('initializations', function () { | ||
it('should be able to create an instance of the point class', function () { | ||
var sketch = new SrlPoint(); | ||
}); | ||
it('should be able to create an instance of the point class initialized with two values', function () { | ||
var point = new SrlPoint(x, y); | ||
expect(point.getX()).to.equal(x); | ||
expect(point.getY()).to.equal(y); | ||
}); | ||
it('set all values of the point', function () { | ||
var point = new SrlPoint(x, y); | ||
point.setTime(time); | ||
point.setId(id); | ||
expect(point.getX()).to.equal(x); | ||
expect(point.getY()).to.equal(y); | ||
expect('' + point.getTime()).to.equal('' + time); | ||
expect(point.getId()).to.equal(id); | ||
}); | ||
it('can not set x and y separately', function () { | ||
var point = new SrlPoint(x, y); | ||
expect(function () { | ||
point.setX(5); | ||
}).to.throw(SketchException); | ||
expect(function () { | ||
point.setY(5); | ||
}).to.throw(SketchException); | ||
}); | ||
}); | ||
|
||
describe('protobuf', function () { | ||
it('should be able to create an arraybuffer', function () { | ||
var point = new SrlPoint(); | ||
point.setP(x, y); | ||
point.setTime(time); | ||
point.setId(id); | ||
var arrayBuffer = point.toArrayBuffer(); | ||
var decoded = ProtoPoint.decode(arrayBuffer); | ||
expect(decoded.getX()).to.equal(x); | ||
expect(decoded.getY()).to.equal(y); | ||
expect('' + decoded.getTime()).to.equal('' + time); | ||
expect(decoded.getId()).to.equal(id); | ||
}); | ||
|
||
it('should be able to parse an array buffer', function () { | ||
var protoPoint = new ProtoPoint(); | ||
protoPoint.setX(x); | ||
protoPoint.setY(y); | ||
protoPoint.setTime(time); | ||
protoPoint.setId(id); | ||
var arrayBuffer = protoPoint.toArrayBuffer(); | ||
var decoded = SrlPoint.decode(arrayBuffer); | ||
expect(decoded.getX()).to.equal(x); | ||
expect(decoded.getY()).to.equal(y); | ||
expect('' + decoded.getTime()).to.equal('' + time); | ||
expect(decoded.getId()).to.equal(id); | ||
}); | ||
}); | ||
}); |