Beispiel #1
0
def test_str5_color():
    """
    Test the str5 functions for cmyk and hsv.
    """
    cornell.assert_equals(
        '(98.45, 25.36, 72.80, 1.000)',
        a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
Beispiel #2
0
def test_hist_init():
    """
    Tests the __init__ method and getters in ImageHistory
    """
    print('Testing history initializer')
    import a6image
    import a6history
    p = pixels.Pixels(6)

    p[0] = (255, 0, 0)
    p[1] = (0, 255, 0)
    p[2] = (0, 0, 255)
    p[3] = (0, 255, 255)
    p[4] = (255, 0, 255)
    p[5] = (255, 255, 0)

    image = a6image.Image(p, 2)
    hist = a6history.ImageHistory(image)
    cornell.assert_equals(id(image), id(hist.getOriginal()))
    cornell.assert_equals(type(image), type(hist.getCurrent()))
    cornell.assert_not_equals(id(image), id(hist.getCurrent()))

    current = hist.getCurrent()
    cornell.assert_not_equals(id(p), id(current.getPixels()))
    for pos in range(current.getLength()):
        cornell.assert_equals(p[pos], current.getPixels()[pos])

    cornell.assert_true(hasattr(hist, '_history'))
    cornell.assert_equals(list, type(hist._history))
    cornell.assert_equals(1, len(hist._history))
Beispiel #3
0
def test_into():
    """
    Tests for function into
    """
    cornell.assert_equals(0, lab08.into(5, 3))
    cornell.assert_equals(1, lab08.into(6, 3))
    cornell.assert_equals(2, lab08.into(9, 3))
    cornell.assert_equals(2, lab08.into(18, 3))
    cornell.assert_equals(4, lab08.into(3 * 3 * 3 * 3 * 7, 3))
Beispiel #4
0
def test_number2():
    """
    Tests for function number2
    """
    cornell.assert_equals(0, lab08.number2(0))
    cornell.assert_equals(1, lab08.number2(2))
    cornell.assert_equals(2, lab08.number2(232))
    cornell.assert_equals(0, lab08.number2(333))
    cornell.assert_equals(3, lab08.number2(234252))
Beispiel #5
0
def test_number_not():
    """
    Tests for function number_not
    """
    mylist = [5, 3, 3455, 74, 74, 74, 3]
    cornell.assert_equals(0, lab08.number_not([], 4))
    cornell.assert_equals(0, lab08.number_not([4], 4))
    cornell.assert_equals(4, lab08.number_not(mylist, 74))
    cornell.assert_equals(5, lab08.number_not(mylist, 3))
    cornell.assert_equals(7, lab08.number_not(mylist, 4))
Beispiel #6
0
def test_remove_first():
    """
    Tests for function remove_first
    """
    cornell.assert_equals([], lab08.remove_first([], 3))
    cornell.assert_equals([], lab08.remove_first([3], 3))
    cornell.assert_equals([3], lab08.remove_first([3], 4))
    cornell.assert_equals([3, 4, 4, 5], lab08.remove_first([3, 4, 4, 4, 5], 4))
    cornell.assert_equals([3, 5, 4, 4, 4],
                          lab08.remove_first([3, 4, 5, 4, 4, 4], 4))
Beispiel #7
0
def test_numberof():
    """
    Tests for function numberof
    """
    mylist = [5, 3, 3455, 74, 74, 74, 3]
    cornell.assert_equals(0, lab08.numberof([], 4))
    cornell.assert_equals(1, lab08.numberof([4], 4))
    cornell.assert_equals(3, lab08.numberof(mylist, 74))
    cornell.assert_equals(2, lab08.numberof(mylist, 3))
    cornell.assert_equals(0, lab08.numberof(mylist, 4))
def test_num_runs():
    """
    Tests the function num_space_runs
    """
    print('  Testing num_space_runs')
    cornell.assert_equals(4, lab12.num_space_runs('  a  f   g    '))
    cornell.assert_equals(2, lab12.num_space_runs('a  f   g'))
    cornell.assert_equals(3, lab12.num_space_runs('  a  bc   d'))
    cornell.assert_equals(1, lab12.num_space_runs('  a'))
    cornell.assert_equals(0, lab12.num_space_runs('ab'))
    print('  num_space_runs looks okay')
Beispiel #9
0
def test_numberof():
    """
    Tests the function numberof
    """
    print('  Testing numberof')
    mylist = [5, 3, 3455, 74, 74, 74, 3]
    cornell.assert_equals(3, lab11.numberof(mylist, 74))
    cornell.assert_equals(2, lab11.numberof(mylist, 3))
    cornell.assert_equals(0, lab11.numberof(mylist, 4))
    cornell.assert_equals(1, lab11.numberof([4], 4))
    cornell.assert_equals(0, lab11.numberof([], 4))
    print('  numberof looks okay')
def test_dealerScore():
    """
    Tests the dealerScore method for Blackjack objects
    """
    deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)]
    game = lab09.Blackjack(deck)

    cornell.assert_equals(9, game.dealerScore())
    game.dealerHand = [card.Card(2, 2), card.Card(3, 1)]
    game.playerHand = [card.Card(1, 13), card.Card(0, 3)]
    cornell.assert_equals(13, game.dealerScore())

    print('The dealerScore tests passed')
