From f6d24306c3c1c24eb9f78794c9ede82874fbb564 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Fri, 12 Apr 2024 13:13:20 +0200 Subject: [PATCH] add tests --- .../src/test/java/pl/jacekpoz/AppTest.java | 11 ---- .../app/src/test/java/pl/jacekpoz/GFTest.java | 61 +++++++++++++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) delete mode 100644 lab2/zad2/app/src/test/java/pl/jacekpoz/AppTest.java create mode 100644 lab2/zad2/app/src/test/java/pl/jacekpoz/GFTest.java diff --git a/lab2/zad2/app/src/test/java/pl/jacekpoz/AppTest.java b/lab2/zad2/app/src/test/java/pl/jacekpoz/AppTest.java deleted file mode 100644 index 7b37322..0000000 --- a/lab2/zad2/app/src/test/java/pl/jacekpoz/AppTest.java +++ /dev/null @@ -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"); - } -} diff --git a/lab2/zad2/app/src/test/java/pl/jacekpoz/GFTest.java b/lab2/zad2/app/src/test/java/pl/jacekpoz/GFTest.java new file mode 100644 index 0000000..42fcc50 --- /dev/null +++ b/lab2/zad2/app/src/test/java/pl/jacekpoz/GFTest.java @@ -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()); + } +}