Skip to content

Commit

Permalink
test: card test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchen committed Apr 19, 2021
1 parent ed90b3c commit 93ab639
Show file tree
Hide file tree
Showing 12 changed files with 1,484 additions and 64 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ jobs:
node-version: ${{ matrix.node }}
- name: Install modules
run: yarn --ignore-optional
- name: Run devSettings check
run: yarn devsettingscheck
- name: Run tests
run: yarn test
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
. "$(dirname "$0")/_/husky.sh"
. "$(dirname "$0")/common.sh"

npm run devsettingscheck
npm run test
134 changes: 134 additions & 0 deletions __test__/cards.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import cards from '../src/data/cards'
import cardsbk from './cardsbk'
import { PersonStatusType } from '../src/types/state'

const dummyStatus1: PersonStatusType = {
bricks: 3,
gems: 0,
recruits: 6,
brickProd: 8,
gemProd: 9,
recruitProd: 11,
tower: 12,
wall: 0,
}

const dummyStatus2: PersonStatusType = {
bricks: 0,
gems: 4,
recruits: 2,
brickProd: 11,
gemProd: 6,
recruitProd: 8,
tower: 1,
wall: 2,
}

const dummyStatus3: PersonStatusType = {
bricks: 8,
gems: 13,
recruits: 6,
brickProd: 2,
gemProd: 3,
recruitProd: 6,
tower: 20,
wall: 2,
}

it('None of the cards is modified', () => {
cards.forEach((card, i) => {
const cardbk = cardsbk[i]
const { effect: e1, ...cardRest } = card
const { effect: e2, ...cardsbkRest } = cardbk
expect(cardRest).toStrictEqual(cardsbkRest)

let p1, o1, p2, o2

// dummyStatus2 vs dummyStatus1

p1 = { ...dummyStatus2 }
o1 = { ...dummyStatus1 }
e1(p1, o1)
p2 = { ...dummyStatus2 }
o2 = { ...dummyStatus1 }
e2(p2, o2)
expect(o1).toStrictEqual(o2)
expect(p1).toStrictEqual(p2)

expect(p1.bricks >= 0).toBeTruthy()
expect(p1.gems >= 0).toBeTruthy()
expect(p1.recruits >= 0).toBeTruthy()
expect(p1.brickProd >= 1).toBeTruthy()
expect(p1.gemProd >= 1).toBeTruthy()
expect(p1.recruitProd >= 1).toBeTruthy()
expect(p1.tower >= 0).toBeTruthy()
expect(p1.wall >= 0).toBeTruthy()

expect(o1.bricks >= 0).toBeTruthy()
expect(o1.gems >= 0).toBeTruthy()
expect(o1.recruits >= 0).toBeTruthy()
expect(o1.brickProd >= 1).toBeTruthy()
expect(o1.gemProd >= 1).toBeTruthy()
expect(o1.recruitProd >= 1).toBeTruthy()
expect(o1.tower >= 0).toBeTruthy()
expect(o1.wall >= 0).toBeTruthy()

// dummyStatus1 vs dummyStatus2

p1 = { ...dummyStatus1 }
o1 = { ...dummyStatus2 }
e1(p1, o1)
p2 = { ...dummyStatus1 }
o2 = { ...dummyStatus2 }
e2(p2, o2)
expect(o1).toStrictEqual(o2)
expect(p1).toStrictEqual(p2)

expect(p1.bricks >= 0).toBeTruthy()
expect(p1.gems >= 0).toBeTruthy()
expect(p1.recruits >= 0).toBeTruthy()
expect(p1.brickProd >= 1).toBeTruthy()
expect(p1.gemProd >= 1).toBeTruthy()
expect(p1.recruitProd >= 1).toBeTruthy()
expect(p1.tower >= 0).toBeTruthy()
expect(p1.wall >= 0).toBeTruthy()

expect(o1.bricks >= 0).toBeTruthy()
expect(o1.gems >= 0).toBeTruthy()
expect(o1.recruits >= 0).toBeTruthy()
expect(o1.brickProd >= 1).toBeTruthy()
expect(o1.gemProd >= 1).toBeTruthy()
expect(o1.recruitProd >= 1).toBeTruthy()
expect(o1.tower >= 0).toBeTruthy()
expect(o1.wall >= 0).toBeTruthy()

// dummyStatus2 vs dummyStatus3

p1 = { ...dummyStatus2 }
o1 = { ...dummyStatus3 }
e1(p1, o1)
p2 = { ...dummyStatus2 }
o2 = { ...dummyStatus3 }
e2(p2, o2)
expect(o1).toStrictEqual(o2)
expect(p1).toStrictEqual(p2)

expect(p1.bricks >= 0).toBeTruthy()
expect(p1.gems >= 0).toBeTruthy()
expect(p1.recruits >= 0).toBeTruthy()
expect(p1.brickProd >= 1).toBeTruthy()
expect(p1.gemProd >= 1).toBeTruthy()
expect(p1.recruitProd >= 1).toBeTruthy()
expect(p1.tower >= 0).toBeTruthy()
expect(p1.wall >= 0).toBeTruthy()

expect(o1.bricks >= 0).toBeTruthy()
expect(o1.gems >= 0).toBeTruthy()
expect(o1.recruits >= 0).toBeTruthy()
expect(o1.brickProd >= 1).toBeTruthy()
expect(o1.gemProd >= 1).toBeTruthy()
expect(o1.recruitProd >= 1).toBeTruthy()
expect(o1.tower >= 0).toBeTruthy()
expect(o1.wall >= 0).toBeTruthy()
})
})
Loading

0 comments on commit 93ab639

Please sign in to comment.