add tests
This commit is contained in:
parent
991c864826
commit
f6d24306c3
2 changed files with 61 additions and 11 deletions
|
@ -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");
|
||||
}
|
||||
}
|
61
lab2/zad2/app/src/test/java/pl/jacekpoz/GFTest.java
Normal file
61
lab2/zad2/app/src/test/java/pl/jacekpoz/GFTest.java
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue