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

Commit

Permalink
#125: changed vars to this;
Browse files Browse the repository at this point in the history
  • Loading branch information
w20k committed Oct 11, 2016
1 parent 9329162 commit ec5e63b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/mods/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ idrinth.land = {
calculate: function () {
var baseCalculator = function ( checkElementFunc ) {
var factor = idrinth.settings.factor ? 10 : 1;
var results = { };
var nextPrice = function ( building ) {
return ( 10 + idrinth.settings.land[building] ) * idrinth.land.data[building].base;
};
var results = { };
var applyResult = function ( results, res, factor, nextPrice ) {
idrinth.settings.land.gold = idrinth.settings.land.gold - nextPrice ( res.key ) * factor / 10;
results[res.key] = ( results[res.key] === undefined ? 0 : results[res.key] ) + factor;
Expand All @@ -29,7 +29,7 @@ idrinth.land = {
min: null
};
for (var building in idrinth.land.data) {
if ( building && idrinth.land.data[building] && idrinth.land.data.hasOwnProperty ( building ) ) {
if ( building && idrinth.land.data.hasOwnProperty ( building ) && idrinth.land.data[building] ) {
res = check ( checkElementFunc, building, factor, res, nextPrice );
}
}
Expand Down
20 changes: 11 additions & 9 deletions tests/mods/landSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,23 @@ describe ( 'Land.js tests', function () {
describe ( "Land calculate method", function () {

beforeEach ( function () {
var mock = {},
defaultStructure = '{ "value": "", "parentNode": { "nextSibling": { "innerHTML": "" } } }',
document_getElementById;
document_getElementById = jasmine.createSpyObj ( "input", [ 'value', 'parentNode', 'nextSibling', 'innerHTML' ] );
this.mock = {};
this.defaultStructure = '{ "value": "", "parentNode": { "nextSibling": { "innerHTML": "" } } }';
this.document_getElementById = jasmine.createSpyObj ( "input", [ 'value', 'parentNode', 'nextSibling', 'innerHTML' ] );

for ( var i in idrinth.land.data ) {
if ( idrinth.land.data.hasOwnProperty ( i ) ) {
mock[ 'idrinth-land-' + i ] = JSON.parse ( defaultStructure );
this.mock[ 'idrinth-land-' + i ] = JSON.parse ( defaultStructure );
}
}
mock[ 'idrinth-land-gold' ] = { value: '' };
this.mock[ 'idrinth-land-gold' ] = { value: '' };

spyOn ( document, "getElementById" ).and.callFake ( function ( id ) {
if ( mock.hasOwnProperty ( id ) ) {
return mock[ id ];
if ( this.mock.hasOwnProperty ( id ) ) {
return this.mock[ id ];
}

return document_getElementById ( id );
return this.document_getElementById ( id );
} );

spyOn(idrinth.core, 'alert');
Expand All @@ -79,8 +78,11 @@ describe ( 'Land.js tests', function () {

it ( "Should properly calculate without errors", function () {
//Prepare values
idrinth.settings.land.gold = 8000000000;

idrinth.land.calculate ();


} );

} );
Expand Down

0 comments on commit ec5e63b

Please sign in to comment.