Safe Haskell | None |
---|---|
Language | GHC2021 |
Test.Credit
Synopsis
- data Size
- logstar :: Size -> Credit
- log2 :: Size -> Credit
- linear :: Size -> Credit
- data Strategy
- genExecutionTrace :: Arbitrary op => Strategy -> Gen (Tree op)
- class (Arbitrary op, Show op) => DataStructure (t :: (Type -> Type) -> Type) op | t -> op where
- runTree :: forall (t :: (Type -> Type) -> Type) op. DataStructure t op => Tree op -> Either Error ()
- runTreeTrace :: forall (t :: (Type -> Type) -> Type) op. (MemoryStructure t, DataStructure t op) => Tree op -> String
- checkCredits :: forall (t :: (Type -> Type) -> Type) op. DataStructure t op => Strategy -> Property
- checkCreditsTrace :: forall (t :: (Type -> Type) -> Type) op. (MemoryStructure t, DataStructure t op) => Strategy -> Property
Common Time-Complexity Functions
Instances
Enum Size Source # | |
Num Size Source # | |
Integral Size Source # | |
Real Size Source # | |
Defined in Test.Credit Methods toRational :: Size -> Rational # | |
Show Size Source # | |
Eq Size Source # | |
Ord Size Source # | |
Pretty Size Source # | |
Defined in Test.Credit | |
Monad m => MemoryCell m Size Source # | |
Defined in Test.Credit Methods prettyCell :: Size -> m Memory Source # |
Execution Traces for Testing
Running Data Structures on Execution Traces
class (Arbitrary op, Show op) => DataStructure (t :: (Type -> Type) -> Type) op | t -> op where Source #
Methods
cost :: Size -> op -> Credit Source #
Given a size and an operation, return the cost of the operation. This function can not inspect the internal state of the data structure.
create :: MonadLazy m => m (t m) Source #
create a new instance of the data structure. We allow the computation to be lazy, since lazy data structures often contain thunks even if they contain no elements. The create data structure is assumed to have size zero.
perform :: MonadInherit m => Size -> t m -> op -> m (Size, t m) Source #
Given a data structure, its size, and an operation, return the updated size and data structure. We allow the size to depend on the internal state of the data structure, since some operations, like insertions into a binary search tree, might return different sizes depending on whether a new element is already present.
Instances
(Arbitrary a, BoundedDeque q, Show a) => DataStructure (BD q a) (DequeOp a) Source # | |
(Arbitrary a, BoundedDeque q, Show a) => DataStructure (D q a) (DequeOp a) Source # | |
(Arbitrary a, Ord a, BoundedHeap h, Show a) => DataStructure (BH h a) (HeapOp a) Source # | |
(Arbitrary a, Ord a, BoundedHeap h, Show a) => DataStructure (H h a) (HeapOp a) Source # | |
(Arbitrary a, BoundedQueue q, Show a) => DataStructure (Q q a) (QueueOp a) Source # | |
(Arbitrary a, BoundedRandomAccess q, Show a) => DataStructure (RA q a) (RandomAccessOp a) Source # | |
(Arbitrary a, Ord a, BoundedSortable q, Show a) => DataStructure (S q a) (SortableOp a) Source # | |
runTree :: forall (t :: (Type -> Type) -> Type) op. DataStructure t op => Tree op -> Either Error () Source #
Evaluate an execution trace of operations on the given data structure using the credit monad. Returns either an error or unit if the evaluation succeeded.
runTreeTrace :: forall (t :: (Type -> Type) -> Type) op. (MemoryStructure t, DataStructure t op) => Tree op -> String Source #
Evaluate an execution trace of operations on the given data structure using the credit monad. Returns a pretty-printed string of the execution trace annotated with the internal state of the data structure at each step.
Testing Data Structures on Execution Traces
checkCredits :: forall (t :: (Type -> Type) -> Type) op. DataStructure t op => Strategy -> Property Source #
Test the given data structure in the credit monad using the given strategy. This property only reports if evaluation succeeded or not.
checkCreditsTrace :: forall (t :: (Type -> Type) -> Type) op. (MemoryStructure t, DataStructure t op) => Strategy -> Property Source #
Test the given data structure in the credit monad using the given strategy. If evaluation fails, this property prints the execution trace annotated with the internal state of the data structure at each step.