Esempio n. 1
0
 def test_question_checkAnswer_wrong(self):
     quest = 'q?'
     ans = []
     ans.append(Answer('a', 1))
     ans.append(Answer('b', 0))
     ans.append(Answer('c', 0))
     question = Question(quest, ans)
     res = question.checkAnswer('b')
     self.assertEqual(res, 0)
Esempio n. 2
0
 def test_question_checkAnswer_correct(self):
     quest = 'q?'
     ans = []
     ans.append(Answer('a', 1))
     ans.append(Answer('b', 0))
     ans.append(Answer('c', 0))
     question = Question(quest, ans)
     given_answer = 'a'
     res = question.checkAnswer(given_answer)
     self.assertEqual(res, 1)
Esempio n. 3
0
    def test_quiz_checkAnswer_correct(self):
        quest = 'q?'
        ans = []
        questions = []
        ans.append(Answer('a', 1))
        ans.append(Answer('b', 0))
        ans.append(Answer('c', 0))
        questions.append(Question(quest, ans))
        questions.append(Question(quest, ans))
        questions.append(Question(quest, ans))

        quiz = Quiz(0, questions)
        res = quiz.checkAnswer('a')
        self.assertEqual(res, 1)
        res = quiz.checkAnswer('a')
        self.assertEqual(res, 2)
Esempio n. 4
0
 def test_quiz_islost(self):
     quest = 'q?'
     ans = []
     questions = []
     ans.append(Answer('a', 1))
     ans.append(Answer('b', 0))
     ans.append(Answer('c', 0))
     questions.append(Question(quest, ans))
     questions.append(Question(quest, ans))
     quiz = Quiz(0, questions)
     quiz.checkAnswer('a')
     self.assertEqual(quiz.currentQuestion, 1)
     try:
         quiz.checkAnswer('b')
     except LostQuizError:
         self.assertEqual(quiz.currentQuestion, -1)
Esempio n. 5
0
    def test_quiz_iscompleted(self):
        quest = 'q?'
        ans = []
        questions = []
        ans.append(Answer('a', 1))
        ans.append(Answer('b', 0))
        ans.append(Answer('c', 0))
        questions.append(Question(quest, ans))
        questions.append(Question(quest, ans))
        quiz = Quiz(0, questions)

        quiz.checkAnswer('a')
        self.assertFalse(quiz.isCompleted())

        try:
            quiz.checkAnswer('a')
        except CompletedQuizError:
            self.assertTrue(quiz.isCompleted())
Esempio n. 6
0
 def test_question_checkAnswer_nonexisting(self):
     quest = 'q?'
     ans = []
     ans.append(Answer('a', 1))
     ans.append(Answer('b', 0))
     ans.append(Answer('c', 0))
     question = Question(quest, ans)
     given_answer = 'd'
     self.assertRaises(NonExistingAnswerError, question.checkAnswer,
                       given_answer)
Esempio n. 7
0
    def test_quiz_checkAnswer_wrong(self):
        quest = 'q?'
        ans = []
        questions = []
        ans.append(Answer('a', 1))
        ans.append(Answer('b', 0))
        ans.append(Answer('c', 0))
        questions.append(Question(quest, ans))

        quiz = Quiz(0, questions)
        self.assertRaises(LostQuizError, quiz.checkAnswer, 'b')
Esempio n. 8
0
    def test_quiz_checkAnswer_complete(self):
        quest = 'q?'
        ans = []
        questions = []
        ans.append(Answer('a', 1))
        ans.append(Answer('b', 0))
        ans.append(Answer('c', 0))
        questions.append(Question(quest, ans))

        quiz = Quiz(0, questions)
        self.assertRaises(CompletedQuizError, quiz.checkAnswer, 'a')
Esempio n. 9
0
def create_quiz(request):
    global _LOADED_QUIZZES, _QUIZNUMBER
    json_data = request.get_json()
    qs = json_data['questions']
    questions = []
    for q in qs:
        question = q['question']
        answers = []
        for a in q['answers']:
            answers.append(Answer(a['answer'], a['correct']))
        question = Question(question, answers)
        questions.append(question)

    _LOADED_QUIZZES[str(_QUIZNUMBER)] = Quiz(_QUIZNUMBER, questions)
    _QUIZNUMBER += 1

    return jsonify({'quiznumber': _QUIZNUMBER - 1})
Esempio n. 10
0
    def createDummyQuiz(self):
        json_data = {
            "questions": [{
                "question":
                "What's the answer to all questions?",
                "answers": [{
                    "answer": "33",
                    "correct": 0
                }, {
                    "answer": "42",
                    "correct": 1
                }, {
                    "answer": "1",
                    "correct": 0
                }]
            }, {
                "question":
                "What's the answer to all questions?",
                "answers": [{
                    "answer": "33",
                    "correct": 0
                }, {
                    "answer": "42",
                    "correct": 1
                }, {
                    "answer": "1",
                    "correct": 0
                }]
            }]
        }
        qs = json_data['questions']
        questions = []
        for q in qs:
            question = q['question']
            answers = []
            for a in q['answers']:
                answers.append(Answer(a['answer'], a['correct']))
            question = Question(question, answers)
            questions.append(question)

        return Quiz(1, questions)
Esempio n. 11
0
 def test_isCompleted(self):
     answer_1 = Answer("la prima", 1)
     answer_2 = Answer("la seconda")
     question = Question("Buona?", [answer_1, answer_2])
     quiz = Quiz(1, [question])
     self.assertEqual(quiz.isCompleted(), False)
 def test_isCompleted(self):
     answer_1 = Answer("la prima", 1)
     answer_2 = Answer("la seconda")
     question = Question("Buona?", [answer_1, answer_2])
     self.assertEqual(question.checkAnswer("la prima"), True)