Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ds.shell;
- import static org.junit.jupiter.api.Assertions.*;
- import java.io.File;
- import java.io.IOException;
- import java.util.Scanner;
- import org.junit.jupiter.api.AfterAll;
- import org.junit.jupiter.api.BeforeAll;
- import org.junit.jupiter.api.Test;
- class ShellSortTest {
- static Student[] students;
- static String originalPath = "/path/to/students.csv";
- static String sortedPath = "/path/to/sorted_students.csv";
- @BeforeAll
- static void setUpBeforeClass() throws Exception {
- students = TextFileParser.readFile(originalPath);
- }
- @AfterAll
- static void tearDownAfterClass() throws Exception {
- students = null;
- }
- @Test
- void testReadsFromFile() throws IOException {
- assertNotNull(students);
- assertTrue(students[0] instanceof Student);
- assertEquals(1000000, students.length);
- }
- @Test
- void testSortsStudents() {
- ShellSort.sort(students);
- assertEquals(100, students[0].getStudentID());
- assertEquals(101, students[1].getStudentID());
- assertEquals(102, students[2].getStudentID());
- assertEquals(20110396, students[543823].getStudentID());
- assertEquals(10185139, students[385139].getStudentID());
- assertEquals(30333094, students[999998].getStudentID());
- assertEquals(30333095, students[999999].getStudentID());
- }
- @Test
- void testWritesToFile() throws IOException {
- new File(sortedPath).delete(); // delete old file
- ShellSort.sort(students);
- TextFileParser.writeFile(students, sortedPath);
- assertTrue(new File(sortedPath).exists());
- Scanner scanner = new Scanner(new File(sortedPath));
- /* Check if students are loaded correctly from file lines */
- String line = scanner.nextLine();
- String[] parts = line.split(";");
- Student s1 = new Student(Integer.parseInt(parts[0]), parts[1], parts[2],
- parts[3], parts[4], Integer.parseInt(parts[5]));
- assertEquals(100, s1.getStudentID());
- scanner.close();
- }
- @Test
- void testStudentsAreComparable() {
- Student s1 = new Student(1, "A", "01-01-1997", "IBU", "IT", 2018);
- Student s2 = new Student(2, "B", "31-12-1997", "IBU", "IT", 2018);
- assertTrue(s2.compareTo(s1) > 0);
- assertTrue(s1.compareTo(s2) < 0);
- assertTrue(s1.compareTo(s1) == 0);
- }
- }
Add Comment
Please, Sign In to add comment