Skip to content
This repository was archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
fixing typos
Browse files Browse the repository at this point in the history
adding basic functionality test
  • Loading branch information
Idrinth committed May 31, 2018
1 parent 3a1f878 commit 5970c0e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 45 deletions.
46 changes: 15 additions & 31 deletions src/workers/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
},
/**
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -131,15 +115,15 @@ 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}
*/
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;
}
Expand All @@ -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;
}
Expand All @@ -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 ) );
}
/**
Expand All @@ -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 ),
Expand All @@ -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]) {
Expand All @@ -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;
}
}
Expand All @@ -215,7 +199,7 @@ var idrinth = {
do {
modified = this.increase();
} while ( modified )
return stat;
return this.stat;
}
}
};
101 changes: 87 additions & 14 deletions test/workers/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});
});
} );
Expand All @@ -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');
});
});
} );
} );
} );
Expand All @@ -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');
});
});
} );
} );
} );
Expand All @@ -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
});
});
} );
} );
} );
Expand All @@ -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
});
} );
} );
} );
Expand Down

0 comments on commit 5970c0e

Please sign in to comment.