Beispiel #1
0
def test_survey_get_questions() -> None:
    q1 = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    q2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    q3 = CheckboxQuestion(3, "choose", [1, 2, 3, 4])
    q_list = [q1, q2, q3]
    s = Survey(q_list)
    assert s.get_questions() == [q1, q2, q3]
Beispiel #2
0
def test_survey_survey_get_questions() -> None:
    """A test for get_questions() in class Survey."""
    q1 = CheckboxQuestion(1, 'ABC', ['a', '1', ','])
    q2 = YesNoQuestion(2, 'BBC')
    s = Survey([q1, q2])
    lst = s.get_questions()
    assert q1 in lst and q2 in lst
Beispiel #3
0
 def all_answered(self, surveys: Survey) -> bool:
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     for student in self.students:
         for question in surveys.get_questions():
             if not student.has_answer(question):
                 return False
     return True
Beispiel #4
0
 def all_answered(self, survey: Survey) -> bool:
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     acc = []
     for student in self.students:
         for question in survey.get_questions():
             if question.validate_answer(student.get_answer(question)):
                 acc.append(True)
     return False not in acc
Beispiel #5
0
 def all_answered(self, survey: Survey) -> bool:  # done
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     for stud in self.get_students():
         for q in survey.get_questions():
             if not stud.has_answer(q):
                 # if one stud does not have an answer will return false
                 return False
     return True
Beispiel #6
0
 def all_answered(self, survey: Survey) -> bool:
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     valid_answers = True
     questions = survey.get_questions()
     for question in questions:
         for student in self.students:
             if not student.has_answer(question):
                 valid_answers = False
     return valid_answers
Beispiel #7
0
 def all_answered(self, survey: Survey) -> bool:
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     questions = survey.get_questions()
     valid = True
     for question in questions:
         for student in self.students:
             if not question.validate_answer(student.get_answer(question)):
                 valid = False
     return valid
Beispiel #8
0
 def all_answered(self, survey: Survey) -> bool:
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     question_list = survey.get_questions()
     for student in self.students:
         for question in question_list:
             answer = student.get_answer(question)
             if answer is None or not answer.is_valid(question):
                 return False
     return True
Beispiel #9
0
 def all_answered(self, survey: Survey) -> bool:  #NOT DONE
     """
     Return True iff all the students enrolled in this course have a valid
     answer for every question in <survey>.
     """
     for student in self.students:
         q = survey.get_questions()
         for question in q:
             this_students_ans = student.get_answer(question)
             valid = question.validate_answer(this_students_ans.content)
             if not valid:
                 return False
     return True
def answer_questions(survey_: survey.Survey, course_: course.Course,
                     data: Dict[str, Any]) -> None:
    """
    Answer the questions in <survey_> by assigning answers to the
    student in <course_> accoding to the data in <data>
    """
    students = {s.id: s for s in course_.get_students()}
    questions = {q.id: q for q in survey_.get_questions()}
    for s_data in data['students']:
        student = students[s_data['id']]
        for a_data in s_data['answers']:
            question = questions[a_data['question_id']]
            answer = survey.Answer(a_data['answer'])
            student.set_answer(question, answer)