Beispiel #11
0
def test_str5_color():
    """
    Test the str5 functions for cmyk and hsv.
    """
    cornell.assert_equals('(98.45, 25.36, 72.80, 1.000)',
                          a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
    cornell.assert_equals('(1.000, 0.000, 100.0, 100.0)',
                          a3.str5_cmyk(cornell.CMYK(1, 0.0, 99.999999, 100)))
    cornell.assert_equals('(0.000, 0.000, 0.000)',
                          a3.str5_hsv(cornell.HSV(0, 0.0, 0)))
    cornell.assert_equals('(360.0, 1.000, 1.000)',
                          a3.str5_hsv(cornell.HSV(359.999, 1.0, 1)))
    cornell.assert_equals('(279.5, 1.000, 0.735)',
                          a3.str5_hsv(cornell.HSV(279.547, 1, 0.7346983)))
Beispiel #12
0
def test_num_digits():
    """
    Tests for function num_digits
    """
    cornell.assert_equals(1, lab08.num_digits(0))
    cornell.assert_equals(1, lab08.num_digits(3))
    cornell.assert_equals(2, lab08.num_digits(34))
    cornell.assert_equals(4, lab08.num_digits(1356))
Beispiel #13
0
def test_sum_digits():
    """
    Tests for function sum_digits
    """
    cornell.assert_equals(0, lab08.sum_digits(0))
    cornell.assert_equals(3, lab08.sum_digits(3))
    cornell.assert_equals(7, lab08.sum_digits(34))
    cornell.assert_equals(12, lab08.sum_digits(345))
Beispiel #14
0
def test_replace_table():
    """
    Test the function replace_table
    """
    cornell.assert_equals([[2, 0, 2], [0, 2, 0]],
                          replace_table([[1, 0, 1], [0, 1, 0]], 1, 2))
    cornell.assert_equals([[1, 3, 1], [3, 1, 3]],
                          replace_table([[1, 0, 1], [0, 1, 0]], 0, 3))
    cornell.assert_equals([[1, 0, 1], [0, 1, 0]],
                          replace_table([[1, 0, 1], [0, 1, 0]], 4, 5))
    cornell.assert_equals([[1, 2, 3], [4, 5, 6], [7, 8, 10]],
                          replace_table([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 9,
                                        10))
    cornell.assert_equals([[-1, 0, 4], [0, 3, 2], [4, 4, 0]],
                          replace_table([[-1, 0, 1], [0, 3, 2], [1, 1, 0]], 1,
                                        4))
def test_split():
    """
    Tests the function split
    """
    print('  Testing split')
    cornell.assert_equals(['a', 'b', 'c', 'd'], lab12.split('a b c d '))
    cornell.assert_equals(['ab', 'cd'], lab12.split('ab cd '))
    cornell.assert_equals(['ab', 'c', 'de'], lab12.split('ab c de '))
    cornell.assert_equals(['a'], lab12.split('a '))
    print('  split looks okay')
def test_score():
    """
    Tests the _score method (which is hidden, but we access anyway)
    """
    # need a dummy game object to call its _score function (and test it)
    deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)]
    game = lab09.Blackjack(deck)

    cornell.assert_equals(13, game._score([card.Card(2, 2), card.Card(3, 1)]))
    cornell.assert_equals(13, game._score([card.Card(1, 13), card.Card(0, 3)]))
    cornell.assert_equals(22, game._score([card.Card(1, 1), card.Card(0, 1)]))
    cornell.assert_equals(
        9, game._score([card.Card(1, 2),
                        card.Card(0, 3),
                        card.Card(3, 4)]))
    cornell.assert_equals(0, game._score([]))

    print('The _score tests passed')
Beispiel #17
0
def testD():
    "test procedure for part D"

    # Test is_currency
    cornell.assert_equals(True, a1.iscurrency('USD'))
    cornell.assert_equals(True, a1.iscurrency('SAR'))
    cornell.assert_equals(False, a1.iscurrency('   '))
    cornell.assert_equals(False, a1.iscurrency('sar'))

    #Test Exchange
    cornell.assert_floats_equal(112.518, a1.exchange('USD', 'SAR', 30))
