Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
added test function
Browse files Browse the repository at this point in the history
  • Loading branch information
jaebradley committed May 22, 2016
1 parent e5265da commit 6c0f6a2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/data/models/GameBoxScoreLeaders.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use es6';

import {Record} from 'immutable';
import TeamBoxScoreLeaders from './TeamBoxScoreLeaders';

const defaults = {
home : new TeamBoxScoreLeaders(),
home: new TeamBoxScoreLeaders(),
visitor: new TeamBoxScoreLeaders(),
};

Expand Down
2 changes: 2 additions & 0 deletions src/data/models/TeamBoxScoreLeaders.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use es6';

import {Record} from 'immutable';
import StatisticalLeaders from './StatisticalLeaders';

Expand Down
3 changes: 1 addition & 2 deletions src/translators/data/BoxScoreDataTranslator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Player from '../../data/models/Player';
export default class BoxScoreDataTranslator {
static translateStatLeaders(leaderData) {
const leaders = leaderData.leader.map(leader => new Player({firstName: leader.FirstName, lastName: leader.LastName}));
return new StatisticalLeaders({value: leaderData.StatValue, leaders: leaders});
return new StatisticalLeaders({value: parseInt(leaderData.StatValue), leaders: leaders});
}

static translateBoxScoreData(data) {
Expand Down Expand Up @@ -57,7 +57,6 @@ export default class BoxScoreDataTranslator {
assists: homeAssistsLeaders,
rebounds: homeReboundsLeaders,
});

return new GameBoxScoreLeaders({home: homeBoxScoreLeaders, visitor: visitorBoxScoreLeaders});
}
}
58 changes: 56 additions & 2 deletions test/BoxScoreDataTranslator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use es6';

import {expect} from 'chai';
import {expect, assert} from 'chai';
import BoxScoreDataTranslator from '../src/translators/data/BoxScoreDataTranslator';
import GameBoxScoreLeaders from '../src/data/models/GameBoxScoreLeaders';
import TeamBoxScoreLeaders from '../src/data/models/TeamBoxScoreLeaders';
Expand All @@ -13,6 +13,60 @@ import pregameBoxScore from './data/boxscore/pregame.json';

describe('Box score data translator', function() {
it('translate pregame box score data', function() {
expect(BoxScoreDataTranslator.translateBoxScoreData(pregameBoxScore)).to.eql(new GameBoxScoreLeaders());
assert.isOk(BoxScoreDataTranslator.translateBoxScoreData(pregameBoxScore).equals(new GameBoxScoreLeaders()), 'pregame box score and empty game box score leaders are equal');
});

it('translate first quarter box score data', function() {
const visitorPointsLeaders = new StatisticalLeaders({
value: 2,
leaders: [
new Player({firstName: 'Kevin', lastName: 'Durant'}),
new Player({firstName: 'Serge', lastName: 'Ibaka'}),
new Player({firstName: 'Andre', lastName: 'Roberson'}),
new Player({firstName: 'Steven', lastName: 'Adams'}),
]
});
const visitorAssistsLeaders = new StatisticalLeaders({
value: 2,
leaders: [new Player({firstName: 'Russell', lastName: 'Westbrook'})]
});
const visitorReboundsLeaders = new StatisticalLeaders({
value: 2,
leaders: [new Player({firstName: 'Steven', lastName: 'Adams'})]
})
const visitorBoxScoreLeaders = new TeamBoxScoreLeaders({
points: visitorPointsLeaders,
assists: visitorAssistsLeaders,
rebounds: visitorReboundsLeaders,
});

const homePointsLeaders = new StatisticalLeaders({
value: 4,
leaders: [new Player({firstName: 'Klay', lastName: 'Thompson'})]
});
const homeAssistsLeaders = new StatisticalLeaders({
value: 1,
leaders: [
new Player({firstName: 'Andrew', lastName: 'Bogut'}),
new Player({firstName: 'Stephen', lastName: 'Curry'}),
new Player({firstName: 'Draymond', lastName: 'Green'}),
]
});
const homeReboundsLeaders = new StatisticalLeaders({
value: 1,
leaders: [new Player({firstName: 'Draymond', lastName: 'Green'})]
})
const homeBoxScoreLeaders = new TeamBoxScoreLeaders({
points: homePointsLeaders,
assists: homeAssistsLeaders,
rebounds: homeReboundsLeaders,
});

const expected = new GameBoxScoreLeaders({home: homeBoxScoreLeaders, visitor: visitorBoxScoreLeaders});
expect(BoxScoreDataTranslator.translateBoxScoreData(firstQuarterBoxScore)).to.eql(expected);
});

it('translate first quarter stat leader', function() {

});
});

0 comments on commit 6c0f6a2

Please sign in to comment.