~ubuntu-branches/ubuntu/raring/agda/raring-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/TypeChecking/Tests.hs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2009-07-20 19:49:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090720194941-hcjy91vrn16csh7d
Tags: upstream-2.2.4+dfsg
ImportĀ upstreamĀ versionĀ 2.2.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Agda.TypeChecking.Tests where
 
2
 
 
3
import qualified Data.Set as Set
 
4
import Agda.Utils.QuickCheck
 
5
 
 
6
import Agda.Syntax.Internal
 
7
import Agda.TypeChecking.Test.Generators
 
8
import Agda.TypeChecking.Telescope
 
9
import Agda.TypeChecking.Substitute
 
10
import Agda.Utils.Size
 
11
import Agda.Utils.Permutation
 
12
import Agda.Utils.TestHelpers
 
13
 
 
14
---------------------------------------------------------------------------
 
15
-- * Tests for "Agda.Utils.Permutation"
 
16
---------------------------------------------------------------------------
 
17
 
 
18
---------------------------------------------------------------------------
 
19
-- * Tests for "Agda.TypeChecking.Telescope"
 
20
---------------------------------------------------------------------------
 
21
 
 
22
-- | @telFromList . telToList == id@
 
23
prop_telToListInv :: TermConfiguration -> Property
 
24
prop_telToListInv conf =
 
25
  forAll (genC conf) $ \tel ->
 
26
  telFromList (telToList tel) == tel
 
27
 
 
28
-- | All elements of 'flattenTel' are well-scoped under the original telescope.
 
29
prop_flattenTelScope :: TermConfiguration -> Property
 
30
prop_flattenTelScope conf =
 
31
  forAll (genC conf) $ \tel ->
 
32
  all (isWellScoped $ extendWithTelConf tel conf) (flattenTel tel)
 
33
 
 
34
-- | @unflattenTel . flattenTel == id@
 
35
prop_flattenTelInv :: TermConfiguration -> Property
 
36
prop_flattenTelInv conf =
 
37
  forAll (genC conf) $ \tel ->
 
38
  unflattenTel (teleNames tel) (flattenTel tel) == tel
 
39
 
 
40
-- | 'reorderTel' is stable.
 
41
prop_reorderTelStable :: TermConfiguration -> Property
 
42
prop_reorderTelStable conf =
 
43
  forAll (genC conf) $ \tel ->
 
44
  reorderTel (flattenTel tel) == idP (size tel)
 
45
 
 
46
-- | The result of splitting a telescope is well-scoped.
 
47
prop_splitTelescopeScope :: TermConfiguration -> Property
 
48
prop_splitTelescopeScope conf =
 
49
  forAll (genC conf)                        $ \tel ->
 
50
  forAll (listOfElements [0..size tel - 1]) $ \vs ->
 
51
  let SplitTel tel1 tel2 perm = splitTelescope (Set.fromList vs) tel
 
52
      tel' = telFromList (telToList tel1 ++ telToList tel2)
 
53
  in  isWellScoped conf tel'
 
54
 
 
55
-- | The permutation generated when splitting a telescope preserves scoping.
 
56
prop_splitTelescopePermScope :: TermConfiguration -> Property
 
57
prop_splitTelescopePermScope conf =
 
58
      forAllShrink (genC conf) (shrinkC conf)                $ \tel ->
 
59
      forAllShrink (listOfElements [0..size tel - 1]) shrink $ \vs ->
 
60
  let SplitTel tel1 tel2 perm = splitTelescope (Set.fromList vs) tel
 
61
      conf1 = extendWithTelConf tel1 conf
 
62
      conf2 = conf1 { tcFreeVariables = map (size tel2 +) (tcFreeVariables conf1) }
 
63
      conf' = conf  { tcFreeVariables = map (size tel +) (tcFreeVariables conf) ++ vs }
 
64
  in  forAllShrink (genC conf') (shrinkC conf') $ \t ->
 
65
      isWellScoped conf2 (substs (renamingR $ invertP perm) (t :: Term))
 
66
 
 
67
{-
 
68
-- | The permutation generated when splitting a telescope correctly translates
 
69
--   between the old and the new telescope.
 
70
prop_splitTelescopePermInv :: TermConfiguration -> Property
 
71
prop_splitTelescopePermInv conf =
 
72
      forAll (wellScopedTel conf)               $ \tel ->
 
73
      forAll (listOfElements [0..size tel - 1]) $ \vs ->
 
74
  let SplitTel tel1 tel2 perm = splitTelescope (Set.fromList vs) tel
 
75
      tel' = telFromList (telToList tel1 ++ telToList tel2)
 
76
      conf1 = extendWithTelConf tel  conf
 
77
      conf2 = extendWithTelConf tel' conf
 
78
  in  forAll (wellScopedTerm conf1) $ \t1 ->
 
79
      forAll (wellScopedTerm conf2) $ \t2 ->
 
80
  let t1' = rename (invertP perm) $ rename perm t1
 
81
      t2' = rename perm $ rename (invertP perm) t2
 
82
  in  t1 == t1' && t2 == t2'
 
83
-}
 
84
 
 
85
tests :: IO Bool
 
86
tests = runTests "Agda.TypeChecking.Tests"
 
87
  [ quickCheck' prop_telToListInv
 
88
  , quickCheck' prop_flattenTelScope
 
89
  , quickCheck' prop_flattenTelInv
 
90
  , quickCheck' prop_reorderTelStable
 
91
  , quickCheck' prop_splitTelescopeScope
 
92
  , quickCheck' prop_splitTelescopePermScope
 
93
  ]