Is there any way that in the same test I have thes...
# kotest
k
Is there any way that in the same test I have these two assertions, first one passes second one fails? Don't get it...
Copy code
o1 shouldBe o2
(o1 == o2) shouldBe true
s
Shouldbe uses it's own equals for some types
What are the types of o1 and o2
k
just a regular class ...
I've tried overding equals() to always return false - still, frist one passes, second one fails
s
Data classes ?
Probably need to see the definition and data
k
nope, not data classes, ordinary class with a single member... I'll try to create a simple example to reproduce
my class implements Set and Iterable, maybe that messes it up?
s
Yep
Those are special cased
You may have found a bug
k
ah, cool... so I'm not going mad 😆
allright, I'll make a small example then to test it out... thanks!
With the latest kotest (5.1.0) only test #3 fails, first two succeed...
Copy code
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class ArraySet(val orders: Array<String>) : Set<String> {

    override val size get() = orders.size
    override fun iterator() = orders.iterator()
    override fun contains(element: String) = orders.contains(element)
    override fun containsAll(elements: Collection<String>) = orders.toList().containsAll(elements)
    override fun isEmpty() = orders.isEmpty()

    override fun equals(other: Any?): Boolean = false

    override fun hashCode(): Int {
        return orders.sumOf { it.hashCode() }
    }

    companion object {
        fun of(vararg orders: String): ArraySet {
            return ArraySet(orders.distinct().toTypedArray())
        }
    }
}

class ArraySetTest : FunSpec({
    val o1 = ArraySet.of("foo", "bar")
    val o2 = ArraySet.of("bar", "foo")
    val o3 = ArraySet.of("foo", "bar")
    val o4 = ArraySet.of("foo, bar, baz")

    test("1. permutation") {
        o1 shouldBe o2
    }
    test("2. completely equal") {
        o1 shouldBe o3
    }
    test("3. different elements") {
        o1 shouldBe o4
    }
})
s
Can you ticket on website
If you have time
k
👍 will do a bit later! will link the github issue...
s
👍
Ty