<commit_before>package ktx.collections

import org.junit.Assert.*
import org.junit.Test
import com.badlogic.gdx.utils.Array as GdxArray
import com.badlogic.gdx.utils.BooleanArray as GdxBooleanArray
import com.badlogic.gdx.utils.FloatArray as GdxFloatArray
import com.badlogic.gdx.utils.IntArray as GdxIntArray

/**
 * Tests utilities for LibGDX custom ArrayList equivalent - Array.
 * @author MJ
 */
class ArraysTest {
  @Test
  fun shouldCreateArray() {
    val array = gdxArrayOf<Any>()
    assertNotNull(array)
    assertTrue(array is GdxArray)
    assertEquals(0, array.size)
  }

  @Test
  fun shouldCreateArrayWithCustomInitialCapacity() {
    assertEquals(32, gdxArrayOf<Any>(initialCapacity = 32).items.size)
    assertEquals(128, gdxArrayOf<Any>(initialCapacity = 128).items.size)
  }

  @Test
  fun shouldCreateArraysWithCustomOrderedSetting() {
    assertFalse(gdxArrayOf<Any>(ordered = false).ordered)
    assertTrue(gdxArrayOf<Any>(ordered = true).ordered)
  }

  @Test
  fun shouldCreateArraysWithCustomElements() {
    val array = gdxArrayOf("1", "2", "3")
    assertEquals(3, array.size)
    assertTrue("1" in array)
    assertTrue("2" in array)
    assertTrue("3" in array)
  }

  @Test
  fun shouldReportSize() {
    val array: GdxArray<String>? = GdxArray.with("1", "2", "3")
    assertEquals(3, array.size())
    assertEquals(array!!.size, array.size())
    val nullArray: GdxArray<Any>? = null
    assertEquals(0, nullArray.size())
  }

  @Test
  fun shouldReportEmptyStatus() {
    val array: GdxArray<String>? = GdxArray.with("1", "2", "3")
    assertFalse(array.isEmpty())
    val emptyArray = GdxArray<Any>()
    assertTrue(emptyArray.isEmpty())
    val nullArray: GdxArray<Any>? = null
    assertTrue(nullArray.isEmpty())
  }

  @Test
  fun shouldReportNonEmptyStatus() {
    val array: GdxArray<String>? = GdxArray.with("1", "2", "3")
    assertTrue(array.isNotEmpty())
    val emptyArray = GdxArray<Any>()
    assertFalse(emptyArray.isNotEmpty())
    val nullArray: GdxArray<Any>? = null
    assertFalse(nullArray.isNotEmpty())
  }

