rocketraman
03/10/2021, 1:50 PMIterable<T>
and returns a subset of that given a single element T
. For example, assume my function has signature fun <T> Iterable<T>.priorAdjacent(elem: T): List<T>
.
Currently use the pattern: expectThat(elems) { get { priorAdjacent(elems[3]) } isEqualTo elems.slice(1..2) }
which reads nicely and produces understandable failure messages. That being said, is that the best approach?robfletcher
03/10/2021, 2:46 PMfun <T> Assertion.Builder<Iterable<T>>.priorAdjacent(elem: T): Assertion.Builder<List<T>> =
get { priorAdjacent(elem) }
robfletcher
03/10/2021, 2:47 PMexpectThat(elems)
.priorAdjacent(elems[3])
.isEqualTo(elems.slice(1..2))
christophsturm
03/10/2021, 2:47 PMchristophsturm
03/10/2021, 2:48 PMrobfletcher
03/10/2021, 2:49 PMrocketraman
03/10/2021, 2:50 PMpriorAdjacent
is the function under test yes. So this isn't idiomatic then?rocketraman
03/10/2021, 2:51 PMexpectThat(subject)
was the expected way to use Strikt. No pun intended 🙂christophsturm
03/10/2021, 2:53 PMrocketraman
03/10/2021, 2:54 PMrocketraman
03/10/2021, 3:04 PM▼ Expect that [Elem(idx=0), Elem(idx=1), Elem(idx=2)]:
▼ priorAdjacent(elems[1], ::isAdjacent):
✗ is equal to []
found [Elem(idx=0)]
vs
▼ Expect that [Elem(idx=0)]:
✗ is equal to []
found [Elem(idx=0)]
The only way to make sense of the latter message is via its context in the test code.robfletcher
03/10/2021, 3:52 PMexpectCatching {
elems.priorAdjacent(elems[3])
}
.isSuccess()
.isEqualTo(elems.slice(1..2))
rocketraman
03/10/2021, 4:10 PM▼ Expect that Success([Elem(idx=0), Elem(idx=1), Elem(idx=2)]):
✓ is success
▼ value:
✗ is equal to [Elem(idx=1), Elem(idx=2)]
found [Elem(idx=0), Elem(idx=1), Elem(idx=2)]
christophsturm
03/10/2021, 4:27 PMcall
?