diff --git a/kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt b/kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt new file mode 100644 index 0000000000..759627b56e --- /dev/null +++ b/kotlin/src/main/kotlin/com/baeldung/kotlin/User.kt @@ -0,0 +1,3 @@ +package com.baeldung.kotlin + +data class User(val name: String, val age: Int, val hobbies: List) diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt index 7cf2faaf42..6fb6d0a288 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/EqualityTest.kt @@ -23,4 +23,36 @@ class EqualityTest { assertTrue(a == b) } + + @Test + fun givenUser_whenCheckReference_thenEqualReference() { + val user = User("John", 30, listOf("Hiking, Chess")) + val user2 = User("Sarah", 28, listOf("Shopping, Gymnastics")) + + assertFalse(user === user2) + } + + @Test + fun givenUser_whenCheckValue_thenStructurallyEqual() { + val user = User("John", 30, listOf("Hiking, Chess")) + val user2 = User("John", 30, listOf("Hiking, Chess")) + + assertTrue(user == user2) + } + + @Test + fun givenArray_whenCheckReference_thenEqualReference() { + val hobbies = arrayOf("Riding motorcycle, Video games") + val hobbies2 = arrayOf("Riding motorcycle, Video games") + + assertFalse(hobbies === hobbies2) + } + + @Test + fun givenArray_whenCheckContent_thenStructurallyEqual() { + val hobbies = arrayOf("Hiking, Chess") + val hobbies2 = arrayOf("Hiking, Chess") + + assertTrue(hobbies contentEquals hobbies2) + } } \ No newline at end of file