Beispiel #18
0
def test_complement():
    """
    Test function complement
    """
    cornell.assert_equals(cornell.RGB(255 - 250, 255 - 0, 255 - 71),
                          a3.complement_rgb(cornell.RGB(250, 0, 71)))
    cornell.assert_equals(cornell.RGB(255 - 0, 255 - 0, 255 - 0),
                          a3.complement_rgb(cornell.RGB(0, 0, 0)))
    cornell.assert_equals(cornell.RGB(255 - 255, 255 - 255, 255 - 255),
                          a3.complement_rgb(cornell.RGB(255, 255, 255)))
    cornell.assert_equals(cornell.RGB(255 - 173, 255 - 69, 255 - 4),
                          a3.complement_rgb(cornell.RGB(173, 69, 4)))
Beispiel #19
0
def test_replace_copy():
    """
    Tests the function replace_copy
    """
    print('  Testing replace_copy')
    cornell.assert_equals([4], lab11.replace_copy([5], 5, 4))
    cornell.assert_equals([], lab11.replace_copy([], 1, 2))
    mylist = [5, 3, 3455, 74, 74, 74, 3]
    cornell.assert_equals([5, 20, 3455, 74, 74, 74, 20],
                          lab11.replace_copy(mylist, 3, 20))
    cornell.assert_equals([5, 3, 3455, 74, 74, 74, 3],
                          lab11.replace_copy(mylist, 1, 3))
    print('  replace_copy looks okay')
def test_uniques():
    """
    Test procedure for function uniques
    """
    print('Testing function uniques')
    thelist = [5, 9, 5, 7]
    cornell.assert_equals(3, lab07.uniques(thelist))

    thelist = [5, 5, 1, 'a', 5, 'a']
    cornell.assert_equals(3, lab07.uniques(thelist))

    thelist = [1, 2, 3, 4, 5]
    cornell.assert_equals(5, lab07.uniques(thelist))

    thelist = []
    cornell.assert_equals(0, lab07.uniques(thelist))

    # Make sure the function does not modify the original
    thelist = [5, 9, 5, 7]
    result = lab07.uniques(thelist)
    cornell.assert_equals([5, 9, 5, 7], thelist)
Beispiel #21
0
def test_image_str():
    """
    Tests the __str__ method in class Image
    """
    print('Testing image __str__ method')
    import a6image
    p = pixels.Pixels(6)

    p[0] = (255, 64, 0)
    p[1] = (0, 255, 64)
    p[2] = (64, 0, 255)
    p[3] = (64, 255, 128)
    p[4] = (128, 64, 255)
    p[5] = (255, 128, 64)

    str0 = '[[' + str(p[0]) + ', ' + str(p[1]) + '],  [' + str(
        p[2]) + ', ' + str(p[3]) + ']]'
    str1 = '[[' + str(p[0]) + ', ' + str(p[1]) + '],  [' + str(
        p[2]) + ', ' + str(p[3]) + '],  [' + str(p[4]) + ', ' + str(
            p[5]) + ']]'
    str2 = '[[' + str(p[0]) + ', ' + str(p[1]) + ', ' + str(
        p[2]) + '],  [' + str(p[3]) + ', ' + str(p[4]) + ', ' + str(
            p[5]) + ']]'
    str3 = '[[' + str(p[0]) + ', ' + str(p[1]) + ', ' + str(p[2]) + ', ' + str(
        p[3]) + ', ' + str(p[4]) + ', ' + str(p[5]) + ']]'
    str4 = '[[' + str(p[0]) + '],  [' + str(p[1]) + '],  [' + str(
        p[2]) + '],  [' + str(p[3]) + '],  [' + str(p[4]) + '],  [' + str(
            p[5]) + ']]'

    image = a6image.Image(p[:4], 2)
    cornell.assert_equals(str0, str(image))

    image = a6image.Image(p, 2)
    cornell.assert_equals(str1, str(image))
    image.setWidth(3)
    cornell.assert_equals(str2, str(image))
    image.setWidth(6)
    cornell.assert_equals(str3, str(image))
    image.setWidth(1)
    cornell.assert_equals(str4, str(image))
Beispiel #22
0
def test_sum_list():
    """
    Tests for function sum_list
    """
    cornell.assert_equals(0, lab08.sum_list([]))
    cornell.assert_equals(34, lab08.sum_list([34]))
    cornell.assert_equals(46, lab08.sum_list([7, 34, 1, 2, 2]))
