Skip to content

Instantly share code, notes, and snippets.

@guiferrpereira
Last active October 20, 2017 10:57
Show Gist options
  • Save guiferrpereira/d6a7502298c8583b8faf41990bbe08ed to your computer and use it in GitHub Desktop.
Save guiferrpereira/d6a7502298c8583b8faf41990bbe08ed to your computer and use it in GitHub Desktop.
NDrive Code Challenge
Please send a zip archive containing your code and any relevant materials in an email along with your resume and motivations to jobs@ndrive.com, please add vitor.magalhaes@ndrive.com in CC.
The purpose of this test is not to see you're fast! Intead we want to verify your abilities to code and see how you architecture an application, so this is the time to show everything you know that is applicable and relevant (design pattern, OOP concepts, tests, etc.)
NDrive's quest for global domination has prompted us to open a store - we sell only three products:
```
+---------------|------------------------------|---------+
| Product Code | Name | Price |
+---------------|------------------------------|---------+
| 1M_TRAF | Traffic Service (1 Month) | €3.11 |
| 3M_SP_C | Speed Cameras (3 Months) | €5.00 |
| MAP_EUR | Europe Map | €11.23 |
+---------------|------------------------------|---------+
```
Our CEO is a big fan of buy-one-get-one-free offers and of "Traffic Service (1 Month)". He wants us to add a rule to do this.
The COO, though, likes low prices and wants people buying "Speed Cameras (3 Months)" to get a price
discount for bulk purchases. If you buy 3 or more Speed Cameras, the price should drop to €4.50.
Our check-out can scan items in any order, and because the CEO and COO change
their minds often, it needs to be flexible regarding our pricing rules.
The interface to our checkout looks like this (shown in Ruby):
```
co = Checkout.new(pricing_rules)
co.scan(item)
co.scan(item)
price = co.total
```
Implement a checkout system that fulfils these requirements in Ruby.
Here are some test data:
```
Basket: 1M_TRAF, 3M_SP_C, 1M_TRAF, MAP_EUR
Total price expected: €19.34
```
```
Basket: 1M_TRAF, 1M_TRAF
Total price expected: €3.11
```
```
Basket: 3M_SP_C, 3M_SP_C, 1M_TRAF, 3M_SP_C
Total price expected: €16.61
```
PS: Here at NDrive, we love tests ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment