Beispiel #1
0
def test_cannot_create_course_with_duplciate_name():
    alice = create_Teacher('Alice', 1)

    math_by_alice = create_Course('Math', 1, alice)

    bob = create_Teacher('Bob', 2)

    with must_catch_ValueError(
            'Attempt to create course with duplicate name {!r} (already exists: {})'.format(
                'Math',
                math_by_alice
            ),
    ):
        math_by_bob = create_Course('Math', 2, bob)
Beispiel #2
0
def test_can_create_unique_choices():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    math_simple = create_Quiz(math, 'Simple')

    what_is_1_plus_1 = create_Question(math_simple, 'What is 1+1?')

    choice_1_1_1A = create_Choice(what_is_1_plus_1, False, 'One')
    choice_1_1_1B = create_Choice(what_is_1_plus_1, True, 'Two')
    choice_1_1_1C = create_Choice(what_is_1_plus_1, False, 'Three')

    assert choice_1_1_1A.letter != choice_1_1_1B.letter
    assert choice_1_1_1A.letter != choice_1_1_1C.letter
    assert choice_1_1_1B.letter != choice_1_1_1C.letter

    what_is_2_minus_2 = create_Question(math_simple, 'What is 2-2?')

    choice_1_1_2A = create_Choice(what_is_2_minus_2, True, 'Zero')
    choice_1_1_2B = create_Choice(what_is_2_minus_2, False, 'One')
    choice_1_1_2C = create_Choice(what_is_2_minus_2, False, 'Two')

    print
    print('              alice: {}'.format(alice))
    print('               math: {}'.format(math))
    print('        math_simple: {}'.format(math_simple))
    print('   what_is_1_plus_1: {}'.format(what_is_1_plus_1))
    print('      choice_1_1_1A: {}'.format(choice_1_1_1A))
    print('      choice_1_1_1B: {}'.format(choice_1_1_1B))
    print('      choice_1_1_1C: {}'.format(choice_1_1_1C))
    print('  what_is_2_minus_2: {}'.format(what_is_2_minus_2))
    print('      choice_1_1_2A: {}'.format(choice_1_1_2A))
    print('      choice_1_1_2B: {}'.format(choice_1_1_2B))
    print('      choice_1_1_2C: {}'.format(choice_1_1_2C))
Beispiel #3
0
def test_cannot_call_next_quiz_number_twice():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    quiz_number_1 = math.next_quiz_number()

    with must_catch_AssertionError():
        quiz_number_2 = math.next_quiz_number()
def test_can_join_course():
    alice = create_Teacher('Alice', 1)

    math    = create_Course('Math',    1, alice)
    english = create_Course('English', 2, alice)

    bob     = create_Student('Bob', 2)
    charlie = create_Student('Charlie', 3)

    bob.join_course('Math')
    bob.join_course('English')
    charlie.join_course('English')

    math.debug_dump()
    english.debug_dump()

    bob.debug_dump()
    charlie.debug_dump()
def test_cannot_join_same_course_twice():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    bob = create_Student('Bob', 2)

    bob.join_course('Math')

    with must_catch_ValueError('{} has already joined course {}; cannot join a second time'.format(bob, math)):
        bob.join_course('Math')
Beispiel #6
0
def test_can_create_unique_quizzes():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    addition    = create_Quiz(math, 'Addition')
    subtraction = create_Quiz(math, 'Subtraction')
    math_final  = create_Quiz(math, 'math_final')

    assert addition.number     != subtraction.number
    assert addition.number    != math_final.number
    assert subtraction.number != math_final.number

    print
    print('        alice: {}'.format(alice))
    print('         math: {}'.format(math))
    print('     addition: {}'.format(addition))
    print('  subtraction: {}'.format(subtraction))
    print('   math_final: {}'.format(math_final))
def test_can_create_unique_questions():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    math_simple = create_Quiz(math, 'Simple')

    what_is_1_plus_1  = create_Question(math_simple, 'What is 1+1?')
    what_is_2_minus_2 = create_Question(math_simple, 'What is 2-2?')
    what_is_3_times_3 = create_Question(math_simple, 'What is 3*3?')

    assert what_is_1_plus_1.number  != what_is_2_minus_2.number
    assert what_is_1_plus_1.number  != what_is_3_times_3.number
    assert what_is_2_minus_2.number != what_is_3_times_3.number

    print
    print('              alice: {}'.format(alice))
    print('               math: {}'.format(math))
    print('        math_simple: {}'.format(math_simple))
    print('   what_is_1_plus_1: {}'.format(what_is_1_plus_1))
    print('  what_is_2_minus_2: {}'.format(what_is_2_minus_2))
    print('  what_is_3_times_3: {}'.format(what_is_3_times_3))
def test_debug_dump():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    math_simple = create_Quiz(math, 'Simple')
    math_final  = create_Quiz(math, 'math_final')

    what_is_1_plus_1 = create_Question(math_simple, 'What is 1+1?')

    choice_1_1_1A = create_Choice(what_is_1_plus_1, False, 'One')
    choice_1_1_1B = create_Choice(what_is_1_plus_1, True,  'Two')
    choice_1_1_1C = create_Choice(what_is_1_plus_1, False, 'Three')

    what_is_2_minus_2 = create_Question(math_simple, 'What is 2-2?')

    choice_1_1_2A = create_Choice(what_is_2_minus_2, True,  'Zero')
    choice_1_1_2B = create_Choice(what_is_2_minus_2, False, 'One')
    choice_1_1_2C = create_Choice(what_is_2_minus_2, False, 'Two')

    what_is_3_times_3 = create_Question(math_simple, 'What is 3*3?')

    choice_1_1_3A = create_Choice(what_is_3_times_3, False, 'Zero')
    choice_1_1_3B = create_Choice(what_is_3_times_3, False, 'Three')
    choice_1_1_3C = create_Choice(what_is_3_times_3, False, 'Six')
    choice_1_1_3D = create_Choice(what_is_3_times_3, True,  'Nine')

    print
    print('        alice: {}'.format(alice))
    print('         math: {}'.format(math))
    print('  math_simple: {}'.format(math_simple))

    alice           .debug_dump()
    math            .debug_dump()
    math_simple     .debug_dump()
    what_is_1_plus_1.debug_dump()
