Closed chshersh closed 5 years ago
Do you have any idea regarding this? would it be enough to map through the Treap, taking the measures and comparing the list of measures?
@sphaso Sure, I have an idea. Currently unit tests for the update and construction functions look like this:
What would be nice is to write the tests in the following form:
it "delete 0 removes first element" $
Treap.delete 0 smallTreap `describedAs` [2..5] `with` 14
In order to make this work we need to add several custom functions to the Test.Common
module, specifically:
with :: [a] -> m -> ([a], m)
with = (,)
describedAs :: Treap m a -> ([a], m) -> Expectation
(the constraints and fixities are to figure out)
@chshersh great. I'm working on it on my fork. Do you think these types are good or should they be more generic?
with :: [Int] -> Int -> ([Int], Sum Int)
describedAs :: TestTreap -> ([Int], Sum Int) -> Bool
@sphaso Almost correct. But instead of Bool
, describedAs
should have result type Expectation
from the hspec
library and implemented in terms of shouldBe
@chshersh gotcha, I completely missed the Expectation type :) I opened a PR.
Currently unit tests compare two treaps only by comparing elements via
toList
function. It would be more robust to test also the measure of theTreap
. But for that we need more convenient util functions.