Permalink
Browse files

fixed unit tests

  • Loading branch information...
1 parent 66732ad commit 0ab56a81d991a0cb2e58a78f7a4977c8ff80c907 @christian-bromann christian-bromann committed Aug 18, 2016
Showing with 156 additions and 154 deletions.
  1. +0 −1 .eslintignore
  2. +11 −1 gruntfile.js
  3. +6 −5 lib/helpers/calcResult.js
  4. +1 −1 package.json
  5. +2 −6 test/bootstrap.js
  6. +49 −0 test/fixtures/example.json
  7. +87 −140 test/spec/unit.js
View
@@ -1,4 +1,3 @@
build/
-examples/
bin/
./*.js
View
@@ -13,11 +13,21 @@ module.exports = function (grunt) {
}]
}
},
+ mochaTest: {
+ unit: {
+ src: ['./test/bootstrap.js', './test/spec/**/*'],
+ options: {
+ reporter: 'spec',
+ require: ['babel-register'],
+ timeout: 120000
+ }
+ }
+ },
eslint: {
options: {
parser: 'babel-eslint'
},
- target: ['index.js', 'lib/**/*.js', 'examples/**/*.js'] //, 'test/**/*.js']
+ target: ['index.js', 'lib/**/*.js', 'examples/**/*.js', 'test/**/*.js']
},
contributors: {
options: {
@@ -54,19 +54,20 @@ const calcResult = {
*/
'max': (results, result) => {
if (results instanceof Array) {
- return calculateArray('max', results)
+ let ret = {}
+ results.forEach((result) => calcResult['max'](result, ret))
+ return ret
}
Object.keys(results).forEach((attr) => {
- if (typeof results[attr] !== 'number') {
- return false
- }
-
if (typeof results[attr] === 'object') {
if (!result[attr]) {
result[attr] = {}
}
+
return calcResult['max'](results[attr], result[attr] || {})
+ } else if (typeof results[attr] !== 'number') {
+ return false
}
if (!result[attr]) {
View
@@ -52,7 +52,7 @@
"grunt-mocha-test": "^0.12.7",
"grunt-npm": "0.0.2",
"load-grunt-tasks": "^3.5.0",
- "mocha": "^2.3.4",
+ "mocha": "^3.0.2",
"webdriverio": "git://github.com/webdriverio/webdriverio#master"
},
"dependencies": {
View
@@ -1,9 +1,5 @@
/**
* require dependencies
*/
-// WebdriverIO = require('webdriverio');
-// WebdriverRTC = require('../');
-should = require('chai').should();
-expect = require('chai').expect;
-// capabilities = {logLevel: 'silent',desiredCapabilities:{browserName: 'phantomjs'}};
-// testurl = 'http://localhost:8080/test/site/index.html';
+require('chai').should()
+global.expect = require('chai').expect
@@ -0,0 +1,49 @@
+[{
+ "attr1": 13,
+ "attr2": 2,
+ "attr3": {
+ "attr1": 43,
+ "attr2": 46,
+ "attr3": {
+ "attr1": {
+ "attr1": 15
+ }
+ }
+ }
+},{
+ "attr1": 22,
+ "attr2": 10,
+ "attr3": {
+ "attr1": 3,
+ "attr2": 7,
+ "attr3": {
+ "attr1": {
+ "attr1": 1
+ }
+ }
+ }
+},{
+ "attr1": 29,
+ "attr2": 34,
+ "attr3": {
+ "attr1": 17,
+ "attr2": 25,
+ "attr3": {
+ "attr1": {
+ "attr1": 4
+ }
+ }
+ }
+},{
+ "attr1": 14,
+ "attr2": 42,
+ "attr3": {
+ "attr1": 9,
+ "attr2": 2,
+ "attr3": {
+ "attr1": {
+ "attr1": 49
+ }
+ }
+ }
+}]
View
@@ -1,144 +1,91 @@
-var calcResult = require('../../lib/helpers/calcResult');
-
-describe('calcResult', function() {
-
- var exampleResults = [{
- attr1: 13,
- attr2: 2,
- attr3: {
- attr1: 43,
- attr2: 46,
- attr3: {
- attr1: {
- attr1: 15
- }
- }
- }
- },{
- attr1: 22,
- attr2: 10,
- attr3: {
- attr1: 3,
- attr2: 7,
- attr3: {
- attr1: {
- attr1: 1
- }
- }
- }
- },{
- attr1: 29,
- attr2: 34,
- attr3: {
- attr1: 17,
- attr2: 25,
- attr3: {
- attr1: {
- attr1: 4
- }
- }
- }
- },{
- attr1: 14,
- attr2: 42,
- attr3: {
- attr1: 9,
- attr2: 2,
- attr3: {
- attr1: {
- attr1: 49
- }
- }
- }
- }];
-
- describe('should be able to calculate the mean', function() {
- var addedResults;
-
- it('should add to result', function() {
- addedResults = calcResult['+'](exampleResults);
-
- addedResults.attr1.should.be.equal(78);
- addedResults.attr2.should.be.equal(88);
- addedResults.attr3.attr1.should.be.equal(72);
- addedResults.attr3.attr2.should.be.equal(80);
- addedResults.attr3.attr3.attr1.attr1.should.be.equal(69);
- });
-
- it('should divide the result', function() {
- dividedResults = calcResult['/'](addedResults, exampleResults.length);
-
- dividedResults.attr1.should.be.equal(19.5);
- dividedResults.attr2.should.be.equal(22);
- dividedResults.attr3.attr1.should.be.equal(18);
- dividedResults.attr3.attr2.should.be.equal(20);
- dividedResults.attr3.attr3.attr1.attr1.should.be.equal(17.25);
- });
-
- });
-
- describe('should be able to calculate the median', function() {
- var resultArray;
-
- it('list results into an array', function() {
- resultArray = calcResult['[]'](exampleResults);
-
- resultArray.attr1.should.be.deep.equal([13,22,29,14]);
- resultArray.attr2.should.be.deep.equal([2 ,10,34,42]);
- resultArray.attr3.attr1.should.be.deep.equal([43,3 ,17,9]);
- resultArray.attr3.attr2.should.be.deep.equal([46,7 ,25,2]);
- resultArray.attr3.attr3.attr1.attr1.should.be.deep.equal([15,1,4,49]);
- });
-
- it('get the middle value of that array if length is even', function() {
- var mean = calcResult['-|-'](resultArray);
-
- mean.attr1.should.be.equal(18.00);
- mean.attr2.should.be.equal(22.00);
- mean.attr3.attr1.should.be.equal(13.00);
- mean.attr3.attr2.should.be.equal(16.00);
- mean.attr3.attr3.attr1.attr1.should.be.equal(9.50);
- });
-
- it('get the middle value of that array if length is uneven', function() {
+import calcResult from '../../lib/helpers/calcResult'
+import exampleResults from '../fixtures/example.json'
+
+describe('calcResult', () => {
+ it('should find the min value', () => {
+ let minResult = calcResult['min'](exampleResults)
+
+ minResult.attr1.should.be.equal(13)
+ minResult.attr2.should.be.equal(2)
+ minResult.attr3.attr1.should.be.equal(3)
+ minResult.attr3.attr2.should.be.equal(2)
+ minResult.attr3.attr3.attr1.attr1.should.be.equal(1)
+ })
+
+ it('should find the max value', () => {
+ let maxResult = calcResult['max'](exampleResults)
+
+ maxResult.attr1.should.be.equal(29)
+ maxResult.attr2.should.be.equal(42)
+ maxResult.attr3.attr1.should.be.equal(43)
+ maxResult.attr3.attr2.should.be.equal(46)
+ maxResult.attr3.attr3.attr1.attr1.should.be.equal(49)
+ })
+
+ describe('should be able to calculate the mean', () => {
+ let addedResults
+
+ it('should add to result', () => {
+ addedResults = calcResult['+'](exampleResults)
+
+ addedResults.attr1.should.be.equal(78)
+ addedResults.attr2.should.be.equal(88)
+ addedResults.attr3.attr1.should.be.equal(72)
+ addedResults.attr3.attr2.should.be.equal(80)
+ addedResults.attr3.attr3.attr1.attr1.should.be.equal(69)
+ })
+
+ it('should divide the result', () => {
+ let dividedResults = calcResult['/'](addedResults, exampleResults.length)
+
+ dividedResults.attr1.should.be.equal(19.5)
+ dividedResults.attr2.should.be.equal(22)
+ dividedResults.attr3.attr1.should.be.equal(18)
+ dividedResults.attr3.attr2.should.be.equal(20)
+ dividedResults.attr3.attr3.attr1.attr1.should.be.equal(17.25)
+ })
+ })
+
+ describe('should be able to calculate the median', () => {
+ let resultArray
+
+ it('list results into an array', () => {
+ resultArray = calcResult['[]'](exampleResults)
+
+ resultArray.attr1.should.be.deep.equal([13, 22, 29, 14])
+ resultArray.attr2.should.be.deep.equal([2, 10, 34, 42])
+ resultArray.attr3.attr1.should.be.deep.equal([43, 3, 17, 9])
+ resultArray.attr3.attr2.should.be.deep.equal([46, 7, 25, 2])
+ resultArray.attr3.attr3.attr1.attr1.should.be.deep.equal([15, 1, 4, 49])
+ })
+
+ it('get the middle value of that array if length is even', () => {
+ let mean = calcResult['-|-'](resultArray)
+
+ mean.attr1.should.be.equal(18.00)
+ mean.attr2.should.be.equal(22.00)
+ mean.attr3.attr1.should.be.equal(13.00)
+ mean.attr3.attr2.should.be.equal(16.00)
+ mean.attr3.attr3.attr1.attr1.should.be.equal(9.50)
+ })
+
+ it('get the middle value of that array if length is uneven', () => {
/**
* add another value to have uneven length
*/
- resultArray.attr1.push(18);
- resultArray.attr2.push(22);
- resultArray.attr3.attr1.push(13);
- resultArray.attr3.attr2.push(16);
- resultArray.attr3.attr3.attr1.attr1.push(9);
-
- var median = calcResult['-|-'](resultArray);
-
- median.attr1.should.be.equal(18.00);
- median.attr2.should.be.equal(22.00);
- median.attr3.attr1.should.be.equal(13.00);
- median.attr3.attr2.should.be.equal(16.00);
- median.attr3.attr3.attr1.attr1.should.be.equal(9.00);
- });
-
- });
-
- it('should find the min value', function() {
- minResult = calcResult['min'](exampleResults);
-
- minResult.attr1.should.be.equal(13);
- minResult.attr2.should.be.equal(2);
- minResult.attr3.attr1.should.be.equal(3);
- minResult.attr3.attr2.should.be.equal(2);
- minResult.attr3.attr3.attr1.attr1.should.be.equal(1);
- });
-
- it('should find the max value', function() {
- maxResult = calcResult['max'](exampleResults);
-
- maxResult.attr1.should.be.equal(29);
- maxResult.attr2.should.be.equal(42);
- maxResult.attr3.attr1.should.be.equal(43);
- maxResult.attr3.attr2.should.be.equal(46);
- maxResult.attr3.attr3.attr1.attr1.should.be.equal(49);
- });
-
+ resultArray.attr1.push(18)
+ resultArray.attr2.push(22)
+ resultArray.attr3.attr1.push(13)
+ resultArray.attr3.attr2.push(16)
+ resultArray.attr3.attr3.attr1.attr1.push(9)
+
+ let median = calcResult['-|-'](resultArray)
+
+ median.attr1.should.be.equal(18.00)
+ median.attr2.should.be.equal(22.00)
+ median.attr3.attr1.should.be.equal(13.00)
+ median.attr3.attr2.should.be.equal(16.00)
+ median.attr3.attr3.attr1.attr1.should.be.equal(9.00)
+ })
+ })
})

0 comments on commit 0ab56a8

Please sign in to comment.