@@ -0,0 +1,42 @@
1+module Regression.T10 (test10) where
2+
3+import Control.Applicative
4+import Data.Functor.Identity
5+import qualified Control.Monad.Ether.Implicit as I
6+
7+import Test.Tasty
8+import Test.Tasty.QuickCheck
9+
10+testEther :: Integer -> I.StateT Integer Maybe [Integer]
11+testEther m = range
12+ where
13+ range = liftA2 (:) yield (range <|> pure [])
14+ yield = I.stateT $ \n -> do
15+ I.guard (n <= m)
16+ Just (n, n + 1)
17+
18+testEther' :: Integer -> I.State Integer [Integer]
19+testEther' m =
20+ I.stateT $ Identity . maybe ([], m + 1) id . I.runStateT (testEther m)
21+
22+next1 :: Integer -> Integer -> Maybe Integer
23+next1 m n
24+ | n <= m = Just (m + 1)
25+ | otherwise = Nothing
26+
27+range1 :: Integer -> Integer -> Maybe [Integer]
28+range1 m n
29+ | n <= m = Just [n..m]
30+ | otherwise = Nothing
31+
32+test10 :: TestTree
33+test10 = testGroup "T10: Alternative instance"
34+ [ testProperty "execStateT works"
35+ $ \m n -> I.execStateT (testEther m) n == next1 m n
36+ , testProperty "evalStateT works"
37+ $ \m n -> I.evalStateT (testEther m) n == range1 m n
38+ , testProperty "execState works"
39+ $ \m n -> I.execState (testEther' m) n == m + 1
40+ , testProperty "evalState works"
41+ $ \m n -> I.evalState (testEther' m) n == [n..m]
42+ ]