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

Commit 5970c0e

Browse files
committed
fixing typos
adding basic functionality test
1 parent 3a1f878 commit 5970c0e

2 files changed

Lines changed: 102 additions & 45 deletions

File tree

src/workers/stats.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ var idrinth = {
88
*/
99
work: function ( data ) {
1010
let calc = new idrinth.Calculator (
11-
new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ),
12-
new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ),
13-
new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance )
14-
);
11+
new idrinth.StatSet ( data.attack, data.defense, data.perception, data.level, data.stats ),
12+
new idrinth.PremiumSet ( data.utym, data.mirele, data.kraken ),
13+
new idrinth.MultiplierSet ( data.legion, data.mount, data.critchance )
14+
);
1515
return calc.calculate ();
1616
},
1717
/**
@@ -90,22 +90,6 @@ var idrinth = {
9090
let modifier = 10000 + Math.floor ( toPositive ( this.level / 500 - 2 ) ) * 1500;
9191
return 1 + Math.ceil ( toPositive ( value - modifier ) / 1500 );
9292
}
93-
/**
94-
* @return {Array}
95-
*/
96-
getIncreaseableStats () {
97-
let stats = [ ];
98-
if ( this.getCost ( this.attack ) <= this.stats ) {
99-
stats.push ( 'attack' );
100-
}
101-
if ( this.getCost ( this.defense ) <= this.stats ) {
102-
stats.push ( 'defense' );
103-
}
104-
if ( this.getCost ( this.perception ) <= this.stats ) {
105-
stats.push ( 'perception' );
106-
}
107-
return stats;
108-
}
10993
},
11094
/**
11195
* @class Actual logic for stat calculation
@@ -119,7 +103,7 @@ var idrinth = {
119103
* @param {idrinth.MultiplierSet} multiplier
120104
* @return {StatSet}
121105
*/
122-
construct ( stat, premium, multiplier ) {
106+
constructor ( stat, premium, multiplier ) {
123107
this.stat = stat;
124108
this.premium = premium;
125109
this.multiplier = multiplier;
@@ -131,15 +115,15 @@ var idrinth = {
131115
if (! this.premium.mirele ) {
132116
return 0;
133117
}
134-
return 1.8 * ( this.stats.perception <= 10000 ? 10 : 35 ) * this.multipliers.legion;
118+
return 1.8 * ( this.stat.perception <= 10000 ? 10 : 35 ) * this.multipliers.legion;
135119
}
136120
/**
137121
* @returns {Number}
138122
*/
139123
addOneAttack () {
140124
let base = 4;
141125
if ( this.premium.utym ) {
142-
base += ( this.stats.attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
126+
base += ( this.stat.attack <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
143127
}
144128
return base;
145129
}
@@ -149,10 +133,10 @@ var idrinth = {
149133
addOneDefense () {
150134
let base = 1;
151135
if ( this.premium.utym ) {
152-
base += ( this.stats.defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
136+
base += ( this.stat.defense <= 10000 ? 0.1 : 1 / 35 ) * 1.8 * this.multiplier.legion;
153137
}
154138
if ( this.premium.kraken ) {
155-
base += ( this.stats.defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this.multiplier.legion;
139+
base += ( this.stat.defense <= 10000 ? 0.2 : 0.01 ) * 1.8 * this.multiplier.legion;
156140
}
157141
return base;
158142
}
@@ -162,7 +146,7 @@ var idrinth = {
162146
* @returns {Number}
163147
*/
164148
addProcs ( value ) {
165-
let perc = this.stats.perception + 1;
149+
let perc = this.stat.perception + 1;
166150
return value * ( 1 + this.multiplier.mount + this.multiplier.critchance * 0.01 * Math.floor ( perc < 500000 ? perc / 5000 : 50 + perc / 10000 ) );
167151
}
168152
/**
@@ -179,7 +163,7 @@ var idrinth = {
179163
}
180164
return value;
181165
}
182-
_getSet() {
166+
getSet() {
183167
return {
184168
perception: this.addPercProcs(this.addProcs ( this.addOnePerception ())) / this.stat.getCost ( this.stat.perception ),
185169
defense: this.addProcs ( this.addOneDefense ()) / this.stat.getCost ( this.stat.defense ),
@@ -190,7 +174,7 @@ var idrinth = {
190174
* @return {Boolean} was modified
191175
*/
192176
increase () {
193-
let data = this._getSet();
177+
let data = this.getSet();
194178
let isBiggest = function(key, data) {
195179
for (let prop in data) {
196180
if(data[prop] > data[key]) {
@@ -200,8 +184,8 @@ var idrinth = {
200184
return true;
201185
};
202186
for (let key in data) {
203-
if (isBiggest(key, data) && this.stats.getCost(this.stats[key]) < this.stats.stats) {
204-
this.stats.increase(key);
187+
if (isBiggest(key, data) && this.stat.getCost(this.stat[key]) < this.stat.stats) {
188+
this.stat.increase(key);
205189
return true;
206190
}
207191
}
@@ -215,7 +199,7 @@ var idrinth = {
215199
do {
216200
modified = this.increase();
217201
} while ( modified )
218-
return stat;
202+
return this.stat;
219203
}
220204
}
221205
};

test/workers/stats.js

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ describe ( 'workers/stats.js', function ( ) {
2828
mount: 0,
2929
critchance: 5
3030
}, {
31-
attack: 1,
31+
attack: 1000,
3232
defense: 1,
3333
perception: 1,
34-
level: 1,
35-
stats: 0
34+
stats: 1,
35+
level: 1
3636
}
3737
]
3838
].forEach(function(set) {
39-
/*it ('Case '+JSON.stringify(set[0])+' should return '+JSON.stringify(set[1]), function() {
40-
idrinth.work(set[0]).should.be.equal.to(set[1]);
41-
});*/
39+
it ('Case '+JSON.stringify(set[0])+' should return '+JSON.stringify(set[1]), function() {
40+
idrinth.work(set[0]).should.be.deep.equal(set[1]);
41+
});
4242
});
4343
});
4444
} );
@@ -49,11 +49,25 @@ describe ( 'workers/stats.js', function ( ) {
4949
describe( 'idrinth.PremiumSet', function( ) {
5050
it ( 'PremiumSet should be a function', function ( ) {
5151
idrinth.PremiumSet.should.be.a( 'function' );
52-
describe ( 'idrinth.PremiumSet#Instance', function ( ) {
53-
var premium = new idrinth.PremiumSet( );
52+
describe ( 'idrinth.PremiumSet()', function ( ) {
53+
var premium = new idrinth.PremiumSet( 'u', 'm', 'k' );
5454
it ( 'PremiumSet should return an object', function ( ) {
5555
should.exist( premium );
5656
premium.should.be.an( 'object' );
57+
describe ('idrinth.PremiumSet#Instance', function() {
58+
it ('PremiumSet should have a mirele property', function () {
59+
expect(premium).to.have.property('mirele');
60+
premium.mirele.should.be.equal('m');
61+
});
62+
it ('PremiumSet should have a utym property', function () {
63+
expect(premium).to.have.property('utym');
64+
premium.utym.should.be.equal('u');
65+
});
66+
it ('PremiumSet should have a kraken property', function () {
67+
expect(premium).to.have.property('kraken');
68+
premium.kraken.should.be.equal('k');
69+
});
70+
});
5771
} );
5872
} );
5973
} );
@@ -64,11 +78,25 @@ describe ( 'workers/stats.js', function ( ) {
6478
describe ( 'idrinth.MultiplierSet', function ( ) {
6579
it ( 'MultiplierSet should be a function', function ( ) {
6680
idrinth.MultiplierSet.should.be.a( 'function' );
67-
describe ( 'idrinth.MultiplierSet#Instance', function ( ) {
68-
var multiplier = new idrinth.MultiplierSet( );
81+
describe ( 'idrinth.MultiplierSet()', function ( ) {
82+
var multiplier = new idrinth.MultiplierSet( 'l', 'm', 'c');
6983
it ( 'MultiplierSet should return an object', function ( ) {
7084
should.exist( multiplier );
7185
multiplier.should.be.an( 'object' );
86+
describe ('idrinth.MultiplierSet#Instance', function() {
87+
it ('MultiplierSet should have a mount property', function () {
88+
expect(multiplier).to.have.property('mount');
89+
multiplier.mount.should.be.equal('m');
90+
});
91+
it ('MultiplierSet should have a critchance property', function () {
92+
expect(multiplier).to.have.property('critchance');
93+
multiplier.critchance.should.be.equal('c');
94+
});
95+
it ('MultiplierSet should have a legion property', function () {
96+
expect(multiplier).to.have.property('legion');
97+
multiplier.legion.should.be.equal('l');
98+
});
99+
});
72100
} );
73101
} );
74102
} );
@@ -79,11 +107,41 @@ describe ( 'workers/stats.js', function ( ) {
79107
describe ( 'idrinth.StatSet', function ( ) {
80108
it ( 'StatSet should be a function', function ( ) {
81109
idrinth.StatSet.should.be.a( 'function' );
82-
describe ( 'idrinth.StatSet#Instance', function ( ) {
83-
var stat = new idrinth.StatSet( );
110+
describe ( 'idrinth.StatSet()', function ( ) {
111+
var stat = new idrinth.StatSet( 'a', 'd', 'p', 'l', 's' );
84112
it ( 'StatSet should return an object', function ( ) {
85113
should.exist( stat );
86114
stat.should.be.an( 'object' );
115+
describe ('idrinth.StatSet#Instance', function() {
116+
it ('StatSet should have an attack property', function () {
117+
expect(stat).to.have.property('attack');
118+
stat.attack.should.be.equal('a');
119+
});
120+
it ('StatSet should have an defense property', function () {
121+
expect(stat).to.have.property('defense');
122+
stat.defense.should.be.equal('d');
123+
});
124+
it ('StatSet should have an perception property', function () {
125+
expect(stat).to.have.property('perception');
126+
stat.perception.should.be.equal('p');
127+
});
128+
it ('StatSet should have an level property', function () {
129+
expect(stat).to.have.property('level');
130+
stat.level.should.be.equal('l');
131+
});
132+
it ('StatSet should have an stats property', function () {
133+
expect(stat).to.have.property('stats');
134+
stat.stats.should.be.equal('s');
135+
});
136+
it ('StatSet should have an increase property', function () {
137+
expect(stat).to.have.property('increase');
138+
// @todo test
139+
});
140+
it ('StatSet should have an getCost property', function () {
141+
expect(stat).to.have.property('getCost');
142+
// @todo test
143+
});
144+
});
87145
} );
88146
} );
89147
} );
@@ -94,11 +152,26 @@ describe ( 'workers/stats.js', function ( ) {
94152
describe ( 'idrinth.Calculator', function ( ) {
95153
it ( 'Calculator should be a function', function ( ) {
96154
idrinth.Calculator.should.be.a( 'function' );
97-
describe ( 'idrinth.Calculator#Instance', function ( ) {
98-
var calculator = new idrinth.Calculator( );
155+
describe ( 'idrinth.Calculator()', function ( ) {
156+
var calculator = new idrinth.Calculator( 'stat', 'premium', 'multiplier');
99157
it ( 'Calculator should return an object', function ( ) {
100158
should.exist( calculator );
101159
calculator.should.be.an( 'object' );
160+
describe ('idrinth.Calculator#Instance', function() {
161+
it ('Calculator should have an stat property', function () {
162+
expect(calculator).to.have.property('stat');
163+
calculator.stat.should.be.equal('stat');
164+
});
165+
it ('Calculator should have an premium property', function () {
166+
expect(calculator).to.have.property('premium');
167+
calculator.premium.should.be.equal('premium');
168+
});
169+
it ('Calculator should have an multiplier property', function () {
170+
expect(calculator).to.have.property('multiplier');
171+
calculator.multiplier.should.be.equal('multiplier');
172+
});
173+
//@todo method tests
174+
});
102175
} );
103176
} );
104177
} );

0 commit comments

Comments
 (0)