Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for existing behaviors of breed and fertilize
This will ensure refactoring of reducers doesn't affect these actions
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import expect from 'expect'; | ||
import * as actions from '../../src/code/actions'; | ||
import reducer from '../../src/code/reducers/'; | ||
|
||
const types = actions.actionTypes; | ||
|
||
describe('breedClutch action', () => { | ||
it('should create an action for breeding a clutch', () => { | ||
expect(actions.breedClutch(20)).toEqual({ | ||
type: types.CLUTCH_BRED, | ||
clutchSize: 20 | ||
}); | ||
}); | ||
|
||
describe('the reducer', () => { | ||
it('should add 20 new drakes', () => { | ||
let defaultState = reducer(undefined, {}); | ||
let initialState = defaultState.set("drakes", [ | ||
{ alleleString: "a:T,b:T", sex: 0 }, | ||
{ alleleString: "a:t,b:t", sex: 1 } | ||
]); | ||
|
||
let nextState = reducer(initialState, { | ||
type: types.CLUTCH_BRED, | ||
clutchSize: 20 | ||
}); | ||
|
||
expect(nextState.drakes.length).toEqual(22); | ||
}); | ||
|
||
it('should create offspring from the parent drakes', () => { | ||
let defaultState = reducer(undefined, {}); | ||
let initialState = defaultState.set("drakes", [ | ||
{ alleleString: "a:T,b:T", sex: 0 }, | ||
{ alleleString: "a:t,b:t", sex: 1 } | ||
]); | ||
|
||
let nextState = reducer(initialState, { | ||
type: types.CLUTCH_BRED, | ||
clutchSize: 20 | ||
}); | ||
|
||
for (let i = 2; i < 22; i++) { | ||
expect(nextState.drakes[i].alleleString.indexOf("a:T,b:t")).toBeGreaterThan(-1); | ||
} | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import expect from 'expect'; | ||
import * as actions from '../../src/code/actions'; | ||
import reducer from '../../src/code/reducers/'; | ||
|
||
const types = actions.actionTypes; | ||
|
||
describe('fertilize action', () => { | ||
it('should create an action for fertilizing', () => { | ||
expect(actions.fertilize(0, 1)).toEqual({ | ||
type: types.FERTILIZED, | ||
gamete1: 0, | ||
gamete2: 1 | ||
}); | ||
}); | ||
|
||
describe('the reducer', () => { | ||
it('should breed a new drake given the gametes', () => { | ||
let defaultState = reducer(undefined, {}); | ||
let initialState = defaultState.merge({ | ||
drakes: [ | ||
{ alleleString: "a:t,b:T,a:m,b:M,a:w,b:W,a:h,b:H,a:c,b:C,a:b,b:B,a:fl,b:Fl,a:hl,b:Hl,a:a,b:A1,a:d,b:D,a:bog,b:Bog,a:Rh,b:rh", sex: 1 }, | ||
{ alleleString: "a:T,b:t,a:M,b:m,a:W,b:w,a:H,b:h,a:C,b:c,a:B,b:b,a:Fl,b:fl,a:Hl,b:hl,a:A1,b:A2,a:D,a:Bog,a:rh", sex: 0 } | ||
], | ||
gametes: { | ||
currentGametes: [ | ||
{ | ||
'1': 'a', | ||
'2': 'b', | ||
XY: 'y' | ||
}, | ||
{ | ||
'1': 'b', | ||
'2': 'b', | ||
XY: 'x2' | ||
} | ||
] | ||
} | ||
}); | ||
|
||
let nextState = reducer(initialState, { | ||
type: types.FERTILIZED, | ||
gamete1: 0, | ||
gamete2: 1 | ||
}); | ||
|
||
let offspring = nextState.drakes[2]; | ||
|
||
expect(offspring.sex).toEqual(0); | ||
expect(offspring.alleleString).toEqual("a:T,a:M,a:W,a:H,a:C,a:B,a:Fl,a:Hl,a:A1,a:D,a:Bog,a:rh,b:T,b:M,b:W,b:H,b:c,b:b,b:fl,b:hl,b:A2,"); | ||
}); | ||
}); | ||
|
||
}); |