From e621c764be6a68f8b5f12b020f7a71cd35f98651 Mon Sep 17 00:00:00 2001 From: ucrhh Date: Thu, 11 Feb 2021 09:51:32 +0100 Subject: [PATCH] test TreeNumberGenerator --- .../latexcreator/TreeNumberGenerator.java | 3 ++ .../latexcreator/TreeNumberGeneratorTest.java | 38 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGeneratorTest.java diff --git a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGenerator.java b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGenerator.java index c17c8f3..2aef835 100644 --- a/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGenerator.java +++ b/src/main/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGenerator.java @@ -14,6 +14,9 @@ public class TreeNumberGenerator { } protected void push() { + if (current < 0) { + throw new IllegalStateException("The first step must add a step to the tree"); + } numbers.add(current); } diff --git a/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGeneratorTest.java b/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGeneratorTest.java new file mode 100644 index 0000000..0f23139 --- /dev/null +++ b/src/test/java/edu/kit/typicalc/view/content/typeinferencecontent/latexcreator/TreeNumberGeneratorTest.java @@ -0,0 +1,38 @@ +package edu.kit.typicalc.view.content.typeinferencecontent.latexcreator; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + + +class TreeNumberGeneratorTest { + + @Test + void normalFunctionalityTest() { + List expected = List.of(0, 1, 1, 1, 2, 2, 3); + TreeNumberGenerator generator = new TreeNumberGenerator(); + generator.incrementPush(); + generator.incrementPush(); + generator.push(); + generator.push(); + generator.incrementPush(); + generator.push(); + generator.incrementPush(); + List actual = generator.getNumbers(); + + assertEquals(expected.size(), actual.size()); + for (int i = 0; i < expected.size(); i++) { + assertEquals(expected.get(i), actual.get(i)); + } + } + + @Test + void pushExceptionTest() { + TreeNumberGenerator generator = new TreeNumberGenerator(); + assertThrows(IllegalStateException.class, generator::push); + } + +}