Skip to content

Instantly share code, notes, and snippets.

@ib84
Last active December 16, 2015 10:39
Show Gist options
  • Save ib84/5421735 to your computer and use it in GitHub Desktop.
Save ib84/5421735 to your computer and use it in GitHub Desktop.
Naive version of a series of tests (validations) for a test.
val validatations : Seq[(String, (S,Seq[(K,Seq[V])]) => Try[Boolean])]=
Seq(
("def findLT(key: K)", (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b = index.findLT(key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => ordering.lt(pair._1, key)).map(_._1).toSet
b.forall(key => c.contains(key))
}
}
assert(allTrue, "findLT failed")
allTrue
}
),
("def findGT(key: K)", (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b = index.findGT(key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => ordering.gt(pair._1, key)).map(_._1).toSet
b.forall(key => c.contains(key))
}
}
assert(allTrue, "findGT failed")
allTrue
}
),
("def findLTE(key: K)", (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b = index.findLTE(key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => ordering.lteq(pair._1, key)).map(_._1).toSet
b.forall(key => c.contains(key))
}
}
assert(allTrue, "findLTE failed")
allTrue
}
),
("def findGTE(key: K)", (index:S, dataSeq:Seq[(K,Seq[V])]) => Try
{
val allTrue = dataSeq.forall{ case (key, valueSeq) =>
{
val b = index.findGTE(key)
val ordering = implicitly[Ordering[K]]
val c = dataSeq.filter( pair => ordering.gteq(pair._1, key)).map(_._1).toSet
b.forall(key => c.contains(key))
}
}
assert(allTrue, "findGTE failed")
allTrue
}
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment