Skip to content

Commit

Permalink
tests & minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Jun 29, 2017
1 parent d300230 commit efe9672
Show file tree
Hide file tree
Showing 6 changed files with 3,567 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- '6'
- '7'
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ const getPokeball = require('get-pokeball')

module.exports = async (catchRate, pokeball, f, statusAilment = 0) => {
if (typeof catchRate !== 'number') {
throw new TypeError('Catch Rate is required and should be a number.')
throw new TypeError('Catch Rate is required and should be a number')
}

if (typeof pokeball !== 'string') {
throw new TypeError('Pokeball is required and should be a string.')
throw new TypeError('Pokeball is required and should be a string')
}

if (typeof f !== 'number' || f > 255 || f < 1) {
throw new TypeError('f is required and should be a number.')
throw new TypeError('f is required and should be a number between 1-255')
}

const ball = await getPokeball(pokeball)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test": "xo && ava"
},
"dependencies": {
"get-pokeball": "^0.0.1",
"pokemon-f": "^0.0.1"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Options:

## Related

- [pokemon-game](https://github.com/bukinoshita/pokemon-game) — Pokemon game — Get 'em all
- [pokedex-api](https://github.com/bukinoshita/pokedex-api) — Pokedex API
- [pokemon-catch-probability](https://github.com/bukinoshita/pokemon-catch-probability) — Check probabilty to catch a pokemon
- [get-pokeball](https://github.com/bukinoshita/get-pokeball) — Get pokeball information
- [catch-pokemon](https://github.com/bukinoshita/catch-pokemon) — Algorithm to catch a pokemon
- [pokemon-capture-quote](https://github.com/bukinoshita/pokemon-capture-quote) — Pokemon capture quote
- [pokemon-f](https://github.com/bukinoshita/pokemon-f) — Algorithm to calculate `f` on capture pokemon method
Expand Down
43 changes: 43 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,46 @@ test(async t => {

t.is(await m(catchRate, 'pokeball', f), 1)
})

test('burned', async t => {
const catchRate = 163
const hpMax = 35
const hpCurrent = 29
const f = await pokemonF(hpMax, 'pokeball', hpCurrent)
t.is(await m(catchRate, 'pokeball', f, 12), 2)
})

test('frozen', async t => {
const catchRate = 163
const hpMax = 35
const hpCurrent = 29
const f = await pokemonF(hpMax, 'pokeball', hpCurrent)
t.is(await m(catchRate, 'pokeball', f, 25), 2)
})

test('catchRate error', async t => {
const catchRate = '163'
const hpMax = 35
const hpCurrent = 29
const f = await pokemonF(hpMax, 'pokeball', hpCurrent)
const error = await t.throws(m(catchRate, 'pokeball', f))

t.is(error.message, 'Catch Rate is required and should be a number')
})

test('pokeball error', async t => {
const catchRate = 163
const hpMax = 35
const hpCurrent = 29
const f = await pokemonF(hpMax, 'pokeball', hpCurrent)
const error = await t.throws(m(catchRate, 2, f))

t.is(error.message, 'Pokeball is required and should be a string')
})

test('f error', async t => {
const catchRate = 163
const error = await t.throws(m(catchRate, 'pokeball', 256))

t.is(error.message, 'f is required and should be a number between 1-255')
})
Loading

0 comments on commit efe9672

Please sign in to comment.