content: /*
   * This file was automatically generated by UTestGen and EvoSuite
   * Mon Mar 18 03:58:37 GMT 2024
   */
  
  package org.apache.lucene.search.exposed;
  
  import org.junit.jupiter.api.Test;
  import static org.junit.jupiter.api.Assertions.*;
  import org.junit.jupiter.api.Timeout;
  import java.util.concurrent.TimeUnit;
  import static org.evosuite.runtime.EvoAssertions.*;
  import org.apache.lucene.search.exposed.ExposedTimSort;
  import org.apache.lucene.search.exposed.compare.ComparatorFactory;
  import org.evosuite.runtime.EvoRunner;
  import org.evosuite.runtime.EvoRunnerParameters;
  import org.junit.runner.RunWith;
  
  @RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, separateClassLoader = true) 
  public class ExposedTimSort_ESTest extends ExposedTimSort_ESTest_scaffolding {
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking2ArgumentsWithNull() throws Throwable  {
        // Test that ExposedTimSort.sort() correctly sorts an array of integers
        int[] arg0 = new int[10];
        ExposedTimSort.sort(arg0, (ComparatorFactory.OrdinalComparator) null);
        assertArrayEquals(new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, arg0);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4Arguments0() throws Throwable  {
        // Given a list of integers to be sorted, a comparator factory, and an indirect comparator
        int[] arg0 = new int[510];
        ComparatorFactory.IndirectComparator arg3 = new ComparatorFactory.IndirectComparator(arg0);
        
        // When the sort method is called with the indirect comparator
        ExposedTimSort.sort(arg0, 309, 502, (ComparatorFactory.OrdinalComparator) arg3);
        
        // Then the list should be sorted according to the indirect comparator
        assertEquals(510, arg0.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsThrowsArrayIndexOutOfBoundsExceptionAndSortTaking4ArgumentsWithNonNull() throws Throwable  {
        // Setup
        int[] arg0 = new int[496];
        ComparatorFactory.IndirectComparator arg3 = new ComparatorFactory.IndirectComparator(arg0);
        
        try {
        ExposedTimSort.sort(arg0, 0, 510, (ComparatorFactory.OrdinalComparator) arg3);
        fail("Expecting exception: ArrayIndexOutOfBoundsException");
        } catch (ArrayIndexOutOfBoundsException e) {
        // Verify that the correct exception was thrown
        verifyException("org.apache.lucene.search.exposed.ExposedTimSort", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsWithNegativeAndNegative() throws Throwable  {
        // Test for sorting an array of integers with an indirect comparator
        int[] arg0 = new int[506];
        ComparatorFactory.IndirectComparator arg3 = new ComparatorFactory.IndirectComparator(arg0);
        // Undeclared exception!
        try {
        ExposedTimSort.sort(arg0, (-1808), (-1808), (ComparatorFactory.OrdinalComparator) arg3);
        fail("Expecting exception: ArrayIndexOutOfBoundsException");
        
        } catch(ArrayIndexOutOfBoundsException e) {
        //
        // no message in exception (getMessage() returned null)
        //
        verifyException("org.apache.lucene.search.exposed.ExposedTimSort", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsThrowsIllegalArgumentExceptionAndSortTaking4ArgumentsWithZero() throws Throwable  {
        int[] numbers = new int[510];
        ComparatorFactory.IndirectComparator comparator = new ComparatorFactory.IndirectComparator(numbers);
        // Undeclared exception!
        try {
        ExposedTimSort.sort(numbers, 309, 0, (ComparatorFactory.OrdinalComparator) comparator);
        fail("Expecting exception: IllegalArgumentException");
        } catch(IllegalArgumentException e) {
        // fromIndex(309) > toIndex(0)
        verifyException("org.apache.lucene.search.exposed.ExposedTimSort", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsAndSortTaking4ArgumentsWithZeroAndSortTaking4ArgumentsWithPositive() throws Throwable  {
        // Set up an array of integers to sort
        int[] arr = new int[487];
        
        // Create a comparator for indirect comparison
        ComparatorFactory.IndirectComparator comparator = new ComparatorFactory.IndirectComparator(arr);
        
        // Populate the array with some values
        arr[416] = 362;
        arr[469] = 362;
        arr[451] = 362;
        
        // Sort the array using ExposedTimSort
        ExposedTimSort.sort(arr, 362, 479, (ComparatorFactory.OrdinalComparator) comparator);
        ExposedTimSort.sort(arr, 0, 367, (ComparatorFactory.OrdinalComparator) comparator);
        
        // Assert that the array is sorted correctly
        assertEquals(487, arr.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsThrowsIllegalArgumentException0() throws Throwable  {
        // rollbacked to evosuite
        int[] arg0 = new int[510];
        ComparatorFactory.IndirectComparator arg3 = new ComparatorFactory.IndirectComparator(arg0);
        arg0[416] = 283;
        arg0[353] = 283;
        arg0[313] = 283;
        // Undeclared exception!
        try { 
          ExposedTimSort.sort(arg0, 283, 496, (ComparatorFactory.OrdinalComparator) arg3);
          fail("Expecting exception: IllegalArgumentException");
        
        } catch(IllegalArgumentException e) {
           //
           // Comparison method violates its general contract!
           //
           verifyException("org.apache.lucene.search.exposed.ExposedTimSort", e);
        }
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsAndSortTaking2Arguments0() throws Throwable  {
        // Given an array of integers and a comparator for indirect comparison
        int[] arg0 = new int[510];
        ComparatorFactory.IndirectComparator arg1 = new ComparatorFactory.IndirectComparator(arg0);
        
        // When we sort the array with TimSort using the indirect comparator
        ExposedTimSort.sort(arg0, 309, 502, (ComparatorFactory.OrdinalComparator) arg1);
        ExposedTimSort.sort(arg0, (ComparatorFactory.OrdinalComparator) arg1);
        
        // Then the array should be sorted according to the indirect comparison rule
        assertEquals(510, arg0.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsAndSortTaking2Arguments1() throws Throwable  {
        // Create an array of 505 integers and a comparator for indirect sorting
        int[] testArray = new int[505];
        ComparatorFactory.IndirectComparator comparator = new ComparatorFactory.IndirectComparator(testArray);
        
        // Set the value at index 416 to 283
        testArray[416] = 283;
        
        // Set the value at index 469 to 283
        testArray[469] = 283;
        
        // Set the value at index 313 to 283
        testArray[313] = 283;
        
        // Sort the array using indirect sorting with a comparator
        ExposedTimSort.sort(testArray, 283, 496, (ComparatorFactory.OrdinalComparator) comparator);
        
        // Sort the entire array using indirect sorting with a comparator
        ExposedTimSort.sort(testArray, (ComparatorFactory.OrdinalComparator) comparator);
        
        // Assert that the length of the array is 505
        assertEquals(505, testArray.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsThrowsIllegalArgumentException1() throws Throwable  {
        // Given
        int[] arg0 = new int[510];
        ComparatorFactory.IndirectComparator arg3 = new ComparatorFactory.IndirectComparator(arg0);
        arg0[316] = 309;
        arg0[313] = 309;
        
        // When
        try {
        ExposedTimSort.sort(arg0, 309, 502, (ComparatorFactory.OrdinalComparator) arg3);
        fail("Expecting exception: IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        // Then
        // Comparison method violates its general contract!
        verifyException("org.apache.lucene.search.exposed.ExposedTimSort", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking2Arguments0() throws Throwable  {
        // Arrange
        int[] input = new int[463];
        ComparatorFactory.IndirectComparator indirectComparator = new ComparatorFactory.IndirectComparator(input);
        input[462] = 419;
        
        // Act
        ExposedTimSort.sort(input, indirectComparator);
        
        // Assert
        assertEquals(463, input.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4Arguments1() throws Throwable  {
        // Given a sorted array of integers and a ComparatorFactory.IndirectComparator
        int[] inputArray = new int[506];
        ComparatorFactory.IndirectComparator comparator = new ComparatorFactory.IndirectComparator(inputArray);
        
        // When we sort the array using ExposedTimSort with an indirect comparator
        ExposedTimSort.sort(inputArray, 474, 478, comparator);
        
        // Then the length of the inputArray should be equal to 506
        assertEquals(506, inputArray.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsAndSortTaking4ArgumentsWithZeroAndSortTaking4ArgumentsWithZero() throws Throwable  {
        // Create an array of 490 integers
        int[] arg0 = new int[490];
        
        // Create a comparator that sorts arrays based on their indices
        ComparatorFactory.IndirectComparator arg3 = new ComparatorFactory.IndirectComparator(arg0);
        
        // Sort the array using ExposedTimSort, which is a sorting algorithm that uses an indirect comparison to sort the array
        ExposedTimSort.sort(arg0, 0, 0, (ComparatorFactory.OrdinalComparator) arg3);
        
        // Assert that the length of the sorted array is equal to 490
        assertEquals(490, arg0.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking4ArgumentsThrowsArrayIndexOutOfBoundsExceptionAndSortTaking4ArgumentsWithNull() throws Throwable  {
        int[] arg0 = new int[496];
        // Given: An array of length 496, and an index of 510 that is out of bounds
        try {
        ExposedTimSort.sort(arg0, 0, 510, (ComparatorFactory.OrdinalComparator) null);
        fail("Expecting exception: ArrayIndexOutOfBoundsException");
        } catch(ArrayIndexOutOfBoundsException e) {
        // When: The array is sorted with an invalid index
        // Then: An ArrayIndexOutOfBoundsException is thrown
        verifyException("java.util.Arrays", e);}
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking2Arguments1() throws Throwable  {
        // Given an array of 528 integers
        int[] input = new int[528];
        
        // When sorted using ExposedTimSort with an indirect comparator
        ComparatorFactory.IndirectComparator indirectComparator = new ComparatorFactory.IndirectComparator(input);
        ExposedTimSort.sort(input, (ComparatorFactory.OrdinalComparator) indirectComparator);
        
        // Then the array should have 528 elements and be sorted
        assertEquals(528, input.length);
    }
  
    @Test
    @Timeout(value = 4000 , unit = TimeUnit.MILLISECONDS)
    public void testSortTaking2Arguments2() throws Throwable  {
        // Given an array of integers and a comparator that compares the elements indirectly
        int[] arg0 = new int[33];
        ComparatorFactory.IndirectComparator arg1 = new ComparatorFactory.IndirectComparator(arg0);
        
        // When we sort the array using ExposedTimSort with the indirect comparator
        ExposedTimSort.sort(arg0, (ComparatorFactory.OrdinalComparator) arg1);
        
        // Then the length of the array should be 33
        assertEquals(33, arg0.length);
    }
  }
  