cash-machine-problem
v1.6.0
Published
an simple solution for a cash machine problem
Downloads
9
Maintainers
Readme
cash-machine-problem
a simple micro-library that develops a solution that simulates the delivery of notes when a client does a withdraw in a cash machine.
Requirements
- Always deliver the lowest number of possible notes
- It’s possible to get the amount requested with available notes
- The client balance is infinite
- Amount of notes is infinite
- Available notes 100,00, 50,00, 20,00, 10,00 $
Examples
- Entry: 30.00 Result: [20.00, 10.00]
- Entry: 80.00 Result: [50.00, 20.00, 10.00]
- Entry: 125.00 Result: throw NoteUnavailableException
- Entry: -130.00 Result: throw InvalidArgumentException
- Entry: NULL Result: [Empty Set]
Install
npm i cash-machine-problem
Install locally
git clone https://github.com/paschalidi/cash-machine-problem.git
cd cash-machine-problem
npm i
Watch Tests
npm run test
Run tests once
npm run test:single
Usage
import calculateNotes from 'cash-machine-problem'
// Returns an array of the lowest number of possible notes
calculateNotes(100)
//=> [100, 0, 0, 0]
calculateNotes(120)
//=> [100, 0, 20, 0]
calculateNotes(130)
//=> [100, 0, 20, 10]
...
API
calculateNotes([integer])
Returns an array of of 4 integers in the following format [x1, x2, x3, x4]
.
x1
represents the amount of $100.00 that the cash machine should return
x2
represents the amount of $50.00 that the cash machine should return
x3
represents the amount of $20.00 that the cash machine should return
x4
represents the amount of $10.00 that the cash machine should return
Architectural Notes
Automated releases with semantic-release-cli
We set up smeantic-release-cli with
semantic-release-cli setup
We chose
Travis CI
for continuous integrationWe added an extra script to
travis.yml
so that tests run before every release. This way if tests dont pass then the release wont happenWe also added
ghooks
so that before everycommit
tests run and any test failcommit
wont take place.
Testing
For testing we chose mocha
and chai
. There reason is the clean api they provide.
Code structure
src/index.js
contains the implementation of thecalculateNotes()
- exports a
default
function so that the end user can be able to specify the name of it herself/himself. - The tests are also included in the
src
directory.
Build process
When travis builds the lib the following comand is being executed
babel --copy-files --out-dir dist --ignore *.test.js src
.babel
will copy all the files from thesrc
directory into thedist
directory and will also convert them toes5
so that it is executable from every browser ornode
version needed. Also the test files are ignored so that the end user wont have them in her/hisnode_modules
directory.before every build the following script will run
rimraf dist
.This will remove the
dist
directory and will run the command for every operating system (Windows, iOS or Linux).More info about
rimraf
here.
Contributing
Angular's document for the contribution can be found here. Thanks :)