From 5970c0e68c032834e764d836633f6258938a7ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Thu, 31 May 2018 18:55:24 +0200 Subject: [PATCH] fixing typos adding basic functionality test --- src/workers/stats.js | 46 +++++++------------ test/workers/stats.js | 101 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 102 insertions(+), 45 deletions(-) diff --git a/src/workers/stats.js b/src/workers/stats.js index 928f958..1f0049a 100644 --- a/src/workers/stats.js +++ b/src/workers/stats.js @@ -8,10 +8,10 @@ var idrinth = { */ work: function ( data ) { let calc = new idrinth.Calculator ( - new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ), - new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ), - new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance ) - ); + new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ), + new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ), + new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance ) + ); return calc.calculate (); }, /** @@ -90,22 +90,6 @@ var idrinth = { let modifier = 10000 + Math.floor ( toPositive ( this.level / 500 - 2 ) ) * 1500; return 1 + Math.ceil ( toPositive ( value - modifier ) / 1500 ); } - /** - * @return {Array} - */ - getIncreaseableStats () { - let stats = [ ]; - if ( this.getCost ( this.attack ) <= this.stats ) { - stats.push ( 'attack' ); - } - if ( this.getCost ( this.defense ) <= this.stats ) { - stats.push ( 'defense' ); - } - if ( this.getCost ( this.perception ) <= this.stats ) { - stats.push ( 'perception' ); - } - return stats; - } }, /** * @class Actual logic for stat calculation @@ -119,7 +103,7 @@ var idrinth = { * @param {idrinth.MultiplierSet} multiplier * @return {StatSet} */ - construct ( stat, premium, multiplier ) { + constructor ( stat, premium, multiplier ) { this.stat = stat; this.premium = premium; this.multiplier = multiplier; @@ -131,7 +115,7 @@ var idrinth = { if (! this.premium.mirele ) { return 0; } - return 1.8 * ( this.stats.perception <= 10000 ? 10 : 35 ) * this.multipliers.legion; + return 1.8 * ( this.stat.perception <= 10000 ? 10 : 35 ) * this.multipliers.legion; } /** * @returns {Number} @@ -139,7 +123,7 @@ var idrinth = { addOneAttack () { let base = 4; if ( this.premium.utym ) { - base += ( this.stats.attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion; + base += ( this.stat.attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion; } return base; } @@ -149,10 +133,10 @@ var idrinth = { addOneDefense () { let base = 1; if ( this.premium.utym ) { - base += ( this.stats.defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion; + base += ( this.stat.defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion; } if ( this.premium.kraken ) { - base += ( this.stats.defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this.multiplier.legion; + base += ( this.stat.defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this.multiplier.legion; } return base; } @@ -162,7 +146,7 @@ var idrinth = { * @returns {Number} */ addProcs ( value ) { - let perc = this.stats.perception + 1; + let perc = this.stat.perception + 1; return value * ( 1 + this.multiplier.mount + this.multiplier.critchance * 0.01 * Math.floor ( perc < 500000 ? perc / 5000 : 50 + perc / 10000 ) ); } /** @@ -179,7 +163,7 @@ var idrinth = { } return value; } - _getSet() { + getSet() { return { perception: this.addPercProcs(this.addProcs ( this.addOnePerception ())) / this.stat.getCost ( this.stat.perception ), defense: this.addProcs ( this.addOneDefense ()) / this.stat.getCost ( this.stat.defense ), @@ -190,7 +174,7 @@ var idrinth = { * @return {Boolean} was modified */ increase () { - let data = this._getSet(); + let data = this.getSet(); let isBiggest = function(key, data) { for (let prop in data) { if(data[prop] > data[key]) { @@ -200,8 +184,8 @@ var idrinth = { return true; }; for (let key in data) { - if (isBiggest(key, data) && this.stats.getCost(this.stats[key]) < this.stats.stats) { - this.stats.increase(key); + if (isBiggest(key, data) && this.stat.getCost(this.stat[key]) < this.stat.stats) { + this.stat.increase(key); return true; } } @@ -215,7 +199,7 @@ var idrinth = { do { modified = this.increase(); } while ( modified ) - return stat; + return this.stat; } } }; \ No newline at end of file diff --git a/test/workers/stats.js b/test/workers/stats.js index 6858783..59eb45b 100644 --- a/test/workers/stats.js +++ b/test/workers/stats.js @@ -28,17 +28,17 @@ describe ( 'workers/stats.js', function ( ) { mount: 0, critchance: 5 }, { - attack: 1, + attack: 1000, defense: 1, perception: 1, - level: 1, - stats: 0 + stats: 1, + level: 1 } ] ].forEach(function(set) { - /*it ('Case '+JSON.stringify(set[0])+' should return '+JSON.stringify(set[1]), function() { - idrinth.work(set[0]).should.be.equal.to(set[1]); - });*/ + it ('Case '+JSON.stringify(set[0])+' should return '+JSON.stringify(set[1]), function() { + idrinth.work(set[0]).should.be.deep.equal(set[1]); + }); }); }); } ); @@ -49,11 +49,25 @@ describe ( 'workers/stats.js', function ( ) { describe( 'idrinth.PremiumSet', function( ) { it ( 'PremiumSet should be a function', function ( ) { idrinth.PremiumSet.should.be.a( 'function' ); - describe ( 'idrinth.PremiumSet#Instance', function ( ) { - var premium = new idrinth.PremiumSet( ); + describe ( 'idrinth.PremiumSet()', function ( ) { + var premium = new idrinth.PremiumSet( 'u', 'm', 'k' ); it ( 'PremiumSet should return an object', function ( ) { should.exist( premium ); premium.should.be.an( 'object' ); + describe ('idrinth.PremiumSet#Instance', function() { + it ('PremiumSet should have a mirele property', function () { + expect(premium).to.have.property('mirele'); + premium.mirele.should.be.equal('m'); + }); + it ('PremiumSet should have a utym property', function () { + expect(premium).to.have.property('utym'); + premium.utym.should.be.equal('u'); + }); + it ('PremiumSet should have a kraken property', function () { + expect(premium).to.have.property('kraken'); + premium.kraken.should.be.equal('k'); + }); + }); } ); } ); } ); @@ -64,11 +78,25 @@ describe ( 'workers/stats.js', function ( ) { describe ( 'idrinth.MultiplierSet', function ( ) { it ( 'MultiplierSet should be a function', function ( ) { idrinth.MultiplierSet.should.be.a( 'function' ); - describe ( 'idrinth.MultiplierSet#Instance', function ( ) { - var multiplier = new idrinth.MultiplierSet( ); + describe ( 'idrinth.MultiplierSet()', function ( ) { + var multiplier = new idrinth.MultiplierSet( 'l', 'm', 'c'); it ( 'MultiplierSet should return an object', function ( ) { should.exist( multiplier ); multiplier.should.be.an( 'object' ); + describe ('idrinth.MultiplierSet#Instance', function() { + it ('MultiplierSet should have a mount property', function () { + expect(multiplier).to.have.property('mount'); + multiplier.mount.should.be.equal('m'); + }); + it ('MultiplierSet should have a critchance property', function () { + expect(multiplier).to.have.property('critchance'); + multiplier.critchance.should.be.equal('c'); + }); + it ('MultiplierSet should have a legion property', function () { + expect(multiplier).to.have.property('legion'); + multiplier.legion.should.be.equal('l'); + }); + }); } ); } ); } ); @@ -79,11 +107,41 @@ describe ( 'workers/stats.js', function ( ) { describe ( 'idrinth.StatSet', function ( ) { it ( 'StatSet should be a function', function ( ) { idrinth.StatSet.should.be.a( 'function' ); - describe ( 'idrinth.StatSet#Instance', function ( ) { - var stat = new idrinth.StatSet( ); + describe ( 'idrinth.StatSet()', function ( ) { + var stat = new idrinth.StatSet( 'a', 'd', 'p', 'l', 's' ); it ( 'StatSet should return an object', function ( ) { should.exist( stat ); stat.should.be.an( 'object' ); + describe ('idrinth.StatSet#Instance', function() { + it ('StatSet should have an attack property', function () { + expect(stat).to.have.property('attack'); + stat.attack.should.be.equal('a'); + }); + it ('StatSet should have an defense property', function () { + expect(stat).to.have.property('defense'); + stat.defense.should.be.equal('d'); + }); + it ('StatSet should have an perception property', function () { + expect(stat).to.have.property('perception'); + stat.perception.should.be.equal('p'); + }); + it ('StatSet should have an level property', function () { + expect(stat).to.have.property('level'); + stat.level.should.be.equal('l'); + }); + it ('StatSet should have an stats property', function () { + expect(stat).to.have.property('stats'); + stat.stats.should.be.equal('s'); + }); + it ('StatSet should have an increase property', function () { + expect(stat).to.have.property('increase'); + // @todo test + }); + it ('StatSet should have an getCost property', function () { + expect(stat).to.have.property('getCost'); + // @todo test + }); + }); } ); } ); } ); @@ -94,11 +152,26 @@ describe ( 'workers/stats.js', function ( ) { describe ( 'idrinth.Calculator', function ( ) { it ( 'Calculator should be a function', function ( ) { idrinth.Calculator.should.be.a( 'function' ); - describe ( 'idrinth.Calculator#Instance', function ( ) { - var calculator = new idrinth.Calculator( ); + describe ( 'idrinth.Calculator()', function ( ) { + var calculator = new idrinth.Calculator( 'stat', 'premium', 'multiplier'); it ( 'Calculator should return an object', function ( ) { should.exist( calculator ); calculator.should.be.an( 'object' ); + describe ('idrinth.Calculator#Instance', function() { + it ('Calculator should have an stat property', function () { + expect(calculator).to.have.property('stat'); + calculator.stat.should.be.equal('stat'); + }); + it ('Calculator should have an premium property', function () { + expect(calculator).to.have.property('premium'); + calculator.premium.should.be.equal('premium'); + }); + it ('Calculator should have an multiplier property', function () { + expect(calculator).to.have.property('multiplier'); + calculator.multiplier.should.be.equal('multiplier'); + }); + //@todo method tests + }); } ); } ); } );