Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question generator tests #111

Merged
merged 12 commits into from
Apr 20, 2024
Merged
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)));
}
}
}

}
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)));
}
}
}

}
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)));
}
}
}

}
Loading