-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSuite.hs
More file actions
66 lines (33 loc) · 1.67 KB
/
TestSuite.hs
File metadata and controls
66 lines (33 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{-# LANGUAGE LambdaCase #-}
module Source.TypeNormalizer.TestSuite where
import Source.TypeNormalizer.Model
import Source.TypeNormalizer.Normalizer
import Source.TypeNormalizer.Parser
import Control.Monad
import Data.List hiding (insert)
import Data.Set hiding (filter,foldr,foldl,fromList)
import Data.Map (Map,fromList)
------------------------------------------------------------------
-- Testing the parser:
------------------------------------------------------------------
-- Testing the normalizer:
-- Normalize twice does not give up the same value for some cases!!
equivalent::ContextType -> Bool
equivalent (ContextType a b) = let (x,y) = ( shapeNormalize a, shapeNormalize b)
in getTheBest (ContextType x y) (toPermutation$openVar x y)
==
getTheBest (ContextType x y) (snd$usefullCopmutations x y)
toPermutation::[Int]->[Permutation]
toPermutation x = fmap (fromList.zip x) $ permutations x
openVar::Type -> Type -> [Int]
openVar a b = (take 1=<<).group.sort $ openVar' a ++ openVar' b
where
openVar' x = case x of
Node (Open n) xs -> n : (openVar' =<<xs)
Node base xs -> (openVar' =<<xs)
getNormalForm::ContextType -> (ContextType,Permutation)
getNormalForm (ContextType x y )= let permut = toPermutation $ openVar x y
(x',y') = (shapeNormalize x, shapeNormalize y)
in getTheBest (ContextType x' y') permut
------------------------------------------------------------------
-- Other Tests: