TypeChecking.hs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {-# LANGUAGE TemplateHaskell #-}
  2. module Internal.TypeChecking ( tests ) where
  3. import Agda.Utils.Impossible
  4. import Agda.Syntax.Internal
  5. import Agda.TypeChecking.Substitute
  6. import Agda.TypeChecking.Telescope
  7. import Agda.Utils.Permutation
  8. import Agda.Utils.Size
  9. import qualified Agda.Utils.VarSet as Set
  10. import Internal.Helpers
  11. import Internal.TypeChecking.Generators hiding ( tests )
  12. ---------------------------------------------------------------------------
  13. -- * Tests for "Agda.Utils.Permutation"
  14. ---------------------------------------------------------------------------
  15. ---------------------------------------------------------------------------
  16. -- * Tests for "Agda.TypeChecking.Telescope"
  17. ---------------------------------------------------------------------------
  18. -- | @telFromList . telToList == id@
  19. prop_telToListInv :: TermConfiguration -> Property
  20. prop_telToListInv conf =
  21. forAll (genC conf) $ \tel ->
  22. telFromList (telToList tel) == tel
  23. -- | All elements of 'flattenTel' are well-scoped under the original telescope.
  24. prop_flattenTelScope :: TermConfiguration -> Property
  25. prop_flattenTelScope conf =
  26. forAll (genC conf) $ \tel ->
  27. all (isWellScoped $ extendWithTelConf tel conf) (flattenTel tel)
  28. -- | @unflattenTel . flattenTel == id@
  29. prop_flattenTelInv :: TermConfiguration -> Property
  30. prop_flattenTelInv conf =
  31. forAll (genC conf) $ \tel ->
  32. unflattenTel (teleNames tel) (flattenTel tel) == tel
  33. -- | 'reorderTel' is stable.
  34. prop_reorderTelStable :: TermConfiguration -> Property
  35. prop_reorderTelStable conf =
  36. forAll (genC conf) $ \tel ->
  37. reorderTel (flattenTel tel) == Just (idP (size tel))
  38. -- | The result of splitting a telescope is well-scoped.
  39. prop_splitTelescopeScope :: TermConfiguration -> Property
  40. prop_splitTelescopeScope conf =
  41. forAll (genC conf) $ \tel ->
  42. forAll (listOfElements [0..size tel - 1]) $ \vs ->
  43. let SplitTel tel1 tel2 perm = splitTelescope (Set.fromList vs) tel
  44. tel' = telFromList (telToList tel1 ++ telToList tel2)
  45. in isWellScoped conf tel'
  46. -- | The permutation generated when splitting a telescope preserves scoping.
  47. prop_splitTelescopePermScope :: TermConfiguration -> Property
  48. prop_splitTelescopePermScope conf =
  49. forAllShrink (genC conf) (shrinkC conf) $ \tel ->
  50. forAllShrink (listOfElements [0..size tel - 1]) shrink $ \vs ->
  51. let SplitTel tel1 tel2 perm = splitTelescope (Set.fromList vs) tel
  52. conf1 = extendWithTelConf tel1 conf
  53. conf2 = conf1 { tcFreeVariables = map (size tel2 +) (tcFreeVariables conf1) }
  54. conf' = conf { tcFreeVariables = map (size tel +) (tcFreeVariables conf) ++ vs }
  55. in forAllShrink (genC conf') (shrinkC conf') $ \t ->
  56. isWellScoped conf2 (applySubst (renamingR $ invertP __IMPOSSIBLE__ perm) (t :: Term))
  57. -- -- | The permutation generated when splitting a telescope correctly translates
  58. -- -- between the old and the new telescope.
  59. -- prop_splitTelescopePermInv :: TermConfiguration -> Property
  60. -- prop_splitTelescopePermInv conf =
  61. -- forAll (wellScopedTel conf) $ \tel ->
  62. -- forAll (listOfElements [0..size tel - 1]) $ \vs ->
  63. -- let SplitTel tel1 tel2 perm = splitTelescope (Set.fromList vs) tel
  64. -- tel' = telFromList (telToList tel1 ++ telToList tel2)
  65. -- conf1 = extendWithTelConf tel conf
  66. -- conf2 = extendWithTelConf tel' conf
  67. -- in forAll (wellScopedTerm conf1) $ \t1 ->
  68. -- forAll (wellScopedTerm conf2) $ \t2 ->
  69. -- let t1' = rename (invertP __IMPOSSIBLE__ perm) $ rename perm t1
  70. -- t2' = rename perm $ rename (invertP __IMPOSSIBLE__ perm) t2
  71. -- in t1 == t1' && t2 == t2'
  72. ------------------------------------------------------------------------
  73. -- * All tests
  74. ------------------------------------------------------------------------
  75. -- Template Haskell hack to make the following $allProperties work
  76. -- under ghc-7.8.
  77. return [] -- KEEP!
  78. -- | All tests as collected by 'allProperties'.
  79. --
  80. -- Using 'allProperties' is convenient and superior to the manual
  81. -- enumeration of tests, since the name of the property is added
  82. -- automatically.
  83. tests :: TestTree
  84. tests = testProperties "Internal.TypeChecking" $allProperties