why
10/04/2020, 9:46 PMlistOf<Int>(1) shouldBe listOf<Int>()
sam
10/05/2020, 12:43 AMwhy
10/05/2020, 8:26 AMwhy
10/05/2020, 8:33 AM@Suppress("UNCHECKED_CAST")
infix fun <T, U : T> T.shouldBe(expected: U?) {
when (expected) {
is Matcher<*> -> should(expected as Matcher<T>)
else -> {
val actual = this
assertionCounter.inc()
eq(actual, expected)?.let(errorCollector::collectOrThrow)
}
}
}
when shouldBe
gets a null back it doesn’t throwwhy
10/05/2020, 8:36 AMprivate fun checkIterableEquality(actual: Iterable<*>, expected: Iterable<*>): Throwable? {
var index = 0
actual.zip(expected) { a, b ->
val t = eq(a, b)
if (t != null) return failure(
Expected(expected.show()),
Actual(actual.show()),
"Elements differ at index $index: "
)
index++
}
return null
}
why
10/05/2020, 8:36 AMpublic inline fun <T, R, V> Iterable<T>.zip(other: Iterable<R>, transform: (a: T, b: R) -> V): List<V> {
val first = iterator()
val second = other.iterator()
val list = ArrayList<V>(minOf(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10)))
while (first.hasNext() && second.hasNext()) {
list.add(transform(first.next(), second.next()))
}
return list
}
sam
10/05/2020, 10:02 AM