add tests

This commit is contained in:
jacekpoz 2024-04-12 13:13:20 +02:00
parent 991c864826
commit f6d24306c3
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
2 changed files with 61 additions and 11 deletions

View file

@ -1,11 +0,0 @@
package pl.jacekpoz;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AppTest {
@Test void appHasAGreeting() {
App classUnderTest = new App();
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
}
}

View file

@ -0,0 +1,61 @@
package pl.jacekpoz;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class GFTest {
@Test
void additionWorks() {
GF a = new GF(5, 2);
GF b = new GF(5, 4);
assertEquals(new GF(5, 1), a.add(b));
}
@Test
void subtractionWorks() {
GF a = new GF(5, 2);
GF b = new GF(5, 4);
assertEquals(new GF(5, 3), a.subtract(b));
}
@Test
void multiplicationWorks() {
GF a = new GF(6, 2);
GF b = new GF(6, 4);
assertEquals(new GF(6, 2), a.multiply(b));
}
@Test
void divisionWorks() {
GF a = new GF(7, 2);
GF b = new GF(7, 4);
assertEquals(new GF(7, 4), a.divide(b));
}
@Test
void divisionByZeroFails() {
GF a = new GF(5, 2);
GF b = new GF(5, 0);
Throwable ex = assertThrows(IllegalArgumentException.class, () -> {
a.divide(b);
});
assertEquals("division by 0 is illegal", ex.getMessage());
}
@Test
void differentCharacteristicsFail() {
GF a = new GF(10, 5);
GF b = new GF(8, 5);
Throwable ex = assertThrows(IllegalArgumentException.class, () -> {
a.add(b);
});
assertEquals("both arguments must have the same characteristic", ex.getMessage());
}
}