Beispiel #23
0
def test_sum_to():
    """
    Tests for function sum_to
    """
    cornell.assert_equals(1, lab08.sum_to(1))
    cornell.assert_equals(6, lab08.sum_to(3))
    cornell.assert_equals(15, lab08.sum_to(5))
def test_str():
    """
    Tests the __str__ function for Blackjack objects
    """
    deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)]
    game = lab09.Blackjack(deck)
    cornell.assert_equals('player: 20; dealer: 9', str(game))

    game.playerHand = []
    cornell.assert_equals('player: 0; dealer: 9', str(game))
    game.dealerHand.append(card.Card(2, 1))
    cornell.assert_equals('player: 0; dealer: 20', str(game))
    game.dealerHand.append(card.Card(2, 5))
    cornell.assert_equals('player: 0; dealer: 25', str(game))

    print('The __str__ tests passed')
Beispiel #25
0
def test_minpos2():
    """
    Tests the function minpos2
    """
    print('  Testing minpos2')
    a = [0, 3, 4, 2, 5, 1]
    cornell.assert_equals(0, lab13.minpos1(a, 0, 5))
    cornell.assert_equals(5, lab13.minpos1(a, 1, 5))
    cornell.assert_equals(3, lab13.minpos1(a, 1, 4))
    print('  minpos2 looks okay')
Beispiel #26
0
def testC():
    """Test procedure for Part C"""
    result = a1.currency_response('USD', 'EUR', 2.5)
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "2.5 United States Dollars", "rhs" : "2.0952375 Euros", "error" : "" }',
        result)
    result = a1.currency_response('p', 'EUR', 2.5)
    cornell.assert_equals(
        '{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Source currency code is invalid." }',
        result)
    result = a1.currency_response('USD', 'y', 2.5)
    cornell.assert_equals(
        '{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Exchange currency code is invalid." }',
        result)
    result = a1.currency_response('qwerty', 'asdfgh', 2)
    cornell.assert_equals(
        '{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Source currency code is invalid." }',
        result)
Beispiel #27
0
def testC():
    "test procedure for part C"

    #Test for Currency Response
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "30000 United States Dollars", "rhs" : "112518 Saudi Riyals", "error" : "" }',
        a1.currency_response('USD', 'SAR', 30000))
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "2 United States Dollars", "rhs" : "1.67619 Euros", "error" : "" }',
        a1.currency_response('USD', 'EUR', 2))
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "0 Dominican Pesos", "rhs" : "0 Saudi Riyals", "error" : "" }',
        a1.currency_response('DOP', 'SAR', 0.0))
def test_asserts():
    """
    This is a simple test procedure to help you understand how assert works
    """
    print('Testing the cornell asserts')
    cornell.assert_equals('b c', 'ab cd'[1:4])
    #cornell.assert_equals('b c', 'ab cd'[1:3])     # UNCOMMENT ONLY WHEN DIRECTED
    
    cornell.assert_true(3 < 4)
    cornell.assert_equals(3, 1+2)
    
    cornell.assert_equals(3.0, 1.0+2.0)
    cornell.assert_floats_equal(6.3, 3.1+3.2)
Beispiel #29
0
def test_str5_color():
    """
    Test the str5 functions for cmyk and hsv.
    """
    cornell.assert_equals(
        '(98.45, 25.36, 72.80, 1.000)',
        a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
    #cornell.assert_equals('(98.45, 25.36, 72.80, 1.000)',
    #                      a3.str5_cmyk(cornell.CMYK(98.448, 25.362, 72.8, 1.0)))
    cornell.assert_equals('(0.000, 0.314, 1.000)',
                          a3.str5_hsv(cornell.HSV(0.0, 0.313725490196, 1.0)))
    cornell.assert_equals('(0.500, 0.666, 1.000)',
                          a3.str5_hsv(cornell.HSV(0.5, 0.666352839474, 1)))
Beispiel #30
0
def test_replace():
    """
    Tests the function replace
    """
    print('  Testing replace')
    mylist = [5]
    lab11.replace(mylist, 5, 4)
    cornell.assert_equals([4], mylist)

    mylist = []
    lab11.replace(mylist, 1, 2)
    cornell.assert_equals([], mylist)

    mylist = [5, 3, 3455, 74, 74, 74, 3]
    lab11.replace(mylist, 3, 20)
    cornell.assert_equals([5, 20, 3455, 74, 74, 74, 20], mylist)

    lab11.replace(mylist, 1, 3)
    cornell.assert_equals([5, 20, 3455, 74, 74, 74, 20], mylist)
    print('  replace looks okay')