style: reformat source and tests, fix imports and packages
This commit is contained in:
@@ -1,134 +1,137 @@
|
||||
package ru.project.finder;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class StudentOccurrenceIndexFinderTest
|
||||
{
|
||||
private StudentOccurrenceIndexFinder finder;
|
||||
private MyList<Student> students;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import ru.project.collection.MyLinkedList;
|
||||
import ru.project.collection.MyList;
|
||||
import ru.project.student.Student;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
finder = new StudentOccurrenceIndexFinder();
|
||||
students = new MyLinkedList<>();
|
||||
}
|
||||
public class StudentOccurrenceIndexFinderTest {
|
||||
private StudentOccurrenceIndexFinder finder;
|
||||
private MyList<Student> students;
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_emptyList_returnsEmptyArray() {
|
||||
int[] result = finder.findOccurrences(students, new Student("A12", 4.5, 1));
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
@Test
|
||||
void shouldTesfindOccurrences_noMatches_returnsEmptyArray() {
|
||||
students.add(new Student("A12", 4.0, 101));
|
||||
students.add(new Student("B23", 3.5, 102));
|
||||
Student target = new Student("C34", 4.8, 103); // такого нет
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
finder = new StudentOccurrenceIndexFinder();
|
||||
students = new MyLinkedList<>();
|
||||
}
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
@Test
|
||||
void shouldTesfindOccurrences_singleMatch_returnsCorrectIndex() {
|
||||
students.add(new Student("A12", 4.0, 101));
|
||||
students.add(new Student("B23", 3.5, 102)); // target здесь
|
||||
students.add(new Student("C34", 4.8, 103));
|
||||
@Test
|
||||
void shouldTesfindOccurrences_emptyList_returnsEmptyArray() {
|
||||
int[] result = finder.findOccurrences(students, new Student("A12", 4.5, 1));
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
Student target = new Student("B23", 3.5, 102);
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
@Test
|
||||
void shouldTesfindOccurrences_noMatches_returnsEmptyArray() {
|
||||
students.add(new Student("A12", 4.0, 101));
|
||||
students.add(new Student("B23", 3.5, 102));
|
||||
Student target = new Student("C34", 4.8, 103); // такого нет
|
||||
|
||||
assertEquals(1, result.length);
|
||||
assertEquals(1, result[0]);
|
||||
}
|
||||
@Test
|
||||
void shouldTesfindOccurrences_multipleMatches_returnsAllIndicesSorted() {
|
||||
// индексы: 0, 2, 4 — должны вернуться в порядке возрастания
|
||||
students.add(new Student("A12", 4.5, 101)); // match
|
||||
students.add(new Student("B23", 3.8, 102));
|
||||
students.add(new Student("A12", 4.5, 101)); // match
|
||||
students.add(new Student("C34", 4.0, 103));
|
||||
students.add(new Student("A12", 4.5, 101)); // match
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
Student target = new Student("A12", 4.5, 101);
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
@Test
|
||||
void shouldTesfindOccurrences_singleMatch_returnsCorrectIndex() {
|
||||
students.add(new Student("A12", 4.0, 101));
|
||||
students.add(new Student("B23", 3.5, 102)); // target здесь
|
||||
students.add(new Student("C34", 4.8, 103));
|
||||
|
||||
assertEquals(3, result.length);
|
||||
assertArrayEquals(new int[]{0, 2, 4}, result);
|
||||
}
|
||||
Student target = new Student("B23", 3.5, 102);
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_allElementsMatch_returnsAllIndices() {
|
||||
Student s = new Student("X99", 5.0, 999);
|
||||
students.add(s);
|
||||
students.add(s);
|
||||
students.add(s);
|
||||
assertEquals(1, result.length);
|
||||
assertEquals(1, result[0]);
|
||||
}
|
||||
|
||||
int[] result = finder.findOccurrences(students, s);
|
||||
assertEquals(3, result.length);
|
||||
assertArrayEquals(new int[]{0, 1, 2}, result);
|
||||
}
|
||||
@Test
|
||||
void shouldTesfindOccurrences_multipleMatches_returnsAllIndicesSorted() {
|
||||
// индексы: 0, 2, 4 — должны вернуться в порядке возрастания
|
||||
students.add(new Student("A12", 4.5, 101)); // match
|
||||
students.add(new Student("B23", 3.8, 102));
|
||||
students.add(new Student("A12", 4.5, 101)); // match
|
||||
students.add(new Student("C34", 4.0, 103));
|
||||
students.add(new Student("A12", 4.5, 101)); // match
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_differentAverageGrade_noMatch() {
|
||||
students.add(new Student("A12", 4.50, 101));
|
||||
Student target = new Student("A12", 4.51, 101); // отличается балл
|
||||
Student target = new Student("A12", 4.5, 101);
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
assertEquals(3, result.length);
|
||||
assertArrayEquals(new int[] {0, 2, 4}, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_allElementsMatch_returnsAllIndices() {
|
||||
Student s = new Student("X99", 5.0, 999);
|
||||
students.add(s);
|
||||
students.add(s);
|
||||
students.add(s);
|
||||
|
||||
int[] result = finder.findOccurrences(students, s);
|
||||
assertEquals(3, result.length);
|
||||
assertArrayEquals(new int[] {0, 1, 2}, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_differentAverageGrade_noMatch() {
|
||||
students.add(new Student("A12", 4.50, 101));
|
||||
Student target = new Student("A12", 4.51, 101); // отличается балл
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_differentGroupNumber_noMatch() {
|
||||
students.add(new Student("A12", 4.5, 101));
|
||||
Student target = new Student("B12", 4.5, 101); // другая группа
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_differentRecordBookNumber_noMatch() {
|
||||
students.add(new Student("A12", 4.5, 101));
|
||||
Student target = new Student("A12", 4.5, 102); // другой номер зачетки
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_nullList_throwsException() {
|
||||
Student target = new Student("A12", 4.5, 101);
|
||||
assertThrows(IllegalArgumentException.class, () -> finder.findOccurrences(null, target));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_nullTarget_throwsException() {
|
||||
assertThrows(IllegalArgumentException.class, () -> finder.findOccurrences(students, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_resultIsSorted() {
|
||||
String[] validGroups = {"A00", "A01", "B12", "C99", "X55"};
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
String group = validGroups[i % validGroups.length];
|
||||
double grade = (3.0 + (i % 3)) / 2.0;
|
||||
if (i % 3 == 0) {
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_differentGroupNumber_noMatch() {
|
||||
students.add(new Student("A12", 4.5, 101));
|
||||
Student target = new Student("B12", 4.5, 101); // другая группа
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
} else {
|
||||
students.add(new Student(group, grade, 200 + i));
|
||||
}
|
||||
}
|
||||
Student target = new Student("A12", 4.5, 101);
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_differentRecordBookNumber_noMatch() {
|
||||
students.add(new Student("A12", 4.5, 101));
|
||||
Student target = new Student("A12", 4.5, 102); // другой номер зачетки
|
||||
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
assertEquals(0, result.length);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_nullList_throwsException() {
|
||||
Student target = new Student("A12", 4.5, 101);
|
||||
assertThrows(IllegalArgumentException.class, () -> finder.findOccurrences(null, target));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void shouldTesfindOccurrences_nullTarget_throwsException() {
|
||||
assertThrows(IllegalArgumentException.class, () -> finder.findOccurrences(students, null));
|
||||
}
|
||||
@Test
|
||||
void shouldTesfindOccurrences_resultIsSorted() {
|
||||
String[] validGroups = {"A00", "A01", "B12", "C99", "X55"};
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
String group = validGroups[i % validGroups.length];
|
||||
double grade = (3.0 + (i % 3)) / 2.0;
|
||||
if (i % 3 == 0) {
|
||||
|
||||
students.add(new Student("A12", 4.5, 101));
|
||||
} else {
|
||||
students.add(new Student(group, grade, 200 + i));
|
||||
}
|
||||
}
|
||||
Student target = new Student("A12", 4.5, 101);
|
||||
int[] result = finder.findOccurrences(students, target);
|
||||
|
||||
|
||||
for (int i = 1; i < result.length; i++) {
|
||||
assertTrue(result[i] > result[i - 1], "Результат должен быть отсортирован");
|
||||
}
|
||||
for (int i = 1; i < result.length; i++) {
|
||||
assertTrue(result[i] > result[i - 1], "Результат должен быть отсортирован");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user