Skip to content

Commit

Permalink
test(#12): update tests of removings in NotEmptyMutableList
Browse files Browse the repository at this point in the history
  • Loading branch information
LVMVRQUXL committed Aug 11, 2022
1 parent 5d62a3b commit 405e89f
Showing 1 changed file with 29 additions and 36 deletions.
Expand Up @@ -405,75 +405,68 @@ class NotEmptyMutableListTest {

@Nested
inner class RemoveAt {
// ---------- Int ----------

@Test
fun `should remove the head from a list containing several elements and with an index as an int that equals 0`() {
// GIVEN
val expectedList: NotEmptyList<String> = NotEmptyList("one", "two")
val head = "one"
val list: NotEmptyMutableList<String> =
NotEmptyMutableList(head, "two")
val index = 0
val target = "target"
val list: NotEmptyMutableList<String> = expectedList
.toNotEmptyMutableList()
.apply { add(index, target) }
// WHEN
val element: String = assertDoesNotThrow { list removeAt index }
// THEN
element assertEquals target
list.run {
assertFalse { element in this }
head assertNotEquals element
size assertEquals expectedList.size
head assertEquals expectedList.head
forEachIndexed { index2: Int, element2: String ->
element2 assertEquals expectedList[index2]
}
element.run {
assertEquals(head)
assertNotEquals(list.head)
assertFalse { this in list }
}
}

@Test
fun `shouldn't remove the head from a singleton list and with an index as an int that equals 0`() {
// GIVEN
val expectedList: NotEmptyList<String> = NotEmptyList("one")
val list: NotEmptyMutableList<String> =
expectedList.toNotEmptyMutableList()
val head = "one"
val list: NotEmptyMutableList<String> = NotEmptyMutableList(head)
val index = 0
// WHEN
val element: String = assertDoesNotThrow { list removeAt index }
// THEN
element assertEquals expectedList.head
assertTrue { element in list }
list.size assertEquals expectedList.size
list.head assertEquals expectedList.head
element.run {
assertEquals(head)
assertEquals(list.head)
assertTrue { this in list }
}
}

@Test
fun `should remove an element with an index as an int in 1 until the list's size`() {
// GIVEN
val expectedList: NotEmptyList<String> = NotEmptyList("one", "two")
val target = "three"
val list: NotEmptyMutableList<String> = expectedList
.toNotEmptyMutableList()
.also { it += target }
val tail = "two"
val list: NotEmptyMutableList<String> =
NotEmptyMutableList("one", tail)
val index: Int = list.size - 1
// WHEN
val element: String = assertDoesNotThrow { list removeAt index }
// THEN
element assertEquals target
list.run {
assertFalse { element in this }
size assertEquals expectedList.size
forEachIndexed { index2: Int, element2: String ->
element2 assertEquals expectedList[index2]
}
}
element assertEquals tail
assertFalse { element in list }
}

@Test
fun `should throw an error with an index as an int that is out of bounds`() {
// GIVEN
val list: NotEmptyMutableList<String> = NotEmptyMutableList("one")
val index: Int = list.size
// WHEN & THEN
assertFailsWith<IndexOutOfBoundsException> { list removeAt index }
// WHEN
val error: IndexOutOfBoundsException =
assertFailsWith { list removeAt index }
// THEN
error.message.assertNotNull() assertEquals indexOutOfBoundsMessage(
index,
list.size
)
}
}

Expand Down

0 comments on commit 405e89f

Please sign in to comment.