CallMatrix.hs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. {-# LANGUAGE TemplateHaskell #-}
  2. module Internal.Termination.CallMatrix
  3. ( callMatrix
  4. , tests
  5. ) where
  6. import Agda.Termination.CallMatrix
  7. import Agda.Termination.CutOff
  8. import Agda.Termination.SparseMatrix ( Size )
  9. import Internal.Helpers
  10. import Internal.Termination.Order ()
  11. import Internal.Termination.SparseMatrix ( matrix )
  12. ------------------------------------------------------------------------
  13. -- * Generators and tests
  14. ------------------------------------------------------------------------
  15. deriving instance CoArbitrary CallMatrix
  16. -- ** CallMatrix
  17. instance Arbitrary CallMatrix where
  18. arbitrary = callMatrix =<< arbitrary
  19. -- | Generates a call matrix of the given size.
  20. callMatrix :: Size ArgumentIndex -> Gen CallMatrix
  21. callMatrix sz = CallMatrix <$> matrix sz
  22. -- ** CallMatrixAug
  23. instance Arbitrary cinfo => Arbitrary (CallMatrixAug cinfo) where
  24. arbitrary = CallMatrixAug <$> arbitrary <*> arbitrary
  25. instance CoArbitrary cinfo => CoArbitrary (CallMatrixAug cinfo) where
  26. coarbitrary (CallMatrixAug m info) = coarbitrary m . coarbitrary info
  27. ------------------------------------------------------------------------
  28. -- * All tests
  29. ------------------------------------------------------------------------
  30. -- Template Haskell hack to make the following $allProperties work
  31. -- under ghc-7.8.
  32. return [] -- KEEP!
  33. -- | All tests as collected by 'allProperties'.
  34. --
  35. -- Using 'allProperties' is convenient and superior to the manual
  36. -- enumeration of tests, since the name of the property is added
  37. -- automatically.
  38. tests :: TestTree
  39. tests = testProperties "Internal.Termination.CallMatrix" $allProperties
  40. -- RETIRED: LONG OUTDATED call matrix invariant
  41. -- -- | In a call matrix at most one element per row may be different
  42. -- -- from 'unknown'.
  43. -- callMatrixInvariant :: CallMatrix -> Bool
  44. -- callMatrixInvariant (CallMatrix m) =
  45. -- matrixInvariant m &&
  46. -- all ((<= 1) . length . filter (/= unknown)) (toLists m)
  47. -- prop_Arbitrary_CallMatrix = callMatrixInvariant
  48. -- -- | Generates a call matrix of the given size.
  49. -- callMatrix :: Size ArgumentIndex -> Gen CallMatrix
  50. -- callMatrix sz = do
  51. -- m <- matrixUsingRowGen sz rowGen
  52. -- return $ CallMatrix { mat = m }
  53. -- where
  54. -- rowGen :: ArgumentIndex -> Gen [Order]
  55. -- rowGen 0 = return []
  56. -- rowGen n = do
  57. -- x <- arbitrary
  58. -- i <- choose (0, n - 1)
  59. -- return $ genericReplicate i unknown ++ [x] ++
  60. -- genericReplicate (n - 1 - i) unknown
  61. -- prop_callMatrix sz =
  62. -- forAll (callMatrix sz) $ \cm ->
  63. -- callMatrixInvariant cm
  64. -- &&
  65. -- size (mat cm) == sz
  66. -- prop_cmMul sz =
  67. -- forAll natural $ \c2 ->
  68. -- forAll (callMatrix sz) $ \cm1 ->
  69. -- forAll (callMatrix $ Size { rows = cols sz, cols = c2 }) $ \cm2 ->
  70. -- callMatrixInvariant (cm1 >*< cm2)
  71. -- tests :: IO Bool
  72. -- tests = runTests "Agda.Termination.CallMatrix"
  73. -- [ quickCheck' callMatrixInvariant
  74. -- , quickCheck' prop_Arbitrary_CallMatrix
  75. -- , quickCheck' prop_callMatrix
  76. -- , quickCheck' prop_cmMul
  77. -- ]
  78. -- where ?cutoff = DontCutOff -- CutOff 2 -- don't cut off in tests!