def test_grade():
    alice = create_Teacher('Alice', 1)

    math = create_Course('Math', 1, alice)

    bob = create_Student('Bob', 2)
    charlie = create_Student('Charlie', 3)
    david = create_Student('David', 4)

    bob.join_course('Math')
    charlie.join_course('Math')
    david.join_course('Math')

    #
    #   Math quiz: Simple
    #
    math_simple = create_Quiz(math, 'Simple')
    math_final = create_Quiz(math, 'math_final')

    what_is_1_plus_1 = create_Question(math_simple, 'What is 1+1?')

    choice_1_1_1A = create_Choice(what_is_1_plus_1, False, 'One')
    choice_1_1_1B = create_Choice(what_is_1_plus_1, True, 'Two')
    choice_1_1_1C = create_Choice(what_is_1_plus_1, False, 'Three')

    what_is_2_minus_2 = create_Question(math_simple, 'What is 2-2?')

    choice_1_1_2A = create_Choice(what_is_2_minus_2, True, 'Zero')
    choice_1_1_2B = create_Choice(what_is_2_minus_2, False, 'One')
    choice_1_1_2C = create_Choice(what_is_2_minus_2, False, 'Two')

    what_is_3_multiplied_by_3 = create_Question(math_simple,
                                                'What is 3 multiplied by 3?')

    choice_1_1_3A = create_Choice(what_is_3_multiplied_by_3, False, 'Zero')
    choice_1_1_3B = create_Choice(what_is_3_multiplied_by_3, False, 'Three')
    choice_1_1_3C = create_Choice(what_is_3_multiplied_by_3, False, 'Six')
    choice_1_1_3D = create_Choice(what_is_3_multiplied_by_3, True, 'Nine')

    what_is_4_modulus_4 = create_Question(math_simple, 'What is 4 modulus 4?')

    choice_1_1_4A = create_Choice(what_is_4_modulus_4, True, 'Zero')
    choice_1_1_4B = create_Choice(what_is_4_modulus_4, False, 'One')

    math_simple.give_quiz_to_all_students()

    #
    #   Test 1A:
    #       Answer one exactly question
    #
    true_fact__1_plus_1__is__2 = create_true_fact('What is 1+1?', 'Two')

    bob.teach(true_fact__1_plus_1__is__2)
    bob.answer_questions()

    assert len(bob.questions) == 1

    #
    #   Test 1B:
    #       Answer the other two questions (in opposite order)
    #
    true_fact__2_minus_2__is__0 = create_true_fact('What is 2-2?', 'Zero')

    false_fact__3_multiplied_by_3__is__6 = create_false_fact(
        'What is 3 multiplied by 3?', 'Six')
    true_fact__3_multiplied_by_3__is__9 = create_false_fact(
        'What is 3 multiplied by 3?', 'Nine')

    bob.teach(false_fact__3_multiplied_by_3__is__6)
    bob.teach(true_fact__2_minus_2__is__0)

    bob.answer_questions()

    assert len(bob.questions) == 3

    #
    #   For this quiz (with 4 questions):
    #
    #       Quiz [0]: <Quiz 'Math' 'Simple' #1.1>
    #           Question [0]: <Question 'Math' 'Simple' #1.1.1 'What is 1+1?'>
    #           Question [1]: <Question 'Math' 'Simple' #1.1.2 'What is 2-2?'>
    #           Question [2]: <Question 'Math' 'Simple' #1.1.3 'What is 3 multiplied by 3?'>
    #           Question [3]: <Question 'Math' 'Simple' #1.1.4 'What is 4 modulus 4?'>
    #
    #   The answers given by Bob (3 answers given; only 2 correct):
    #
    #       Question [0]: <Question 'Math' 'Simple' #1.1.1 'What is 1+1?'>
    #           <Choice 'Math' 'Simple' #1.1.1B correct 'Two'>
    #       Question [1]: <Question 'Math' 'Simple' #1.1.2 'What is 2-2?'>
    #           <Choice 'Math' 'Simple' #1.1.2A correct 'Zero'>
    #       Question [2]: <Question 'Math' 'Simple' #1.1.3 'What is 3 multiplied by 3?'>
    #           <Choice 'Math' 'Simple' #1.1.3C incorrect 'Six'>
    #
    #   Thus Bob scores 50% on the first quiz in math class.
    #
    assert bob.grade_quiz(math_simple) == 50

    #
    #   Math quiz: Final
    #
    math_final__what_is_4_modulus_4 = create_Question(math_final,
                                                      'What is 4 modulus 4?')

    math_final__choice_1_2_1A = create_Choice(math_final__what_is_4_modulus_4,
                                              True, 'Zero')
    math_final__choice_1_2_1B = create_Choice(math_final__what_is_4_modulus_4,
                                              False, 'One')

    math_final__what_is_5_to_the_5th_power = create_Question(
        math_final, 'What is 5 to the 5th power?')
    math_final__choice_1_2_2A = create_Choice(
        math_final__what_is_5_to_the_5th_power, False, 'Five')
    math_final__choice_1_2_2B = create_Choice(
        math_final__what_is_5_to_the_5th_power, False, '25')
    math_final__choice_1_2_2C = create_Choice(
        math_final__what_is_5_to_the_5th_power, False, '125')
    math_final__choice_1_2_2D = create_Choice(
        math_final__what_is_5_to_the_5th_power, False, '625')
    math_final__choice_1_2_2E = create_Choice(
        math_final__what_is_5_to_the_5th_power, True, '3125')
    math_final__choice_1_2_2F = create_Choice(
        math_final__what_is_5_to_the_5th_power, False, '15625')

    math_final.give_quiz_to_all_students()

    true_fact__4_modules_4__is__0 = create_true_fact('What is 4 modulus 4?',
                                                     'Zero')
    true_fact__5_to_the_5th_power__is__0 = create_true_fact(
        'What is 5 to the 5th power?', '3125')

    bob.teach(true_fact__4_modules_4__is__0)
    bob.teach(true_fact__5_to_the_5th_power__is__0)

    #
    #   NOTE:
    #       Bob now knows the true fact "What is 4 modulus 4?" is "Zero".
    #
    #       Bob will *THUS* answer this question on *BOTH* the Simple & the Final!!
    #
    bob.answer_questions()

    assert bob.grade_quiz(math_simple) == 75  #   Improved to 75%!
    assert bob.grade_quiz(math_final) == 100

    assert bob.grade_course(math) == 88  #   87.5 rounded up to 88

    #
    #   Geography
    #
    geography = create_Course('Geography', 2, alice)

    bob.join_course('Geography')
    charlie.join_course('Geography')

    geography_simple = create_Quiz(geography, 'Simple')
    geography_final = create_Quiz(geography, 'Final')

    how_many_states_are_in_the_united_states = create_Question(
        geography_simple,
        'How many states are in the United States?',
    )

    geography_simple__choice_1_2_1A = create_Choice(
        how_many_states_are_in_the_united_states, False, '13')
    geography_simple__choice_1_2_1B = create_Choice(
        how_many_states_are_in_the_united_states, True, '50')
    geography_simple__choice_1_2_1C = create_Choice(
        how_many_states_are_in_the_united_states, False, '51')

    what_is_the_capital_of_new_york = create_Question(
        geography_final, 'What is the capital of New York?')
    geography_final__choice__1_2_1A = create_Choice(
        what_is_the_capital_of_new_york, False, 'Boston')
    geography_final__choice__1_2_1B = create_Choice(
        what_is_the_capital_of_new_york, True, 'New York')

    what_is_the_capital_of_the_united_states = create_Question(
        geography_final,
        'What is the capital of the United States?',
    )

    geography_final__choice__1_2_2A = create_Choice(
        what_is_the_capital_of_the_united_states, False, 'Boston')
    geography_final__choice__1_2_2B = create_Choice(
        what_is_the_capital_of_the_united_states, False, 'New York')

    geography_final__choice__1_2_2C = create_Choice(
        what_is_the_capital_of_the_united_states,
        True,
        'Washington, D.C.',
    )

    what_is_the_capital_of_washington = create_Question(
        geography_final, 'What is the capital of Washington?')
    geography_final__choice__1_2_3A = create_Choice(
        what_is_the_capital_of_washington, False, 'Madison')
    geography_final__choice__1_2_3B = create_Choice(
        what_is_the_capital_of_washington, True, 'Olympia')
    geography_final__choice__1_2_3C = create_Choice(
        what_is_the_capital_of_washington, False, 'Washington, D.C.')

    true_fact__50_states_in_the_united_states = create_true_fact(
        'How many states are in the United States?', '50')
    false_fact__51_states_in_the_united_states = create_false_fact(
        'How many states are in the United States?', '51')

    true_fact__the_capital_of__new_york__is__new_york = create_true_fact(
        'What is the capital of New York?',
        'New York',
    )

    true_fact__the_capital_of_the_united_states_is__Washington_DC = create_true_fact(
        'What is the capital of the United States?',
        'Washington, D.C.',
    )

    true_fact__the_capital_of__washington__is__olympia = create_true_fact(
        'What is the capital of Washington?',
        'Olympia',
    )

    geography_simple.give_quiz_to_all_students()
    geography_final.give_quiz_to_all_students()

    bob.teach(false_fact__51_states_in_the_united_states)
    bob.teach(true_fact__the_capital_of__new_york__is__new_york)
    bob.teach(true_fact__the_capital_of_the_united_states_is__Washington_DC)

    bob.answer_questions()

    assert bob.grade_quiz(geography_simple) == 0
    assert bob.grade_quiz(geography_final) == 67
    assert bob.grade_course(geography) == 34

    #
    #   Eve teaches the jogging, jumping, and swimming classes
    #
    eve = create_Teacher('Eve', 5)

    jogging = create_Course('Jogging', 3, eve)
    jumping = create_Course('Jumping', 4, eve)
    swimming = create_Course('Swimming', 5, eve)

    bob.join_course('Jogging')
    bob.join_course('Jumping')
    bob.join_course('Swimming')

    jumping_empty_quiz = create_Quiz(jumping, 'Empty')

    swiming_easy_quiz = create_Quiz(swimming, 'Easy')

    do_we_use_chlorine_in_our_swimming_pool = create_Question(
        swiming_easy_quiz,
        'Do we use chlorine in our swimming pool?',
    )

    swimming_final__choice_1_5_1A = create_Choice(
        do_we_use_chlorine_in_our_swimming_pool, False, 'No')
    swimming_final__choice_1_5_1B = create_Choice(
        do_we_use_chlorine_in_our_swimming_pool, True, 'Yes')

    swiming_easy_quiz.give_quiz_to_all_students()

    assert bob.grade_course(
        jogging) == 100  #   100 since the jogging class had no quizzes!
    assert bob.grade_course(
        jumping
    ) == 100  #   100 since the jumping class had a quiz with no questions
    assert bob.grade_course(
        swimming) == 0  #   100 since not yet answered the question.

    true_fact__we_use_chlorine_in_our_swimming_pool = create_true_fact(
        'Do we use chlorine in our swimming pool?',
        'Yes',
    )

    bob.teach(true_fact__we_use_chlorine_in_our_swimming_pool)
    bob.answer_questions()

    assert bob.grade_course(
        swimming) == 100  #   100 now that answered the question.

    #
    #   Due to the super easy swimming & jogging class, Bob will now get a great grade for the
    #   semester improving his 88 from his math class to a 96 ...
    #
    #   NOTE:
    #       The specifications did not request a semester grade, but a grade for the semester
    #       by each teachers.
    #
    #       This was more added during testing...
    #
    assert bob.grade_semester_by_teacher(
        alice) == 61  #   Math: 88; Geography: 34.  Averge: 61
    assert bob.grade_semester_by_teacher(eve) == 100

    #
    #   Charlie & David's answers
    #
    #   NOTE:
    #       David is *NOT* taking geography -- but still "knows" the facts about geography.
    #
    #   Both Charlie & David get 100 in Math.
    #   However, since Charlie, *also* took Geography with Alice, and did poorly, his overall grade is down to 59.
    #   David, being lazier, and only taking Math, still gets 100!
    #
    for v in [charlie, david]:
        v.teach(true_fact__1_plus_1__is__2)
        v.teach(true_fact__2_minus_2__is__0)
        v.teach(true_fact__3_multiplied_by_3__is__9)
        v.teach(true_fact__4_modules_4__is__0)
        v.teach(true_fact__5_to_the_5th_power__is__0)

        v.teach(false_fact__51_states_in_the_united_states)
        v.teach(true_fact__the_capital_of__new_york__is__new_york)

        v.answer_questions()

    assert charlie.grade_course(math) == 100
    assert david.grade_course(math) == 100
    assert charlie.grade_course(geography) == 17

    assert charlie.grade_semester_by_teacher(alice) == 59  #   (100 + 17) / 2)
    assert david.grade_semester_by_teacher(
        alice
    ) == 100  #   100.  David *DID* not take & fail Geography like Charlie!

    alice.debug_dump()
    math.debug_dump()
    math_simple.debug_dump()
    what_is_1_plus_1.debug_dump()
    charlie.debug_dump()
Beispiel #10
0
def create_course__and__print(i, name, number, parent):
    course = create_Course(name, number, parent)

    print('      Created: Course [{}]: {}'.format(i, course))
Beispiel #11
0
def implementation(context, teacher_name, course_name):
    teacher = create_Teacher(teacher_name, 2)

    with must_catch_duplicate_course_by_name(find_course(course_name)) as context.caught:
        create_Course(course_name, 2, teacher)
Beispiel #12
0
def implementation(context, teacher_name, course_name):
    teacher = create_Teacher(teacher_name, 1)

    create_Course(course_name, 1, teacher)
Beispiel #13
0
def test_can_remake_alice_and_swimming_without_duplicate_error():
    alice = create_Teacher('Alice', 1)
    swimming = create_Course('Swimming', 1, alice)
Beispiel #14
0
def test_can_create_course_and_student_with_same_number():
    alice = create_Teacher('Alice', 1)
    swimming = create_Course('Swimming', 1, alice)

    assert alice.number == swimming.number
Beispiel #15
0
def create_course_and_print(i, name, number, teacher):
    course = create_Course(name, number, teacher)

    print('...   Created [{}]: {}'.format(i, course))

    return course