0 | ||| Definitions and functions for working with model coverage of a bunch of generated values.
1 | |||
2 | ||| Model coverage means a coverage in terms of the original data structure that is being generated,
3 | ||| e.g. involved types and their constructors.
26 | ||| Raw information of covered labels
32 | export
36 | export
43 | export
51 | export
54 | let (seed, sv) = runRandom seed $ runMaybeT $ runWriterT $ unGen {m=WriterT ModelCoverage $ MaybeT Rand} gen
57 | export
61 | export
65 | ||| Higher-level coverage information, in terms of types and constructors, etc.
66 | export
75 | MkCoverageGenInfo (mergeLeft ts ts') (mergeLeft cns cns') (let _ : Semigroup Nat := Additive in cis <+> cis')
84 | let cons = fromList $ (involvedTypes >>= \ty => (ty,) <$> ty.cons) <&> \(ty, co) => (show co.name, ty, co)
99 | ||| Returns a name by the generator's type
100 | |||
101 | ||| Say, for the `Fuel -> Gen em (n ** Fin n)` it returns name of `Data.Fin.Fin`
122 | ||| Derives function `A -> B` where `A` is determined by the given `TypeInfo`, `B` is determined by `retTy`
123 | |||
124 | ||| For each constructor of `A` the `matcher` function is applied and its result (of type `B`) is used as a result.
125 | ||| Currently, `B` must be a non-dependent type.
126 | deriveMatchingCons : (retTy : TTImp) -> (matcher : Con -> TTImp) -> (funName : Name) -> TypeInfo -> List Decl
141 | ||| Adds labelling of types and constructors to a given generator
142 | |||
143 | ||| Added labelling is not deep, i.e. it adds labels only for the returned type of a generator.
144 | ||| If returned type is a dependent pair, the rightmost type is taken into the account.
153 | let matchDPair = \expr => foldr (\_, r => var "Builtin.DPair.MkDPair" .$ implicitTrue .$ r) expr dpairLefts
164 | `(Test.DepTyCheck.Gen.label
166 | patClause
176 | ||| Boldens the rightmost name after the last dot, if coloured
179 | showType True ti = joinBy "." $ forget $ uncurry lappend $ map (singleton . show . bolden) $ unsnoc $ split (== '.') $ show ti.name
183 | mapMaybe (\ti => lookup ti cgi.coverageInfo <&> (ti,)) (SortedMap.values cgi.types) <&> \(ti, tyCovCnt, cons) => do
193 | else if tyCovCnt == 0 && (not anyCons || not noConsCovered) then [c BrightYellow "not mentioned"]
199 | )
202 | let status : String := if coCovCnt /= 0 then c BrightGreen "covered" ++ cntAddition coCovCnt else c BrightRed "not covered"
205 | export
208 | export
211 | export
218 | -- Try type
223 | -- Try constructor
226 | Just (ti, co) => { coverageInfo $= flip updateExisting ti $ mapSnd $ updateExisting (+cnt) co }