// test_array_improvements.nyash - ArrayBox Phase 2 improvements test
// Testing: sort(), reverse(), indexOf(), slice() methods

print("📦 Testing ArrayBox improvements...")

// Basic array creation and setup
local arr, result, sliceResult

print("=== Setup: Creating test array ===")
arr = new ArrayBox()
arr.push(3)
arr.push(1)
arr.push(4)
arr.push(1)
arr.push(5)
print("Original array: " + arr.toString())

print("\n=== Test 1: sort() method ===")
arr.sort()
print("After sort(): " + arr.toString())
// Expected: [1, 1, 3, 4, 5]

print("\n=== Test 2: reverse() method ===")
arr.reverse()
print("After reverse(): " + arr.toString())
// Expected: [5, 4, 3, 1, 1]

print("\n=== Test 3: indexOf() method ===")
result = arr.indexOf(4)
print("indexOf(4): " + result.toString())
// Expected: 1

result = arr.indexOf(1)
print("indexOf(1): " + result.toString())  
// Expected: 3 (first occurrence from current order)

result = arr.indexOf(999)
print("indexOf(999): " + result.toString())
// Expected: -1 (not found)

print("\n=== Test 4: slice() method ===")
sliceResult = arr.slice(1, 4)
print("slice(1, 4): " + sliceResult.toString())
// Expected: [4, 3, 1] (indices 1, 2, 3)

sliceResult = arr.slice(0, 2)
print("slice(0, 2): " + sliceResult.toString())
// Expected: [5, 4] (indices 0, 1)

sliceResult = arr.slice(2, 10)  // End beyond array
print("slice(2, 10): " + sliceResult.toString())
// Expected: [3, 1, 1] (indices 2 to end)

print("\n=== Test 5: Mixed types sorting ===")
local mixedArr
mixedArr = new ArrayBox()
mixedArr.push("banana")
mixedArr.push(2)
mixedArr.push("apple")
mixedArr.push(1)
mixedArr.push("cherry")
print("Mixed array before sort: " + mixedArr.toString())

mixedArr.sort()
print("Mixed array after sort: " + mixedArr.toString())
// Expected: numbers first (1, 2), then strings alphabetically

print("\n=== Test 6: FloatBox integration ===")
local floatArr
floatArr = new ArrayBox()
floatArr.push(new FloatBox(3.14))
floatArr.push(1)
floatArr.push(new FloatBox(2.71))
floatArr.push(4)
print("Float array before sort: " + floatArr.toString())

floatArr.sort()
print("Float array after sort: " + floatArr.toString())
// Expected: [1, 2.71, 3.14, 4]

print("\n✅ ArrayBox Phase 2 improvements tests completed!")