From 5eaf5c386ad23bd8105a7a670c9c65c73f1fc724 Mon Sep 17 00:00:00 2001 From: Steve Mao Date: Sat, 26 Oct 2019 22:48:54 +1100 Subject: [PATCH 1/3] add one more test to catch a potential bug --- test/Course/StateSpec.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Course/StateSpec.hs b/test/Course/StateSpec.hs index 29b21dbe..a2fc105e 100644 --- a/test/Course/StateSpec.hs +++ b/test/Course/StateSpec.hs @@ -49,6 +49,8 @@ spec = do describe "Monad" $ do it "(=<<)" $ runState ((const $ put 2) =<< put 1) 0 `shouldBe` ((),2) + it "" $ + runState ((\a -> State (\s -> (a * 3, s * 2))) =<< State (\s -> (s + 2, s + 1))) 2 `shouldBe` (12, 6) it "(>>=)" $ let modify f = State (\s -> ((), f s)) in runState (modify (+1) >>= \() -> modify (*2)) 7 `shouldBe` ((),16) From 85c8fd0ed6dfb6456228545e6bf0a56ac38efcd3 Mon Sep 17 00:00:00 2001 From: Steve Mao Date: Sat, 26 Oct 2019 23:10:17 +1100 Subject: [PATCH 2/3] Update StateSpec.hs --- test/Course/StateSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Course/StateSpec.hs b/test/Course/StateSpec.hs index a2fc105e..9b1f3bf9 100644 --- a/test/Course/StateSpec.hs +++ b/test/Course/StateSpec.hs @@ -50,7 +50,7 @@ spec = do it "(=<<)" $ runState ((const $ put 2) =<< put 1) 0 `shouldBe` ((),2) it "" $ - runState ((\a -> State (\s -> (a * 3, s * 2))) =<< State (\s -> (s + 2, s + 1))) 2 `shouldBe` (12, 6) + runState ((\a -> State (\s -> (a + s, 10 + s))) =<< State (\s -> (s * 2, 4 + s))) 2 `shouldBe` (10, 16) it "(>>=)" $ let modify f = State (\s -> ((), f s)) in runState (modify (+1) >>= \() -> modify (*2)) 7 `shouldBe` ((),16) From 45de021f95b3133ecc8038ed4f4ca0217a5cd572 Mon Sep 17 00:00:00 2001 From: Steve Mao Date: Sun, 27 Oct 2019 13:06:25 +1100 Subject: [PATCH 3/3] desc --- test/Course/StateSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Course/StateSpec.hs b/test/Course/StateSpec.hs index 9b1f3bf9..041a0407 100644 --- a/test/Course/StateSpec.hs +++ b/test/Course/StateSpec.hs @@ -49,7 +49,7 @@ spec = do describe "Monad" $ do it "(=<<)" $ runState ((const $ put 2) =<< put 1) 0 `shouldBe` ((),2) - it "" $ + it "correctly produces new state and value" $ runState ((\a -> State (\s -> (a + s, 10 + s))) =<< State (\s -> (s * 2, 4 + s))) 2 `shouldBe` (10, 16) it "(>>=)" $ let modify f = State (\s -> ((), f s))