toEqual

infix fun <T> Expect<T>.toEqual(expected: T): Expect<T>(source)

Expects that the subject of this expectation is (equal to) expected where the comparison is carried out based on Any.equals.

Use toBeEqualComparingTo if you want a comparison based on Comparable.compareTo.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

expect(12) toEqual 12 // holds

fails {
    expect(12) toEqual 11
}

// holds, toEqual is based on equality, use toBeTheInstance for identity
expect(listOf(1)) toEqual listOf(1)

fails { // because array has not implemented equals, so is equivalent to toBeTheInstance
    expect(arrayOf(1)) toEqual arrayOf(1)
}
@JvmName(name = "toBeNull")
infix fun <T : BigDecimal> Expect<T?>.toEqual(expected: Nothing?): Expect<T?>(source)

Expects that the subject of this expectation (a BigDecimal) is null.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

// Use toEqual only to check against null if your subject is a BigDecimal
// Use toEqualNumerically or toEqualIncludingScale if you want to compare it against another BigDecimal
expect(null as BigDecimal?) toEqual null

fails {
    expect(BigDecimal("-12345.6789") as BigDecimal?) toEqual null
}

infix fun <T : BigDecimal> Expect<T>.toEqual(expected: T): Nothing(source)
@JvmName(name = "toBeNullable")
infix fun <T : BigDecimal?> Expect<T>.toEqual(expected: T): Nothing(source)

Deprecated

Use `toEqualNumerically` if you expect that the following assertion holds: `expect(BigDecimal("10")).toBe(BigDecimal("10.0"))` However, if you expect it to be wrong (because `BigDecimal.scale` differ), then use `toEqualIncludingScale`.

Replace with

toEqualNumerically(expected) or toEqualIncludingScale(expected)

Deprecated as it would compare the subject against expected including scale -- many developers are not aware of that.

Use toEqualNumerically if you expect that the following assertion holds:

expect(BigDecimal("10").toBe(BigDecimal("10.0"))

However, if you expect it to be wrong (because BigDecimal.scale differ), then use toEqualIncludingScale.

Since

0.17.0