Order.hs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. {-# LANGUAGE ImplicitParams #-}
  2. module Internal.Termination.Order ( tests ) where
  3. import Agda.Termination.CutOff
  4. import Agda.Termination.Order
  5. import Internal.Helpers
  6. import qualified Internal.Termination.Semiring as Semiring
  7. ------------------------------------------------------------------------------
  8. {- instances cannot have implicit arguments?! GHC manual says:
  9. 7.8.3.1. Implicit-parameter type constraints
  10. You can't have an implicit parameter in the context of a class or instance declaration. For example, both these declarations are illegal:
  11. class (?x::Int) => C a where ...
  12. instance (?x::a) => Foo [a] where ...
  13. Reason: exactly which implicit parameter you pick up depends on
  14. exactly where you invoke a function. But the ``invocation'' of
  15. instance declarations is done behind the scenes by the compiler, so
  16. it's hard to figure out exactly where it is done. Easiest thing is to
  17. outlaw the offending types.
  18. instance (?cutoff :: CutOff) => Arbitrary Order where
  19. arbitrary = frequency
  20. [(20, return Unknown)
  21. ,(80, elements [- ?cutoff .. ?cutoff + 1] >>= Decr)
  22. ] -- no embedded matrices generated for now.
  23. -}
  24. instance Arbitrary Order where
  25. arbitrary = frequency
  26. [(30, return Unknown)
  27. ,(70, elements [0,1] >>= return . Decr True)
  28. ] -- no embedded matrices generated for now.
  29. instance CoArbitrary Order where
  30. coarbitrary (Decr _ k) = variant 0
  31. coarbitrary Unknown = variant 1
  32. coarbitrary (Mat m) = variant 2
  33. ------------------------------------------------------------------------------
  34. prop_decr :: (?cutoff :: CutOff) => Bool -> Int -> Bool
  35. prop_decr u = isOrder . decr u
  36. prop_orderSemiring :: (?cutoff :: CutOff) => Order -> Order -> Order -> Bool
  37. prop_orderSemiring = Semiring.semiringInvariant orderSemiring
  38. ------------------------------------------------------------------------
  39. -- * All tests
  40. ------------------------------------------------------------------------
  41. -- (ASR 2018-01-06) Since some properties use implicit parameters we
  42. -- cannot use 'allProperties' for collecting all the tests (see
  43. -- https://github.com/nick8325/quickcheck/issues/193 ).
  44. tests :: TestTree
  45. tests = testGroup "Internal.Termination.Order"
  46. [ testProperty "prop_decr" prop_decr
  47. , testProperty "prop_orderSemiring" prop_orderSemiring
  48. ]
  49. where ?cutoff = DontCutOff -- CutOff 2 -- don't cut off in tests!