Add oving 5

This commit is contained in:
Andreas Omholt Olsen
2026-02-09 15:28:09 +01:00
parent 6193e26ba1
commit 55c36a603a
33 changed files with 1586 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package oving5.named;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class NamedComparatorTest {
private NamedComparator comparator;
private Person1 p1;
private Person2 p2;
@BeforeEach
public void setUp() {
comparator = new NamedComparator();
p1 = new Person1("Aleksander", "Vestlund");
p2 = new Person2("Dan Vestlund");
}
@Test
@DisplayName("Check that people with the same name are equivalent")
public void testSameFullName() {
assertEquals(0, comparator.compare(p1, p1));
assertEquals(0, comparator.compare(p2, p2));
}
@Test
@DisplayName("Check that given names are compared when the family names are the same")
public void testSameFamilyName() {
// Return negative since first givenName is before second
assertTrue(comparator.compare(p1, p2) < 0, "Aleksander should come before Dan");
// Return positive since first givenName is after second
assertTrue(comparator.compare(p2, p1) > 0, "Dan should come after Aleksander");
}
@Test
@DisplayName("Check that family names are compared correctly")
public void testDifferentFamilyName() {
p2.setFamilyName("Bertelsen");
// Return negative since first familyName is before second
assertTrue(comparator.compare(p2, p1) < 0, "Bertelsen should come before Vestlund");
// Return positive since first familyName is after second
assertTrue(comparator.compare(p1, p2) > 0, "Vestlund should come after Bertelsen");
}
}