From 859cc6fe4a6da802bdd961e1c8004db2ba5030f1 Mon Sep 17 00:00:00 2001 From: jorge Date: Fri, 19 Apr 2024 22:17:48 +0200 Subject: [PATCH 01/12] Created the head of state test file and added a few test cases --- .../generator/HeadOfStateGeneratorTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java new file mode 100644 index 00000000..f95a61a8 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java @@ -0,0 +1,56 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +public class HeadOfStateGeneratorTest { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); + + @Test + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + +} From e4f9e2031c67a9fbee01e071790c5fcc3477ed1c Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:10:38 +0200 Subject: [PATCH 02/12] Improved the tests for the head of state generator --- .../generator/HeadOfStateGeneratorTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java index f95a61a8..ebff864c 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; @@ -19,6 +20,11 @@ public class HeadOfStateGeneratorTest { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); + @Test + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + @Test public void QuestionsAreGeneratedTest() { assertNotNull(questions); @@ -53,4 +59,13 @@ public void AllAnswersInAQuestionAreDifferent() { } } + @Test + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who's the current head of the government of ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + } From 1795b9ae2e3bfa716666c3581c18e61bb26adfb9 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:15:11 +0200 Subject: [PATCH 03/12] The test now run in order --- .../generator/HeadOfStateGeneratorTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java index ebff864c..e33d130c 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java @@ -9,23 +9,29 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import main.java.questionGenerator.QuestionGenerator; import main.java.questionGenerator.question.Question; import main.java.questionGenerator.question.QuestionType; +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class HeadOfStateGeneratorTest { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); @Test + @Order(1) public void AmountOfQuestions() { assertTrue(questions.size()<=3); } @Test + @Order(2) public void QuestionsAreGeneratedTest() { assertNotNull(questions); assertNotEquals(List.of(questions), questions); @@ -35,6 +41,7 @@ public void QuestionsAreGeneratedTest() { } @Test + @Order(3) public void AllQuestionsAreDifferentTest() { List messages = new ArrayList(); for(Question q : questions) { @@ -47,6 +54,7 @@ public void AllQuestionsAreDifferentTest() { } @Test + @Order(4) public void AllAnswersInAQuestionAreDifferent() { for(Question q : questions) { assertFalse(q.getAnswers().isEmpty()); @@ -60,6 +68,7 @@ public void AllAnswersInAQuestionAreDifferent() { } @Test + @Order(5) public void TheQuestionFollowsTheExpectedMessage() { for(Question q : questions) { assertTrue(q.getQuestion().contains("Who's the current head of the government of ")); From 5e58811554076307a93c5f7b7aeb4a3c778f5009 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:17:47 +0200 Subject: [PATCH 04/12] Added tests for the director generator --- .../generator/DirectorGeneratorTests.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java new file mode 100644 index 00000000..6dd1cf2f --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -0,0 +1,76 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +public class DirectorGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.DIRECTOR, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who's the director of the ")); + assertTrue(q.getQuestion().endsWith("?")); + } + } + +} \ No newline at end of file From 4763bf7e29abc564e1ab5ba506620b770e3b36a3 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:19:56 +0200 Subject: [PATCH 05/12] The order of the tests of the director generator now works as intended --- .../questionGenerator/generator/DirectorGeneratorTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java index 6dd1cf2f..049dfd56 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -9,13 +9,16 @@ import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import main.java.questionGenerator.QuestionGenerator; import main.java.questionGenerator.question.Question; import main.java.questionGenerator.question.QuestionType; +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class DirectorGeneratorTests { private QuestionGenerator qg = QuestionGenerator.getInstance(); From 637459ac061df70b7812279ce635dba5e604dd91 Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:32:41 +0200 Subject: [PATCH 06/12] Added the test of the videogame developer generator --- .../VideogameDeveloperGenerator.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java new file mode 100644 index 00000000..05fdb9ab --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogameDeveloperGenerator { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_DEVELOPER, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who were the developers of the videogame ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:33:53 +0200 Subject: [PATCH 07/12] Added new test cases for the director and head of government tests --- .../generator/DirectorGeneratorTests.java | 23 +++++++++++++++++++ .../generator/HeadOfStateGeneratorTest.java | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java index 049dfd56..6a6f35a6 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.List; +import org.json.JSONArray; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -76,4 +77,26 @@ public void TheQuestionFollowsTheExpectedMessage() { } } + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:34:36 +0200 Subject: [PATCH 08/12] Fixed the name of the head of government test --- ...ateGeneratorTest.java => HeadOfGovernmentGeneratorTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename questionGenerator/src/test/java/questionGenerator/generator/{HeadOfStateGeneratorTest.java => HeadOfGovernmentGeneratorTest.java} (98%) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java similarity index 98% rename from questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java rename to questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java index 54a9a773..d2ad302d 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/HeadOfStateGeneratorTest.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java @@ -20,7 +20,7 @@ import main.java.questionGenerator.question.QuestionType; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class HeadOfStateGeneratorTest { +public class HeadOfGovernmentGeneratorTest { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.HEAD_OF_GOVERMENT, 3); From 235e3b8e5afd1ab1edddc066a7824ead748912bd Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:36:44 +0200 Subject: [PATCH 09/12] Fixed the problem in the videogame developer generator test name --- ...operGenerator.java => VideogameDeveloperGeneratorTests.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename questionGenerator/src/test/java/questionGenerator/generator/{VideogameDeveloperGenerator.java => VideogameDeveloperGeneratorTests.java} (98%) diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java similarity index 98% rename from questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java rename to questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java index 05fdb9ab..ffb357f0 100644 --- a/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGenerator.java +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameDeveloperGeneratorTests.java @@ -20,7 +20,7 @@ import main.java.questionGenerator.question.QuestionType; @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class VideogameDeveloperGenerator { +public class VideogameDeveloperGeneratorTests { private QuestionGenerator qg = QuestionGenerator.getInstance(); private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_DEVELOPER, 3); From 549c267171ff3be35f84c552b7db5db6fd172e6f Mon Sep 17 00:00:00 2001 From: jorge Date: Sat, 20 Apr 2024 10:39:13 +0200 Subject: [PATCH 10/12] Added test for the videogame publisher generator --- .../VideogamePublisherGeneratorTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java new file mode 100644 index 00000000..8132bf77 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogamePublisherGeneratorTests.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogamePublisherGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_PUBLISHER, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Who was the publisher of the videogame ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:41:12 +0200 Subject: [PATCH 11/12] Added tests for the videogame genre generator --- .../VideogameGenreGeneratorTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java new file mode 100644 index 00000000..fb3e8e35 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameGenreGeneratorTests.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogameGenreGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_GENRE, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("What's the main genre of the videogame ")); + assertTrue(q.getQuestion().endsWith("?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i Date: Sat, 20 Apr 2024 10:44:03 +0200 Subject: [PATCH 12/12] Added test for the videogame country generator --- .../VideogameCountryGeneratorTests.java | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java diff --git a/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java b/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java new file mode 100644 index 00000000..328ab630 --- /dev/null +++ b/questionGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java @@ -0,0 +1,103 @@ +package test.java.questionGenerator.generator; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +import main.java.questionGenerator.QuestionGenerator; +import main.java.questionGenerator.question.Question; +import main.java.questionGenerator.question.QuestionType; + +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class VideogameCountryGeneratorTests { + + private QuestionGenerator qg = QuestionGenerator.getInstance(); + private List questions = qg.generateQuestions(QuestionType.VIDEOGAME_COUNTRY, 3); + + @Test + @Order(1) + public void AmountOfQuestions() { + assertTrue(questions.size()<=3); + } + + @Test + @Order(2) + public void QuestionsAreGeneratedTest() { + assertNotNull(questions); + assertNotEquals(List.of(questions), questions); + for(Question q : questions) { + assertNotNull(q); + } + } + + @Test + @Order(3) + public void AllQuestionsAreDifferentTest() { + List messages = new ArrayList(); + for(Question q : questions) { + String question = q.getQuestion(); + assertFalse(messages.contains(question)); + messages.add(question); + } + + assertEquals(questions.size(), messages.size()); + } + + @Test + @Order(4) + public void AllAnswersInAQuestionAreDifferent() { + for(Question q : questions) { + assertFalse(q.getAnswers().isEmpty()); + List answers = new ArrayList(); + for(String answer : q.getAnswers()) { + assertFalse(answers.contains(answer)); + answers.add(answer); + } + assertEquals(q.getAnswers().size(), answers.size()); + } + } + + @Test + @Order(5) + public void TheQuestionFollowsTheExpectedMessage() { + for(Question q : questions) { + assertTrue(q.getQuestion().contains("Which country is the videogame ")); + assertTrue(q.getQuestion().endsWith(" from?")); + } + + } + + @Test + @Order(6) + public void QuestionInTheJSONIsTheExpectedOne() { + for(Question q : questions) { + String expectedQuestion = q.getQuestion(); + String actualQuestion = q.getJSON().get("question").toString(); + assertEquals(expectedQuestion, actualQuestion); + } + } + + @Test + @Order(7) + public void AnswersInTheJSONAreTheExpectedOnes() { + for(Question q : questions) { + List answers = q.getAnswers(); + JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); + for(int i=0; i