git.iko.soy/ikoHSE/sc-task-2
on master help sign in
Updated everything
f102b30iko
.gitignore+2−1
@@ -21,7 +21,8 @@ cabal.project.local
21cabal.project.local~
21cabal.project.local~
22.HTF/
22.HTF/
23.ghc.environment.*
23.ghc.environment.*
24−*.cabal
25.DS_Store
24.DS_Store
26.idea/
25.idea/
27*.dump-hi
26*.dump-hi
27+*.lock
28+*.iml
src/Task.hs+6−2
@@ -293,10 +293,12 @@ payForCoffee = error "TODO: payForCoffee"
293
293
294-- | This function should apply the chosen payment method to the customer.
294-- | This function should apply the chosen payment method to the customer.
295-- In other words, it needs to apply the charge to the customer himself
295-- In other words, it needs to apply the charge to the customer himself
296−-- (update the debit card or update the amout of cash he currently has)
296+-- (update the debit card or update the amount of cash he currently has)
297--
297--
298-- If the specified card is not present in the 'Customer' structure, then
298-- If the specified card is not present in the 'Customer' structure, then
299-- do nothing.
299-- do nothing.
300+--
301+-- NOTE: You can not change the order of the cards.
300applyPayment :: Customer -> PaymentMethod -> Customer
302applyPayment :: Customer -> PaymentMethod -> Customer
301applyPayment = error "TODO: applyPayment"
303applyPayment = error "TODO: applyPayment"
302
304
@@ -305,7 +307,7 @@ applyPayment = error "TODO: applyPayment"
305buyCoffee :: Customer -> Coffee -> Maybe Customer
307buyCoffee :: Customer -> Coffee -> Maybe Customer
306buyCoffee = error "TODO: buyCoffee"
308buyCoffee = error "TODO: buyCoffee"
307
309
308−-- | You know the due to a medical condition the customer needs to watch his
310+-- | You know that due to a medical condition the customer needs to watch his
309-- sugar intake. The new privacy-invading piece of ... technology can now
311-- sugar intake. The new privacy-invading piece of ... technology can now
310-- automatically apply filters to coffee orders.
312-- automatically apply filters to coffee orders.
311--
313--
@@ -314,6 +316,8 @@ buyCoffee = error "TODO: buyCoffee"
314-- return the filtered orders and the amount of money the customer saves by
316-- return the filtered orders and the amount of money the customer saves by
315-- being healthy (sugar costs money after all). So, you also have to count how
317-- being healthy (sugar costs money after all). So, you also have to count how
316-- much the total sugar would have cost.
318-- much the total sugar would have cost.
319+--
320+-- NOTE: You can not change the order of the coffee.
317saveTheDiabetic :: [Coffee] -> (RUBAmount, [Coffee])
321saveTheDiabetic :: [Coffee] -> (RUBAmount, [Coffee])
318saveTheDiabetic = error "TODO: saveTheDiabetic"
322saveTheDiabetic = error "TODO: saveTheDiabetic"
319
323
task.cabalnew file+39
@@ -0,0 +1,39 @@
1+cabal-version: 2.2
2+
3+-- This file has been generated from package.yaml by hpack version 0.31.2.
4+--
5+-- see: https://github.com/sol/hpack
6+--
7+-- hash: c454617de75af64ca6c743a3a745918472bb438f8df9c2019b67700d4caaf63c
8+
9+name: task
10+version: 0.1.0.0
11+license: Unlicense
12+license-file: LICENSE
13+build-type: Simple
14+
15+library
16+ exposed-modules:
17+ Task
18+ other-modules:
19+ Paths_task
20+ hs-source-dirs:
21+ src
22+ build-depends:
23+ base >=4.7 && <5
24+ default-language: Haskell2010
25+
26+test-suite task-tests
27+ type: exitcode-stdio-1.0
28+ main-is: Main.hs
29+ other-modules:
30+ Tests
31+ Paths_task
32+ hs-source-dirs:
33+ test
34+ build-depends:
35+ base >=4.7 && <5
36+ , task
37+ , tasty
38+ , tasty-hspec
39+ default-language: Haskell2010
test/Tests.hs+43−46
@@ -18,16 +18,16 @@ tests = do
18 getFirst [] `shouldBe` (Nothing :: Maybe ())
18 getFirst [] `shouldBe` (Nothing :: Maybe ())
19 getFirst [True, False] `shouldBe` Just True
19 getFirst [True, False] `shouldBe` Just True
20 getFirst [True, True, False] `shouldBe` Just True
20 getFirst [True, True, False] `shouldBe` Just True
21− getFirst [1 .. 1000] `shouldBe` Just 1
21+ getFirst [1 .. 1000] `shouldBe` Just (1 :: Int)
22− getFirst [100 .. 1000] `shouldBe` Just 100
22+ getFirst [100 .. 1000] `shouldBe` Just (100 :: Int)
23− getFirst [6, 2, 7, 398, 1984, 383, -1020] `shouldBe` Just 6
23+ getFirst [6, 2, 7, 398, 1984, 383, -1020] `shouldBe` Just (6 :: Int)
24 it "LastMonoid" $ do
24 it "LastMonoid" $ do
25 let getLast = destructLastMonoid . fold . fmap constructLastMonoid
25 let getLast = destructLastMonoid . fold . fmap constructLastMonoid
26 getLast [1 :: Int, 2, 3] `shouldBe` Just 3
26 getLast [1 :: Int, 2, 3] `shouldBe` Just 3
27 getLast [] `shouldBe` (Nothing :: Maybe ())
27 getLast [] `shouldBe` (Nothing :: Maybe ())
28− getLast [1 .. 1000] `shouldBe` Just 1000
28+ getLast [1 .. 1000] `shouldBe` Just (1000 :: Int)
29− getLast [100 .. 10000] `shouldBe` Just 10000
29+ getLast [100 .. 10000] `shouldBe` Just (10000 :: Int)
30− getLast [6, 2, 7, 398, 1984, 383, -1020, 498] `shouldBe` Just 498
30+ getLast [6, 2, 7, 398, 1984, 383, -1020, 498] `shouldBe` Just (498 :: Int)
31 getLast [True, False] `shouldBe` Just False
31 getLast [True, False] `shouldBe` Just False
32 getLast [True, True, False] `shouldBe` Just False
32 getLast [True, True, False] `shouldBe` Just False
33 getLast [True, True, False, True] `shouldBe` Just True
33 getLast [True, True, False, True] `shouldBe` Just True
@@ -60,7 +60,6 @@ tests = do
60 ]
60 ]
61 )
61 )
62 `shouldBe` [ [(NotCompleted, "AAAAAAAAAA")],
62 `shouldBe` [ [(NotCompleted, "AAAAAAAAAA")],
63− [],
64 [(NotCompleted, "a")]
63 [(NotCompleted, "a")]
65 ]
64 ]
66 getPrioritySets
65 getPrioritySets
@@ -144,7 +143,7 @@ tests = do
144 )
143 )
145 `shouldBe` [ [(NotCompleted, "OH NO")],
144 `shouldBe` [ [(NotCompleted, "OH NO")],
146 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
145 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
147− [(Completed, "a")]
146+ [(NotCompleted, "a")]
148 ]
147 ]
149 getPrioritySets
148 getPrioritySets
150 ( removeTask "AAAAAAAAAA" . removeTask "AAAAAAAAAA"
149 ( removeTask "AAAAAAAAAA" . removeTask "AAAAAAAAAA"
@@ -158,7 +157,7 @@ tests = do
158 )
157 )
159 `shouldBe` [ [(NotCompleted, "OH NO")],
158 `shouldBe` [ [(NotCompleted, "OH NO")],
160 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
159 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
161− [(Completed, "a")]
160+ [(NotCompleted, "a")]
162 ]
161 ]
163 getPrioritySets
162 getPrioritySets
164 ( removeTask "aaa" . removeTask "oh HaiMark"
163 ( removeTask "aaa" . removeTask "oh HaiMark"
@@ -172,9 +171,8 @@ tests = do
172 ("OH NO", High)
171 ("OH NO", High)
173 ]
172 ]
174 )
173 )
175− `shouldBe` [ [],
176− [(NotCompleted, "aaa")],
174+ `shouldBe` [ [(NotCompleted, "OH NO")],
177− [(Completed, "a")]
175+ [(NotCompleted, "a")]
178 ]
176 ]
179 it "modifyPriority" $ do
177 it "modifyPriority" $ do
180 getPrioritySets
178 getPrioritySets
@@ -186,12 +184,13 @@ tests = do
186 ("OH NO", High)
184 ("OH NO", High)
187 ]
185 ]
188 )
186 )
189− `shouldBe` [ [(Completed, "AAAAAAAAAA"), (NotCompleted, "OH NO"), (NotCompleted, "aaa")],
187+ `shouldBe` [ [(NotCompleted, "AAAAAAAAAA"), (NotCompleted, "OH NO"), (NotCompleted, "aaa")],
190 [(NotCompleted, "oh HaiMark")],
188 [(NotCompleted, "oh HaiMark")],
191 [(NotCompleted, "a")]
189 [(NotCompleted, "a")]
192 ]
190 ]
193 getPrioritySets
191 getPrioritySets
194 ( modifyPriority "aaa" High
192 ( modifyPriority "aaa" High
193+ . toggleTaskCompletion "a"
195 . modifyPriority "a" High
194 . modifyPriority "a" High
196 . createTasks
195 . createTasks
197 $ [ ("a", Low),
196 $ [ ("a", Low),
@@ -201,13 +200,12 @@ tests = do
201 ("OH NO", High)
200 ("OH NO", High)
202 ]
201 ]
203 )
202 )
204− `shouldBe` [ [ (Completed, "AAAAAAAAAA"),
203+ `shouldBe` [ [ (Completed, "a"),
204+ (NotCompleted, "AAAAAAAAAA"),
205 (NotCompleted, "OH NO"),
205 (NotCompleted, "OH NO"),
206− (NotCompleted, "a"),
207 (NotCompleted, "aaa")
206 (NotCompleted, "aaa")
208 ],
207 ],
209− [(NotCompleted, "oh HaiMark")],
208+ [(NotCompleted, "oh HaiMark")]
210− []
211 ]
209 ]
212 getPrioritySets
210 getPrioritySets
213 ( modifyPriority "aaa" High
211 ( modifyPriority "aaa" High
@@ -222,14 +220,12 @@ tests = do
222 ("OH NO", High)
220 ("OH NO", High)
223 ]
221 ]
224 )
222 )
225− `shouldBe` [ [ (Completed, "AAAAAAAAAA"),
223+ `shouldBe` [ [ (NotCompleted, "AAAAAAAAAA"),
226 (NotCompleted, "OH NO"),
224 (NotCompleted, "OH NO"),
227 (NotCompleted, "a"),
225 (NotCompleted, "a"),
228 (NotCompleted, "aaa"),
226 (NotCompleted, "aaa"),
229 (NotCompleted, "oh HaiMark")
227 (NotCompleted, "oh HaiMark")
230− ],
228+ ]
231− [],
232− []
233 ]
229 ]
234 getPrioritySets
230 getPrioritySets
235 ( modifyPriority "aaa" High
231 ( modifyPriority "aaa" High
@@ -246,12 +242,11 @@ tests = do
246 ("OH NO", High)
242 ("OH NO", High)
247 ]
243 ]
248 )
244 )
249− `shouldBe` [ [ (Completed, "AAAAAAAAAA"),
245+ `shouldBe` [ [ (NotCompleted, "AAAAAAAAAA"),
250 (NotCompleted, "OH NO"),
246 (NotCompleted, "OH NO"),
251 (NotCompleted, "a"),
247 (NotCompleted, "a"),
252 (NotCompleted, "aaa")
248 (NotCompleted, "aaa")
253 ],
249 ],
254− [],
255 [(NotCompleted, "oh HaiMark")]
250 [(NotCompleted, "oh HaiMark")]
256 ]
251 ]
257 it "renameTask" $ do
252 it "renameTask" $ do
@@ -265,12 +260,13 @@ tests = do
265 ("OH NO", High)
260 ("OH NO", High)
266 ]
261 ]
267 )
262 )
268− `shouldBe` [ [(Completed, "henlo"), (NotCompleted, "OH NO")],
263+ `shouldBe` [ [(NotCompleted, "OH NO"), (NotCompleted, "henlo")],
269 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
264 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
270 [(NotCompleted, "a")]
265 [(NotCompleted, "a")]
271 ]
266 ]
272 getPrioritySets
267 getPrioritySets
273 ( renameTask "AAAAAAAAAA" "henlo"
268 ( renameTask "AAAAAAAAAA" "henlo"
269+ . toggleTaskCompletion "a"
274 . renameTask "oh HaiMark" "iz task"
270 . renameTask "oh HaiMark" "iz task"
275 . createTasks
271 . createTasks
276 $ [ ("a", Low),
272 $ [ ("a", Low),
@@ -280,12 +276,13 @@ tests = do
280 ("OH NO", High)
276 ("OH NO", High)
281 ]
277 ]
282 )
278 )
283− `shouldBe` [ [(Completed, "henlo"), (NotCompleted, "OH NO")],
279+ `shouldBe` [ [(NotCompleted, "OH NO"), (NotCompleted, "henlo")],
284 [(NotCompleted, "aaa"), (NotCompleted, "iz task")],
280 [(NotCompleted, "aaa"), (NotCompleted, "iz task")],
285− [(NotCompleted, "a")]
281+ [(Completed, "a")]
286 ]
282 ]
287 getPrioritySets
283 getPrioritySets
288 ( renameTask "AAAAAAAAAA" "henlo"
284 ( renameTask "AAAAAAAAAA" "henlo"
285+ . toggleTaskCompletion "iz task"
289 . renameTask "oh HaiMark" "iz task"
286 . renameTask "oh HaiMark" "iz task"
290 . renameTask "iz not here" "ajajaj"
287 . renameTask "iz not here" "ajajaj"
291 . createTasks
288 . createTasks
@@ -296,8 +293,8 @@ tests = do
296 ("OH NO", High)
293 ("OH NO", High)
297 ]
294 ]
298 )
295 )
299− `shouldBe` [ [(Completed, "henlo"), (NotCompleted, "OH NO")],
296+ `shouldBe` [ [(NotCompleted, "OH NO"), (NotCompleted, "henlo")],
300− [(NotCompleted, "aaa"), (NotCompleted, "iz task")],
297+ [(Completed, "iz task"), (NotCompleted, "aaa")],
301 [(NotCompleted, "a")]
298 [(NotCompleted, "a")]
302 ]
299 ]
303 describe "Coffee" $ do
300 describe "Coffee" $ do
@@ -313,9 +310,9 @@ tests = do
313 it "chargeCoffee" $ do
310 it "chargeCoffee" $ do
314 chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 199 69)
311 chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 199 69)
315 `shouldBe` Just (DebitCard 112 69)
312 `shouldBe` Just (DebitCard 112 69)
316− chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 112 69)
313+ chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 87 69)
317 `shouldBe` Just (DebitCard 0 69)
314 `shouldBe` Just (DebitCard 0 69)
318− chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 111 69)
315+ chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 86 69)
319 `shouldBe` Nothing
316 `shouldBe` Nothing
320 chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 0 69)
317 chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 0 69)
321 `shouldBe` Nothing
318 `shouldBe` Nothing
@@ -329,17 +326,17 @@ tests = do
329 it "payForCoffee" $ do
326 it "payForCoffee" $ do
330 payForCoffee (Customer [DebitCard 199 69] 0) coffee
327 payForCoffee (Customer [DebitCard 199 69] 0) coffee
331 `shouldBe` Just (Card (DebitCard 112 69))
328 `shouldBe` Just (Card (DebitCard 112 69))
332− payForCoffee (Customer [DebitCard 111 12, DebitCard 199 69] 2) coffee
329+ payForCoffee (Customer [DebitCard 86 12, DebitCard 199 69] 2) coffee
333 `shouldBe` Just (Card (DebitCard 112 69))
330 `shouldBe` Just (Card (DebitCard 112 69))
334− payForCoffee (Customer [DebitCard (-12) 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
331+ payForCoffee (Customer [DebitCard (-12) 8, DebitCard 86 12, DebitCard 199 69] 0) coffee
335 `shouldBe` Just (Card (DebitCard 112 69))
332 `shouldBe` Just (Card (DebitCard 112 69))
336− payForCoffee (Customer [DebitCard 112 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
333+ payForCoffee (Customer [DebitCard 87 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
337 `shouldBe` Just (Card (DebitCard 0 8))
334 `shouldBe` Just (Card (DebitCard 0 8))
338− payForCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 0) coffee
335+ payForCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 82 69] 0) coffee
339 `shouldBe` Nothing
336 `shouldBe` Nothing
340− payForCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 112) coffee
337+ payForCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 82 69] 87) coffee
341 `shouldBe` Just (Cash 0)
338 `shouldBe` Just (Cash 0)
342− payForCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 111) coffee
339+ payForCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 81 69] 86) coffee
343 `shouldBe` Nothing
340 `shouldBe` Nothing
344 it "applyPayment" $ do
341 it "applyPayment" $ do
345 applyPayment (Customer [DebitCard 199 69] 0) (Card (DebitCard 112 69))
342 applyPayment (Customer [DebitCard 199 69] 0) (Card (DebitCard 112 69))
@@ -357,17 +354,17 @@ tests = do
357 it "buyCoffee" $ do
354 it "buyCoffee" $ do
358 buyCoffee (Customer [DebitCard 199 69] 0) coffee
355 buyCoffee (Customer [DebitCard 199 69] 0) coffee
359 `shouldBe` Just (Customer [DebitCard 112 69] 0)
356 `shouldBe` Just (Customer [DebitCard 112 69] 0)
360− buyCoffee (Customer [DebitCard 111 12, DebitCard 199 69] 2) coffee
357+ buyCoffee (Customer [DebitCard 86 12, DebitCard 199 69] 2) coffee
361− `shouldBe` Just (Customer [DebitCard 111 12, DebitCard 112 69] 2)
358+ `shouldBe` Just (Customer [DebitCard 86 12, DebitCard 112 69] 2)
362− buyCoffee (Customer [DebitCard (-12) 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
359+ buyCoffee (Customer [DebitCard (-12) 8, DebitCard 86 12, DebitCard 199 69] 0) coffee
363− `shouldBe` Just (Customer [DebitCard (-12) 8, DebitCard 111 12, DebitCard 112 69] 0)
360+ `shouldBe` Just (Customer [DebitCard (-12) 8, DebitCard 86 12, DebitCard 112 69] 0)
364− buyCoffee (Customer [DebitCard 112 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
361+ buyCoffee (Customer [DebitCard 87 8, DebitCard 86 12, DebitCard 199 69] 0) coffee
365− `shouldBe` Just (Customer [DebitCard 0 8, DebitCard 111 12, DebitCard 199 69] 0)
362+ `shouldBe` Just (Customer [DebitCard 0 8, DebitCard 86 12, DebitCard 199 69] 0)
366− buyCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 0) coffee
363+ buyCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 84 69] 0) coffee
367 `shouldBe` Nothing
364 `shouldBe` Nothing
368− buyCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 112) coffee
365+ buyCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 82 69] 87) coffee
369− `shouldBe` Just (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 0)
366+ `shouldBe` Just (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 82 69] 0)
370− buyCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 111) coffee
367+ buyCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 81 69] 86) coffee
371 `shouldBe` Nothing
368 `shouldBe` Nothing
372 it "saveTheDiabetic" $ do
369 it "saveTheDiabetic" $ do
373 saveTheDiabetic
370 saveTheDiabetic