@planetguru/oddsconverter
v0.2.0
Published
convert odds between decimal and fractional formats
Downloads
12
Readme
Description
This is a small library to perform odds conversions. It provides the following functionality:
- Convert from decimal to fractional odds
- Convert from fractional to decimal odds
It also has the following utilities within it
- Simplify a fraction down to it's simplest top-heavy form
- Get the greatest common denominator from two submitted values
- Count the number of decimal places on a floating point value
Known bugs
All tests pass except for the one scenario of converting from 1.33 to 1/3. For some reason this test fails and I don't have the time now to figure out why - I mean the test itself is fine, but the implementation needs fixing, because the converter returns 1.33 as 33/100 which is technically the wrong result (by a tiny margin).
Unit tests
To run the unit tests, run the following $npm test
you should see output that resembles this:
@planetguru/[email protected] test /Users/christopherlacy-hulbert/lopment/javascript/oddsconverter
mocha
odds converter
convert fractional to decimal
✓ 4/3 converts to 2.33
convert fractional to decimal
✓ 4/3 converts to 2.33
convert decimal to fractional
✓ 3.25 converts to 9/4
convert decimal to fractional
✓ convert decimal odds
get greatest common denominator
✓ finds 25/150 GCD to be 25
✓ finds 10/145 GCD to be 5
Simplify fraction
✓ convert 50/100 to 1/2
Count decimal places
✓ counts 3 in 5.425
Count decimal places
✓ counts 0 in 543
Count decimal places
✓ counts 1 in 543.3
Count decimal places, exclude trailing zeros
✓ counts 1 in 543.300
11 passing (11ms)
If any tests are failing, they will also be reported. Please be sure to cover all functions with unit tests which exercise all happy path scenarios and some edge cases if you can think of any.