on master help sign in
Test-suite update (T8)
commitc9a138ca22b9e55874568a8a3928a26a57b0e5d3 authorIndex Int <vlad.z.4096@gmail.com> dateSat 23 Jan 2016, 17:41 (11 years ago) parentfe92c00
2 files changed+47−49
test/Regression.hs−48 test/Regression/T8.hs+47−1
test/Regression.hs−48
@@ -1,13 +1,5 @@
11module Main where
22
3−import Control.Monad
4−
5−import Control.Monad.Ether
6−import Control.Ether.Abbr
7−
8−import qualified Control.Monad.Reader as T
9−import qualified Control.Monad.State as T
10−
113import Test.Tasty
124
135import Regression.T1
@@ -19,9 +11,6 @@ import Regression.T6
1911import Regression.T7
2012import Regression.T8
2113
22−ethereal "Foo" "foo"
23−ethereal "Bar" "bar"
24−
2514main :: IO ()
2615main = defaultMain suite
2716
@@ -36,40 +25,3 @@ suite = testGroup "Ether"
3625 , test7
3726 , test8
3827 ]
39−
40−wrapState_f :: T.MonadState Int m => m String
41−wrapState_f = liftM show T.get
42−
43−wrapState_g :: T.MonadState Bool m => m String
44−wrapState_g = liftM show T.get
45−
46−wrapState_useboth :: Ether '[Foo <-> Int, Bar <-> Bool] m => m String
47−wrapState_useboth = do
48− a <- tagAttach foo wrapState_f
49− b <- tagAttach bar wrapState_g
50− return (a ++ b)
51−
52−wrapStateCore :: Int -> Bool -> String
53−wrapStateCore int bool = evalState foo (evalStateT bar wrapState_useboth bool) int
54−
55−wrapStateBad1_g :: MonadState Foo Int m => m ()
56−wrapStateBad1_g = modify foo (*100)
57−
58−wrapStateBad1_useboth :: MonadState Foo Int m => m String
59−wrapStateBad1_useboth = do
60− wrapStateBad1_g
61− tagAttach foo wrapState_f
62−
63−wrapStateBad1 :: Int -> String
64−wrapStateBad1 = evalState foo wrapStateBad1_useboth
65−
66−wrapStateBad2 :: (T.MonadState Int m , MonadState Foo Int m) => m Int
67−wrapStateBad2 = do
68− modify foo (*100)
69− T.get
70−
71−wrapStateBad2Core :: Int -> Int
72−wrapStateBad2Core = evalState foo (tagAttach foo wrapStateBad2)
73−
74−wrapReaderCore :: Int -> Int
75−wrapReaderCore = runReader foo (tagAttach foo (liftM2 (+) T.ask (ask foo)))
test/Regression/T8.hs+47−1
@@ -1,6 +1,52 @@
11module Regression.T8 (test8) where
22
3+import Control.Ether.Abbr
4+import Control.Monad.Ether
5+
6+import qualified Control.Monad.State as T
7+
38import Test.Tasty
9+import Test.Tasty.QuickCheck
10+
11+ethereal "Foo" "foo"
12+ethereal "Bar" "bar"
13+
14+testMTL1 :: T.MonadState Int m => m ()
15+testMTL1 = T.modify negate
16+
17+testMTL2 :: T.MonadState Bool m => m ()
18+testMTL2 = T.modify not
19+
20+testEther
21+ :: Ether '[Foo <-> Int, Bar <-> Bool] m
22+ => m String
23+testEther = do
24+ tagAttach foo testMTL1
25+ tagAttach bar testMTL2
26+ a <- gets foo show
27+ b <- gets bar show
28+ return (a ++ b)
29+
30+model :: Int -> Bool -> String
31+model a b = show (negate a) ++ show (not b)
32+
33+runner1 a b
34+ = flip (evalState foo) a
35+ . flip (evalStateT bar) b
36+
37+runner2 a b
38+ = flip (evalState bar) b
39+ . flip (evalStateT foo) a
440
541test8 :: TestTree
6−test8 = testGroup "T8:" []
42+test8 = testGroup "T8: Multiple tag attachements"
43+ [ testProperty "runner₁ works"
44+ $ \a b -> property
45+ $ runner1 a b testEther == model a b
46+ , testProperty "runner₂ works"
47+ $ \a b -> property
48+ $ runner2 a b testEther == model a b
49+ , testProperty "runner₁ == runner₂"
50+ $ \a b -> property
51+ $ runner1 a b testEther == runner2 a b testEther
52+ ]