chore: Unsorted array
CI Workflow / build (push) Failing after 46s

This commit is contained in:
2026-07-30 10:05:17 -04:00
parent 01c4bd02b1
commit c4d7baa66a
4 changed files with 49 additions and 17 deletions
@@ -1,4 +0,0 @@
package com.ericampire.demo.dsa.datastructure.array
class StaticArray(val size: Int) {
}
@@ -0,0 +1,27 @@
package com.ericampire.demo.dsa.datastructure.array
class UnsortedArray(initSize: Int = 0) {
init {
require(initSize >= 0) { "Size must be greater than zero." }
}
var maxSize: Int = initSize
private set
private var filledSize = 0
private val internalContainer = IntArray(maxSize)
fun insert(value: Int) {
if (maxSize == filledSize) throw IndexOutOfBoundsException()
internalContainer[filledSize] = value
++filledSize
}
fun remove(index: Int) {
if (filledSize == 0) throw IllegalStateException("Array already empty")
if (index !in 0..<maxSize) throw IndexOutOfBoundsException()
--filledSize
internalContainer[index] = internalContainer[filledSize]
}
}
@@ -1,13 +0,0 @@
package com.ericampire.demo.dsa.datastructure.array
import kotlin.test.Test
import kotlin.test.assertEquals
class StaticArrayTest {
@Test
fun test() {
assertEquals(4, 2 + 2)
}
}
@@ -0,0 +1,22 @@
package com.ericampire.demo.dsa.datastructure.array
import org.junit.jupiter.api.assertThrows
import kotlin.test.Test
import kotlin.test.assertEquals
class UnsortedArrayTest {
@Test
fun `GIVEN a Array with negative size WHEN creating the object THEN throw an exception`() {
assertThrows<IllegalArgumentException> {
UnsortedArray(size = -1)
}
}
@Test
fun `GIVEN a Array without a param WHEN creating the object THEN the size is zero`() {
val array = UnsortedArray()
assertEquals(0, array.maxSize)
}
}