https://github.com/albertllousas/point-of-sale-kata-with-haskell
Point of sale kata with state monad
https://github.com/albertllousas/point-of-sale-kata-with-haskell
Last synced: about 2 months ago
JSON representation
Point of sale kata with state monad
- Host: GitHub
- URL: https://github.com/albertllousas/point-of-sale-kata-with-haskell
- Owner: albertllousas
- License: bsd-3-clause
- Created: 2022-11-02T12:33:08.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-01T16:46:53.000Z (about 2 years ago)
- Last Synced: 2025-01-30T22:48:25.763Z (4 months ago)
- Language: Haskell
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# point-of-sale-kata-with-haskell
Point of sale kata implementation, [here](https://github.com/albertllousas/point-of-sale-kata-definition) the problem statement.
## Tests
```haskell
spec :: Spec
spec = dolet chips = Product { code = "901234", name = "Chips", price = 1.50 }
let redBull = Product { code = "507780", name = "Red Bull", price = 2.35 }
let findProduct = buildFindProductInMemory (Map.fromList [("901234", chips), ("507780", redBull)])describe "Acceptance test" $ do
it "Point of sale should perform a sale with multiple products" $ do
let scan = buildScan findProduct
let result = do
scan "901234"
scan "901234"
scan "unknown"
scan "507780"
scan "507780"
remove "507780"
checkout
StateMonad.runState result emptyShoppingCart `shouldBe` (Display "5.35", ShoppingCart [redBull, chips, chips])
```
[All tests](test/PointOfSaleSpec.hs)```shell
> stack testPointOfSale
Acceptance test
Point of sale should perform a sale with multiple products
Point of sale
When a product is scanned, the price is displayed
When a scanned product is not present, a message 'invalid product' is displayed
When a scan succeed, product is added to the current digital shopping cart.
We can remove a product from the current cart by product-id, the price will be displayed in negative
If we can not remove a product from the current cart, a message 'invalid product' is displayed
When the sale is finished, the point of sale will check out, calculating the total price and displaying it
Product finder in memory implementation
Should find an existent product
Should not find a non existent productFinished in 0.0027 seconds
9 examples, 0 failures
```