Beispiel #1
0
 def test_shift_subtract_index(self):
     interrupter = 0
     ct = np.array([1, 2, 3, 4, 5, 0, 6, 7, 8, 9])
     ct = enc.apply_shift(ct, interrupter, shift_id=6)
     np.testing.assert_array_equal(ct, np.array([1, 3, 5, 7, 9, 0, 11, 13, 15, 17]))
def test_apply_shift():
    points = 0  # variable to store the accumulated grade.

    # Prerequisite-1: Testing if file is exist and imported.
    try:
        import encryption
        comment("Prerequisite-1: The file was successfully loaded... ok")
    except:
        comment("Prerequisite-1: The file couldn't ne loaded. ERROR!")
        grade(points)
        exit()

    # Prerequisite-2: Testing if function buildCoder() is defined.
    try:
        encryption.apply_shift
        comment("Prerequisite-2: The function apply_shift() is defined... ok")
    except:
        comment(
            "Prerequisite-2: The function apply_shift() is NOT defined.  ERROR"
        )
        grade(points)
        exit()

    # Test-1: Testing the function apply_coder().
    output = encryption.apply_shift('Hello, world!', 15)
    expected_output = 'Wtaad, ldgas!'
    if expected_output == output:
        comment(
            "Test-1: The Function returned the correct value... ok\n +20 points"
        )
        points += 20
    else:
        comment(
            "Test-1: The function returned INCORRECT value. ERROR!\n\nFunction returned = "
            + str(output) + "\nExpected output = " + str(expected_output) +
            "\n")
        exit()

    # Test-2: Testing the function apply_coder().
    output = encryption.apply_shift('The quiz is... hard!', 1)
    expected_output = 'Uif rvja jt... ibse!'
    if expected_output == output:
        comment(
            "Test-2: The Function returned the correct value... ok\n +20 points"
        )
        points += 20
    else:
        comment(
            "Test-2: The function returned INCORRECT value. ERROR!\nFunction returned = "
            + str(output) + "\nExpected output = " + str(expected_output))
        exit()

    # Test-3: Testing the function apply_coder().
    output = encryption.apply_shift('12 jackdaws quizzed my sphinx!?', 10)
    expected_output = '12 tkmunkgc aesjjon wi czrsxh!?'
    if expected_output == output:
        comment(
            "Test-3: The Function returned the correct value... ok\n +20 points"
        )
        points += 20
    else:
        comment(
            "Test-3: The function returned INCORRECT value. ERROR!\nFunction returned = "
            + str(output) + "\nExpected output = " + str(expected_output))
        exit()

    # Test-4: Testing the function apply_coder().
    output = encryption.apply_shift('rlghu', 0)
    expected_output = 'rlghu'
    if expected_output == output:
        comment(
            "Test-4: The Function returned the correct value... ok\n +20 points"
        )
        points += 20
    else:
        comment(
            "Test-4: The function returned INCORRECT value. ERROR!\nFunction returned = "
            + str(output) + "\nExpected output = " + str(expected_output))
        exit()

    # Test-5: Testing the function apply_coder().
    output = encryption.apply_shift('amrntqjypwhxgd', 6)
    expected_output = 'gsxtzwpevcndmj'
    if expected_output == output:
        comment(
            "Test-5: The Function returned the correct value... ok\n +20 points"
        )
        points += 20
    else:
        comment(
            "Test-5: The function returned INCORRECT value. ERROR!\nFunction returned = "
            + str(output) + "\nExpected output = " + str(expected_output))
        exit()

    # printing the total grade
    print('----------------------------')
    grade(points)
Beispiel #3
0
 def test_shift_add_index(self):
     interrupter = 0
     ct = np.array([1, 2, 3, 4, 5, 0, 6, 7, 8, 9])
     ct = enc.apply_shift(ct, interrupter, shift_id=5)
     np.testing.assert_array_equal(ct, np.array([1, 1, 1, 1, 1, 0, 1, 1, 1, 1]))
Beispiel #4
0
 def test_shift_subtract_prime(self):
     interrupter = 0
     ct = np.array([1, 2, 3, 4, 5, 0, 6, 7, 8, 9])
     ct = enc.apply_shift(ct, interrupter, shift_id=4)
     np.testing.assert_array_equal(ct, np.array([3, 5, 8, 11, 16, 0, 19, 24, 27, 3]))
Beispiel #5
0
 def test_shift_add_prime(self):
     interrupter = 0
     ct = np.array([1, 2, 3, 4, 5, 0, 6, 7, 8, 9])
     ct = enc.apply_shift(ct, interrupter, shift_id=3)
     np.testing.assert_array_equal(ct, np.array([28, 28, 27, 26, 23, 0, 22, 19, 18, 15]))
Beispiel #6
0
 def test_shift_subtract_totient(self):
     interrupter = 0
     ct = np.array([1, 2, 3, 4, 5, 0, 6, 7, 8, 9])
     ct = enc.apply_shift(ct, interrupter, shift_id=2)
     np.testing.assert_array_equal(ct, np.array([2, 4, 7, 10, 15, 0, 18, 23, 26, 2]))
Beispiel #7
0
 def test_shift_add_totient(self):
     interrupter = 0
     ct = np.array([1, 2, 3, 4, 5, 0, 6, 7, 8, 9])
     ct = enc.apply_shift(ct, interrupter, shift_id=1)
     np.testing.assert_array_equal(ct, np.array([0, 0, 28, 27, 24, 0, 23, 20, 19, 16]))