git.iko.soy/ikoHSE/sc-task-2
on master help sign in
Updated everything
commitf102b30fdaf73977887fbe2d83d26c2fbba37d41 authoriko <ilyakooo0@gmail.com> dateThu 7 May 2020, 01:50 (6 years ago) parent148944c
4 files changed+90−49
.gitignore+2−1 src/Task.hs+6−2 task.cabal+39 test/Tests.hs+43−46
.gitignore+2−1
@@ -21,7 +21,8 @@ cabal.project.local
2121cabal.project.local~
2222.HTF/
2323.ghc.environment.*
24−*.cabal
2524.DS_Store
2625.idea/
2726*.dump-hi
27+*.lock
28+*.iml
src/Task.hs+6−2
@@ -293,10 +293,12 @@ payForCoffee = error "TODO: payForCoffee"
293293
294294-- | This function should apply the chosen payment method to the customer.
295295-- 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)
297297--
298298-- If the specified card is not present in the 'Customer' structure, then
299299-- do nothing.
300+--
301+-- NOTE: You can not change the order of the cards.
300302applyPayment :: Customer -> PaymentMethod -> Customer
301303applyPayment = error "TODO: applyPayment"
302304
@@ -305,7 +307,7 @@ applyPayment = error "TODO: applyPayment"
305307buyCoffee :: Customer -> Coffee -> Maybe Customer
306308buyCoffee = error "TODO: buyCoffee"
307309
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
309311-- sugar intake. The new privacy-invading piece of ... technology can now
310312-- automatically apply filters to coffee orders.
311313--
@@ -314,6 +316,8 @@ buyCoffee = error "TODO: buyCoffee"
314316-- return the filtered orders and the amount of money the customer saves by
315317-- being healthy (sugar costs money after all). So, you also have to count how
316318-- much the total sugar would have cost.
319+--
320+-- NOTE: You can not change the order of the coffee.
317321saveTheDiabetic :: [Coffee] -> (RUBAmount, [Coffee])
318322saveTheDiabetic = error "TODO: saveTheDiabetic"
319323
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
1818 getFirst [] `shouldBe` (Nothing :: Maybe ())
1919 getFirst [True, False] `shouldBe` Just True
2020 getFirst [True, True, False] `shouldBe` Just True
21− getFirst [1 .. 1000] `shouldBe` Just 1
22− getFirst [100 .. 1000] `shouldBe` Just 100
23− getFirst [6, 2, 7, 398, 1984, 383, -1020] `shouldBe` Just 6
21+ getFirst [1 .. 1000] `shouldBe` Just (1 :: Int)
22+ getFirst [100 .. 1000] `shouldBe` Just (100 :: Int)
23+ getFirst [6, 2, 7, 398, 1984, 383, -1020] `shouldBe` Just (6 :: Int)
2424 it "LastMonoid" $ do
2525 let getLast = destructLastMonoid . fold . fmap constructLastMonoid
2626 getLast [1 :: Int, 2, 3] `shouldBe` Just 3
2727 getLast [] `shouldBe` (Nothing :: Maybe ())
28− getLast [1 .. 1000] `shouldBe` Just 1000
29− getLast [100 .. 10000] `shouldBe` Just 10000
30− getLast [6, 2, 7, 398, 1984, 383, -1020, 498] `shouldBe` Just 498
28+ getLast [1 .. 1000] `shouldBe` Just (1000 :: Int)
29+ getLast [100 .. 10000] `shouldBe` Just (10000 :: Int)
30+ getLast [6, 2, 7, 398, 1984, 383, -1020, 498] `shouldBe` Just (498 :: Int)
3131 getLast [True, False] `shouldBe` Just False
3232 getLast [True, True, False] `shouldBe` Just False
3333 getLast [True, True, False, True] `shouldBe` Just True
@@ -60,7 +60,6 @@ tests = do
6060 ]
6161 )
6262 `shouldBe` [ [(NotCompleted, "AAAAAAAAAA")],
63− [],
6463 [(NotCompleted, "a")]
6564 ]
6665 getPrioritySets
@@ -144,7 +143,7 @@ tests = do
144143 )
145144 `shouldBe` [ [(NotCompleted, "OH NO")],
146145 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
147− [(Completed, "a")]
146+ [(NotCompleted, "a")]
148147 ]
149148 getPrioritySets
150149 ( removeTask "AAAAAAAAAA" . removeTask "AAAAAAAAAA"
@@ -158,7 +157,7 @@ tests = do
158157 )
159158 `shouldBe` [ [(NotCompleted, "OH NO")],
160159 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
161− [(Completed, "a")]
160+ [(NotCompleted, "a")]
162161 ]
163162 getPrioritySets
164163 ( removeTask "aaa" . removeTask "oh HaiMark"
@@ -172,9 +171,8 @@ tests = do
172171 ("OH NO", High)
173172 ]
174173 )
175− `shouldBe` [ [],
176− [(NotCompleted, "aaa")],
177− [(Completed, "a")]
174+ `shouldBe` [ [(NotCompleted, "OH NO")],
175+ [(NotCompleted, "a")]
178176 ]
179177 it "modifyPriority" $ do
180178 getPrioritySets
@@ -186,12 +184,13 @@ tests = do
186184 ("OH NO", High)
187185 ]
188186 )
189− `shouldBe` [ [(Completed, "AAAAAAAAAA"), (NotCompleted, "OH NO"), (NotCompleted, "aaa")],
187+ `shouldBe` [ [(NotCompleted, "AAAAAAAAAA"), (NotCompleted, "OH NO"), (NotCompleted, "aaa")],
190188 [(NotCompleted, "oh HaiMark")],
191189 [(NotCompleted, "a")]
192190 ]
193191 getPrioritySets
194192 ( modifyPriority "aaa" High
193+ . toggleTaskCompletion "a"
195194 . modifyPriority "a" High
196195 . createTasks
197196 $ [ ("a", Low),
@@ -201,13 +200,12 @@ tests = do
201200 ("OH NO", High)
202201 ]
203202 )
204− `shouldBe` [ [ (Completed, "AAAAAAAAAA"),
203+ `shouldBe` [ [ (Completed, "a"),
204+ (NotCompleted, "AAAAAAAAAA"),
205205 (NotCompleted, "OH NO"),
206− (NotCompleted, "a"),
207206 (NotCompleted, "aaa")
208207 ],
209− [(NotCompleted, "oh HaiMark")],
210− []
208+ [(NotCompleted, "oh HaiMark")]
211209 ]
212210 getPrioritySets
213211 ( modifyPriority "aaa" High
@@ -222,14 +220,12 @@ tests = do
222220 ("OH NO", High)
223221 ]
224222 )
225− `shouldBe` [ [ (Completed, "AAAAAAAAAA"),
223+ `shouldBe` [ [ (NotCompleted, "AAAAAAAAAA"),
226224 (NotCompleted, "OH NO"),
227225 (NotCompleted, "a"),
228226 (NotCompleted, "aaa"),
229227 (NotCompleted, "oh HaiMark")
230− ],
231− [],
232− []
228+ ]
233229 ]
234230 getPrioritySets
235231 ( modifyPriority "aaa" High
@@ -246,12 +242,11 @@ tests = do
246242 ("OH NO", High)
247243 ]
248244 )
249− `shouldBe` [ [ (Completed, "AAAAAAAAAA"),
245+ `shouldBe` [ [ (NotCompleted, "AAAAAAAAAA"),
250246 (NotCompleted, "OH NO"),
251247 (NotCompleted, "a"),
252248 (NotCompleted, "aaa")
253249 ],
254− [],
255250 [(NotCompleted, "oh HaiMark")]
256251 ]
257252 it "renameTask" $ do
@@ -265,12 +260,13 @@ tests = do
265260 ("OH NO", High)
266261 ]
267262 )
268− `shouldBe` [ [(Completed, "henlo"), (NotCompleted, "OH NO")],
263+ `shouldBe` [ [(NotCompleted, "OH NO"), (NotCompleted, "henlo")],
269264 [(NotCompleted, "aaa"), (NotCompleted, "oh HaiMark")],
270265 [(NotCompleted, "a")]
271266 ]
272267 getPrioritySets
273268 ( renameTask "AAAAAAAAAA" "henlo"
269+ . toggleTaskCompletion "a"
274270 . renameTask "oh HaiMark" "iz task"
275271 . createTasks
276272 $ [ ("a", Low),
@@ -280,12 +276,13 @@ tests = do
280276 ("OH NO", High)
281277 ]
282278 )
283− `shouldBe` [ [(Completed, "henlo"), (NotCompleted, "OH NO")],
279+ `shouldBe` [ [(NotCompleted, "OH NO"), (NotCompleted, "henlo")],
284280 [(NotCompleted, "aaa"), (NotCompleted, "iz task")],
285− [(NotCompleted, "a")]
281+ [(Completed, "a")]
286282 ]
287283 getPrioritySets
288284 ( renameTask "AAAAAAAAAA" "henlo"
285+ . toggleTaskCompletion "iz task"
289286 . renameTask "oh HaiMark" "iz task"
290287 . renameTask "iz not here" "ajajaj"
291288 . createTasks
@@ -296,8 +293,8 @@ tests = do
296293 ("OH NO", High)
297294 ]
298295 )
299− `shouldBe` [ [(Completed, "henlo"), (NotCompleted, "OH NO")],
300− [(NotCompleted, "aaa"), (NotCompleted, "iz task")],
296+ `shouldBe` [ [(NotCompleted, "OH NO"), (NotCompleted, "henlo")],
297+ [(Completed, "iz task"), (NotCompleted, "aaa")],
301298 [(NotCompleted, "a")]
302299 ]
303300 describe "Coffee" $ do
@@ -313,9 +310,9 @@ tests = do
313310 it "chargeCoffee" $ do
314311 chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 199 69)
315312 `shouldBe` Just (DebitCard 112 69)
316− chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 112 69)
313+ chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 87 69)
317314 `shouldBe` Just (DebitCard 0 69)
318− chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 111 69)
315+ chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 86 69)
319316 `shouldBe` Nothing
320317 chargeCoffee (Coffee 2 [OatMilk, Cinnamon]) (DebitCard 0 69)
321318 `shouldBe` Nothing
@@ -329,17 +326,17 @@ tests = do
329326 it "payForCoffee" $ do
330327 payForCoffee (Customer [DebitCard 199 69] 0) coffee
331328 `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
333330 `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
335332 `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
337334 `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
339336 `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
341338 `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
343340 `shouldBe` Nothing
344341 it "applyPayment" $ do
345342 applyPayment (Customer [DebitCard 199 69] 0) (Card (DebitCard 112 69))
@@ -357,17 +354,17 @@ tests = do
357354 it "buyCoffee" $ do
358355 buyCoffee (Customer [DebitCard 199 69] 0) coffee
359356 `shouldBe` Just (Customer [DebitCard 112 69] 0)
360− buyCoffee (Customer [DebitCard 111 12, DebitCard 199 69] 2) coffee
361− `shouldBe` Just (Customer [DebitCard 111 12, DebitCard 112 69] 2)
362− buyCoffee (Customer [DebitCard (-12) 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
363− `shouldBe` Just (Customer [DebitCard (-12) 8, DebitCard 111 12, DebitCard 112 69] 0)
364− buyCoffee (Customer [DebitCard 112 8, DebitCard 111 12, DebitCard 199 69] 0) coffee
365− `shouldBe` Just (Customer [DebitCard 0 8, DebitCard 111 12, DebitCard 199 69] 0)
366− buyCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 0) coffee
357+ buyCoffee (Customer [DebitCard 86 12, DebitCard 199 69] 2) coffee
358+ `shouldBe` Just (Customer [DebitCard 86 12, DebitCard 112 69] 2)
359+ buyCoffee (Customer [DebitCard (-12) 8, DebitCard 86 12, DebitCard 199 69] 0) coffee
360+ `shouldBe` Just (Customer [DebitCard (-12) 8, DebitCard 86 12, DebitCard 112 69] 0)
361+ buyCoffee (Customer [DebitCard 87 8, DebitCard 86 12, DebitCard 199 69] 0) coffee
362+ `shouldBe` Just (Customer [DebitCard 0 8, DebitCard 86 12, DebitCard 199 69] 0)
363+ buyCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 84 69] 0) coffee
367364 `shouldBe` Nothing
368− buyCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 112) coffee
369− `shouldBe` Just (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 0)
370− buyCoffee (Customer [DebitCard 111 8, DebitCard 111 12, DebitCard 110 69] 111) coffee
365+ buyCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 82 69] 87) coffee
366+ `shouldBe` Just (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 82 69] 0)
367+ buyCoffee (Customer [DebitCard 86 8, DebitCard 86 12, DebitCard 81 69] 86) coffee
371368 `shouldBe` Nothing
372369 it "saveTheDiabetic" $ do
373370 saveTheDiabetic