  @Test
  fun shouldReturnLastValidIndexOfArray() {
    val array = GdxArray.with("1", "2", "3")
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyArray() {
    val emptyArray = GdxArray<Any>()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfIntArray() {
    val array = GdxIntArray.with(1, 2, 3)
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyIntArray() {
    val emptyArray = GdxIntArray()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfFloatArray() {
    val array = GdxFloatArray.with(1f, 2f, 3f)
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyFloatArray() {
    val emptyArray = GdxFloatArray()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfBooleanArray() {
    val array = GdxBooleanArray.with(true, false, true)
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyBooleanArray() {
    val emptyArray = GdxBooleanArray()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnAlternativeIfElementIsNull() {
    val array = GdxArray.with("0", null, "2")
    assertEquals("0", array.get(0, "3"))
    assertEquals("3", array[1, "3"]) // This method is also available through square bracket operator.
    assertEquals("2", array.get(2, "3"))
    assertEquals("3", array[3, "3"])
  }

  @Test
  fun shouldAddAllValuesFromCustomIterable() {
    val array = GdxArray<String>()
    assertEquals(0, array.size)
    assertFalse("1" in array)
    assertFalse("2" in array)
    assertFalse("3" in array)

    array.addAll(listOf("1", "2", "3"))
    assertEquals(3, array.size)
    assertTrue("1" in array)
    assertTrue("2" in array)
    assertTrue("3" in array)
  }

  @Test
  fun shouldRemoveAllValuesFromCustomIterable() {
    val array = GdxArray.with("1", "2", "3")
    assertEquals(3, array.size)<commit_msg>Improved LibGDX arrays tests.<commit_after>package ktx.collections

import org.junit.Assert.*
import org.junit.Test
import com.badlogic.gdx.utils.Array as GdxArray
import com.badlogic.gdx.utils.BooleanArray as GdxBooleanArray
import com.badlogic.gdx.utils.FloatArray as GdxFloatArray
import com.badlogic.gdx.utils.IntArray as GdxIntArray

/**
 * Tests utilities for LibGDX custom ArrayList equivalent - Array.
 * @author MJ
 */
class ArraysTest {
  @Test
  fun shouldCreateArray() {
    val array = gdxArrayOf<Any>()
    assertNotNull(array)
    assertTrue(array is GdxArray)
    assertEquals(0, array.size)
  }

  @Test
  fun shouldCreateArrayWithCustomInitialCapacity() {
    assertEquals(32, gdxArrayOf<Any>(initialCapacity = 32).items.size)
    assertEquals(128, gdxArrayOf<Any>(initialCapacity = 128).items.size)
  }

  @Test
  fun shouldCreateArraysWithCustomOrderedSetting() {
    assertFalse(gdxArrayOf<Any>(ordered = false).ordered)
    assertTrue(gdxArrayOf<Any>(ordered = true).ordered)
  }

  @Test
  fun shouldCreateArraysWithCustomElements() {
    val array = gdxArrayOf("1", "2", "3")
    assertEquals(3, array.size)
    assertTrue("1" in array)
    assertTrue("2" in array)
    assertTrue("3" in array)
  }

  @Test
  fun shouldReportSizeOfArray() {
    val array = GdxArray.with("1", "2", "3")
    assertEquals(3, array.size())
    assertEquals(array!!.size, array.size())
    val nullArray: GdxArray<Any>? = null
    assertEquals(0, nullArray.size())
  }

  @Test
  fun shouldReportSizeOfIntArray() {
    val array = GdxIntArray.with(1, 2, 3)
    assertEquals(3, array.size())
    assertEquals(array!!.size, array.size())
    val nullArray: GdxIntArray? = null
    assertEquals(0, nullArray.size())
  }

  @Test
  fun shouldReportSizeOfFloatArray() {
    val array = GdxFloatArray.with(1f, 2f, 3f)
    assertEquals(3, array.size())
    assertEquals(array!!.size, array.size())
    val nullArray: GdxFloatArray? = null
    assertEquals(0, nullArray.size())
  }

  @Test
  fun shouldReportSizeOfBooleanArray() {
    val array = GdxBooleanArray.with(true, false, true)
    assertEquals(3, array.size())
    assertEquals(array!!.size, array.size())
    val nullArray: GdxBooleanArray? = null
    assertEquals(0, nullArray.size())
  }

  @Test
  fun shouldReportEmptyStatus() {
    val array: GdxArray<String>? = GdxArray.with("1", "2", "3")
    assertFalse(array.isEmpty())
    val emptyArray = GdxArray<Any>()
    assertTrue(emptyArray.isEmpty())
    val nullArray: GdxArray<Any>? = null
    assertTrue(nullArray.isEmpty())
  }

  @Test
  fun shouldReportNonEmptyStatus() {
    val array: GdxArray<String>? = GdxArray.with("1", "2", "3")
    assertTrue(array.isNotEmpty())
    val emptyArray = GdxArray<Any>()
    assertFalse(emptyArray.isNotEmpty())
    val nullArray: GdxArray<Any>? = null
    assertFalse(nullArray.isNotEmpty())
  }

  @Test
  fun shouldReturnLastValidIndexOfArray() {
    val array = GdxArray.with("1", "2", "3")
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyArray() {
    val emptyArray = GdxArray<Any>()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnNegativeLastIndexForNullArray() {
    val nullArray: GdxArray<Any>? = null
    assertEquals(-1, nullArray.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfIntArray() {
    val array = GdxIntArray.with(1, 2, 3)
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyIntArray() {
    val emptyArray = GdxIntArray()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnNegativeLastIndexForNullIntArray() {
    val nullArray: GdxIntArray? = null
    assertEquals(-1, nullArray.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfFloatArray() {
    val array = GdxFloatArray.with(1f, 2f, 3f)
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyFloatArray() {
    val emptyArray = GdxFloatArray()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnNegativeLastIndexForNullFloatArray() {
    val nullArray: GdxFloatArray? = null
    assertEquals(-1, nullArray.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfBooleanArray() {
    val array = GdxBooleanArray.with(true, false, true)
    assertEquals(2, array.lastIndex)
  }

  @Test
  fun shouldReturnLastValidIndexOfEmptyBooleanArray() {
    val emptyArray = GdxBooleanArray()
    assertEquals(-1, emptyArray.lastIndex)
  }

  @Test
  fun shouldReturnNegativeLastIndexForNullBooleanArray() {
    val nullArray: GdxBooleanArray? = null
    assertEquals(-1, nullArray.lastIndex)
  }

  @Test
  fun shouldReturnAlternativeIfElementIsNull() {
    val array = GdxArray.with("0", null, "2")
    assertEquals("0", array.get(0, "3"))
    assertEquals("3", array[1, "3"]) // This method is also available through square bracket operator.
    assertEquals("2", array.get(2, "3"))
    assertEquals("3", array[3, "3"])
  }

  @Test
  fun shouldAddAllValuesFromCustomIterable() {
    val array = GdxArray<String>()
    assertEquals(0, array.size)
    assertFalse("1" in array)
    assertFalse("2" in array)
    assertFalse("3" in array)

    array.addAll(listOf("1", "2", "3"))
    assertEquals(3, array.size)
    assertTrue("1" in array)
    assertTrue("2" in array)
    assertTrue("3" in array)
  }

  @Test
  fun shouldRemoveAllValuesFromCustomIterable() {
    val array = GdxArray.with("1", "2", "3")
    assertEquals(3, array.size)
{'fraction_non_alphanumeric': 0.12680779710752463, 'fraction_numerical': 0.017396772165164536, 'mean_word_length': 4.0652866242038215, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3224270', 'n_tokens_mistral': 3173, 'n_tokens_neox': 3112, 'n_words': 651}