diff --git a/.jshintrc b/.jshintrc index dfd08b60..f12c6705 100644 --- a/.jshintrc +++ b/.jshintrc @@ -25,6 +25,6 @@ "trailing": true, "quotmark": "single", "proto": true, - "laxbreak": true + "laxbreak": true, + "mocha": true } - diff --git a/Gruntfile.js b/Gruntfile.js index 0ed1ee85..d4ae0cc3 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,7 +14,8 @@ module.exports = function(grunt) { }, files: [ 'Gruntfile.js', - './build/ros3d.js' + './build/ros3d.js', + './tests/*.js' ] }, karma: { diff --git a/README.md b/README.md index 2592cf24..a6465554 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ros3djs [![Build Status](https://api.travis-ci.org/RobotWebTools/ros3djs.png)](h ======= #### 3D Visualization Library for use with the ROS JavaScript Libraries -For full documentation, see [the ROS wiki](http://ros.org/wiki/ros3djs) or check out some [working demos](http://robotwebtools.org/). +For full documentation, see [the ROS wiki](http://ros.org/wiki/ros3djs) or check out some [working demos](http://robotwebtools.org/demos.html). [JSDoc](http://robotwebtools.org/jsdoc/ros3djs/current/) can be found on the Robot Web Tools website. @@ -89,6 +89,11 @@ To run the build tasks: `grunt doc` will rebuild all JSDoc for the project. +### Testing +Utilizes [mocha](https://mochajs.org/) and [chai](http://chaijs.com/) for in browser testing. + +To run tests simply open `tests/index.html` in a web browser + ### License ros3djs is released with a BSD license. For full terms and conditions, see the [LICENSE](LICENSE) file. diff --git a/package.json b/package.json index 6d7fafe7..fa5f8a75 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,16 @@ "license": "BSD-3-Clause", "main": "./src/Ros3D.js", "devDependencies": { + "chai": "^3.5.0", "grunt": "~1.0.1", + "grunt-contrib-clean": "~1.0.0", "grunt-contrib-concat": "~1.0.1", "grunt-contrib-jshint": "~1.1.0", - "grunt-karma": "~2.0.0", - "grunt-contrib-watch": "~1.0.0", "grunt-contrib-uglify": "~2.0.0", + "grunt-contrib-watch": "~1.0.0", "grunt-jsdoc": "~2.1.0", - "grunt-contrib-clean": "~1.0.0" + "grunt-karma": "~2.0.0", + "mocha": "^3.2.0" }, "repository": { "type": "git", diff --git a/tests/index.html b/tests/index.html new file mode 100644 index 00000000..e5ce7db7 --- /dev/null +++ b/tests/index.html @@ -0,0 +1,25 @@ + + + + + Tests + + + +

ros3d.js Tests

+
+
+ + + + + + + + + + + + + + diff --git a/tests/tests.js b/tests/tests.js new file mode 100644 index 00000000..1fa5d271 --- /dev/null +++ b/tests/tests.js @@ -0,0 +1,67 @@ +/*global describe, it, before, beforeEach, after, afterEach, chai, ROS3D, _ */ + +var assert = chai.assert; + +describe('Initialization', function() { + + + describe('Arrow', function() { + var arrow = new ROS3D.Arrow(); + + it('matrix should be equal to the proper Matrix4', function() { + var a = new THREE.Vector3(0, 1, 0); + arrow.setDirection(a); + var b = new THREE.Matrix4(); + b.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + assert.isTrue(_.isEqual(arrow.matrix.toArray(), b.toArray())); + }); + + it('scale should be equal to THREE.Vector3(2, 2, 2)', function() { + arrow.setLength(2); + assert.isTrue(arrow.scale.equals(new THREE.Vector3(2, 2, 2))); + }); + + it('material.color should be equal to THREE.Color(0xfff000)', function() { + arrow.setColor(0xfff000); + assert.equal(arrow.material.color.getHex(), new THREE.Color(0xfff000).getHex()); + }); + + }); + + describe('depthCloud', function() { + // Setup Kinect DepthCloud stream + var depthCloud = new ROS3D.DepthCloud({ + url : 'http://'+window.location.hostname+':9999/stream?topic=/depthcloud_encoded&type=vp8&bitrate=250000&quality=best', + f : 525.0 + }); + + it('should return 525.0 for value of f', function() { + assert.equal(525.0, depthCloud.f); + }); + }); + + describe('Grid', function() { + var grid = new ROS3D.Grid(); + + it('should default to 22 children', function() { + assert.equal(grid.children.length, 22); + }); + + it('each child\'s color is THREE.Color(\'#cccccc\') by default', function() { + var sample = new THREE.Color('#cccccc').getHex(); + function correctColor(element, index, array) { + return element.material.color.getHex() === sample; + } + assert.isTrue(grid.children.every(correctColor)); + }); + + it('each child\'s linewidth is 1 by default', function() { + function isOne(element, index, array) { + return element.material.linewidth === 1; + } + assert.isTrue(grid.children.every(isOne)); + }); + + }); + +});