import static org.assertj.core.api.Assertions.assertThat;
import java.util.Comparator;
import org.junit.Before;
import org.junit.Test;
import com.gfg.model.GeekEmployee;
public class CheckingSortedArrayContentsUnitTest {
private static final int[] SORTEDINTEGERS = {10, 300, 5000, 70000, 900000};
private static final int[] NOTSORTEDINTEGERS = {100, 30, 11000, 7000};
private static final String[] SORTEDSTRINGS = {"champion", "geeks", "hackathon"};
private static final String[] NOTSORTEDSTRINGS = {"geeks", "champion", "tressurehunt", "hackathon"};
private static final GeekEmployee[] GEEKEMPLOYEESSORTEDBYNAME = {
new GeekEmployee(1, "Monica", 30),
new GeekEmployee(2, "Phoebe", 31),
new GeekEmployee(3, "Rachel", 27)};
private static final GeekEmployee[] GEEKEMPLOYEESNOTSORTEDBYNAME = {
new GeekEmployee(1, "Rachel", 31),
new GeekEmployee(2, "Monica", 26),
new GeekEmployee(3, "Phoebe", 27)};
private static final GeekEmployee[] GEEKEMPLOYEESSORTEDBYAGE = {
new GeekEmployee(1, "Ross", 28),
new GeekEmployee(2, "Chandler", 30),
new GeekEmployee(3, "Joey", 32)};
private static final GeekEmployee[] GEEKEMPLOYEESNOTSORTEDBYAGE = {
new GeekEmployee(1, "Chandler", 30),
new GeekEmployee(2, "Joey", 32),
new GeekEmployee(3, "Ross", 28)};
private CheckingSortedArrayContents sortedArrayChecker;
@Before
public void setup() {
sortedArrayChecker = new CheckingSortedArrayContents();
}
@Test
public void givenIntegerArray_thenReturnIfItIsSortedOrNot() {
assertThat(sortedArrayChecker.isSortedCheck2(SORTEDINTEGERS)).isEqualTo(true);
assertThat(sortedArrayChecker.isSortedCheck2(NOTSORTEDINTEGERS)).isEqualTo(false);
assertThat(sortedArrayChecker.isSortedCheck1RecursiveWay(SORTEDINTEGERS, SORTEDINTEGERS.length)).isEqualTo(true);
assertThat(sortedArrayChecker.isSortedCheck1RecursiveWay(NOTSORTEDINTEGERS, NOTSORTEDINTEGERS.length)).isEqualTo(false);
}
@Test
public void givenStringArray_thenReturnIfItIsSortedOrNot() {
assertThat(sortedArrayChecker.isSortedCheck4(SORTEDSTRINGS)).isEqualTo(true);
assertThat(sortedArrayChecker.isSortedCheck4(NOTSORTEDSTRINGS)).isEqualTo(false);
assertThat(sortedArrayChecker.isSortedCheck3InComparableWay(SORTEDSTRINGS, SORTEDSTRINGS.length)).isEqualTo(true);
assertThat(sortedArrayChecker.isSortedCheck3InComparableWay(NOTSORTEDSTRINGS, NOTSORTEDSTRINGS.length)).isEqualTo(false);
}
@Test
public void givenEmployeeArray_thenReturnIfItIsSortedOrNot() {
assertThat(sortedArrayChecker.isSortedCheck5InComparatorWay(GEEKEMPLOYEESSORTEDBYNAME, Comparator.comparing(GeekEmployee::getName))).isEqualTo(true);
assertThat(sortedArrayChecker.isSortedCheck5InComparatorWay(GEEKEMPLOYEESNOTSORTEDBYNAME, Comparator.comparing(GeekEmployee::getName))).isEqualTo(false);
assertThat(sortedArrayChecker.isSortedCheck5InComparatorWay(GEEKEMPLOYEESSORTEDBYAGE, Comparator.comparingInt(GeekEmployee::getAge))).isEqualTo(true);
assertThat(sortedArrayChecker.isSortedCheck5InComparatorWay(GEEKEMPLOYEESNOTSORTEDBYAGE, Comparator.comparingInt(GeekEmployee::getAge))).isEqualTo(false);
assertThat(sortedArrayChecker
.isSortedCheck6(GEEKEMPLOYEESSORTEDBYAGE, Comparator.comparingInt(GeekEmployee::getAge), GEEKEMPLOYEESSORTEDBYAGE.length))
.isEqualTo(true);
assertThat(sortedArrayChecker
.isSortedCheck6(GEEKEMPLOYEESNOTSORTEDBYAGE, Comparator.comparingInt(GeekEmployee::getAge), GEEKEMPLOYEESNOTSORTEDBYAGE.length))
.isEqualTo(false);
}
}