Skip to content

Golang Command Interface to compute the money return change given an amount, with some refactor

License

Notifications You must be signed in to change notification settings

jofaval/return-change-marchine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Return Change Machine

A classic example of the machine that returns change optimizing the amount of elements it gives for a given amount

Contents

  1. Using go
  2. Problem
  3. Testing
  4. Credits
  5. TODO

Using go

I'm a beginner in Go, so I thought of using this example as practice. I'll be trying to apply some minor optimizations/refactor than what I usually did

Problem

You'll be given a numeric input of the amount that needs the return from.
You should output how much of each element (5x1 dolar bills, 10x50 dolar bills, 2x1 cents, etc.)

The least return the better solution, the less code and more readable, the finer.

Testing

Given it's a small example with predefined best solutions, it'd be nice to clearly identify the possibilities.

Test Driven Development is a nice addition to this clear exercise.

Test with coverage

go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

Credits

To my teacher (Pilar) from whom I learned this exercise.
And to Chelo, a teacher that mentioned this as a technical challenge for some bussiness.

To this article Golang Import Local Package for explaining and providing helpful examples about import of local go packages.

TODO

  • Complete the base exercise
  • Use a map to compute the operations
  • Implement an amount for the change
    • Implement a smart amount for the change, meaning, if we can supply change by using lower value currency, that's still considered a good solution
  • Implement a (clearly defined) test set

About

Golang Command Interface to compute the money return change given an amount, with some refactor

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages