From 20f13467c628f3529f7b278446f73804f65a636a Mon Sep 17 00:00:00 2001 From: joethei Date: Mon, 13 May 2019 16:49:17 +0200 Subject: [PATCH] + test cases #SPM-23: add work 20m testing --- .../spm/baudas/analysis/ShoppingCart.java | 7 +++++- .../spm/baudas/analysis/ShoppingCartTest.java | 23 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingCart.java b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingCart.java index 7153b1e..3f01c76 100644 --- a/src/main/java/de/hsel/spm/baudas/analysis/ShoppingCart.java +++ b/src/main/java/de/hsel/spm/baudas/analysis/ShoppingCart.java @@ -23,10 +23,15 @@ import java.util.Map; public class ShoppingCart implements Analysis, List>> { private Instances instances; + private Map, List> result; @Override public Map, List> getResult() { - Map, List> result = new HashMap<>(); + if(result != null) { + return result; + } + + result = new HashMap<>(); Apriori model = new Apriori(); diff --git a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java index e9e161d..fa28aa9 100644 --- a/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java +++ b/src/test/java/de/hsel/spm/baudas/analysis/ShoppingCartTest.java @@ -4,13 +4,17 @@ import org.junit.jupiter.api.Test; import java.io.File; import java.net.URL; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * Test class for shopping-cart analysis. * - * @author Julian Hinxlage + * @author Johannes Theiner * @version 0.1 */ class ShoppingCartTest { @@ -23,7 +27,10 @@ class ShoppingCartTest { ShoppingCart cart = new ShoppingCart(new File(url.getFile())); Map, List> result = cart.getResult(); - System.out.println(result); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik"))); + assertEquals(Collections.singletonList("Elektromaterial"), result.get(Collections.singletonList("Leuchten"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Schliesstechnik", "Renovierung"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Baustoffe"))); } @Test @@ -34,7 +41,11 @@ class ShoppingCartTest { ShoppingCart cart = new ShoppingCart(new File(url.getFile())); Map, List> result = cart.getResult(); - System.out.println(result); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Elektromaterial"))); + assertEquals(Collections.singletonList("Elektromaterial"), result.get(Arrays.asList("Renovierung", "Leuchten"))); + assertEquals(Collections.singletonList("Sanitaermaterial"), result.get(Arrays.asList("Fliesen", "Armaturen"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Renovierung"))); + } @Test @@ -45,7 +56,11 @@ class ShoppingCartTest { ShoppingCart cart = new ShoppingCart(new File(url.getFile())); Map, List> result = cart.getResult(); - System.out.println(result); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Elektromaterial"))); + assertEquals(Collections.singletonList("Sanitaermaterial"), result.get(Arrays.asList("Eisenwaren", "Fliesen", "Armaturen"))); + assertEquals(Collections.singletonList("Elektromaterial"), result.get(Arrays.asList("Renovierung", "Leuchten"))); + assertEquals(Collections.singletonList("Eisenwaren"), result.get(Arrays.asList("Handwerkzeuge", "Schliesstechnik", "Baustoffe"))); + } }