generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from Arquisoft/Question_Generator_Tests
Question generator tests
- Loading branch information
Showing
6 changed files
with
617 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
questionGenerator/src/test/java/questionGenerator/generator/DirectorGeneratorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
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 DirectorGeneratorTests { | ||
|
||
private QuestionGenerator qg = QuestionGenerator.getInstance(); | ||
private List<Question> 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<String> messages = new ArrayList<String>(); | ||
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<String> answers = new ArrayList<String>(); | ||
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("?")); | ||
} | ||
} | ||
|
||
@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<String> answers = q.getAnswers(); | ||
JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); | ||
for(int i=0; i<actualAnswers.length(); i++) { | ||
assertEquals(answers.get(i), String.valueOf(actualAnswers.get(i))); | ||
} | ||
} | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
...ionGenerator/src/test/java/questionGenerator/generator/HeadOfGovernmentGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 HeadOfGovernmentGeneratorTest { | ||
|
||
private QuestionGenerator qg = QuestionGenerator.getInstance(); | ||
private List<Question> 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); | ||
for(Question q : questions) { | ||
assertNotNull(q); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
public void AllQuestionsAreDifferentTest() { | ||
List<String> messages = new ArrayList<String>(); | ||
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<String> answers = new ArrayList<String>(); | ||
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 current head of the government of ")); | ||
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<String> answers = q.getAnswers(); | ||
JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); | ||
for(int i=0; i<actualAnswers.length(); i++) { | ||
assertEquals(answers.get(i), String.valueOf(actualAnswers.get(i))); | ||
} | ||
} | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
...onGenerator/src/test/java/questionGenerator/generator/VideogameCountryGeneratorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Question> 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<String> messages = new ArrayList<String>(); | ||
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<String> answers = new ArrayList<String>(); | ||
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<String> answers = q.getAnswers(); | ||
JSONArray actualAnswers = q.getJSON().getJSONArray("answers"); | ||
for(int i=0; i<actualAnswers.length(); i++) { | ||
assertEquals(answers.get(i), String.valueOf(actualAnswers.get(i))); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.