Пример #1
0
def test_image_operators():
    """
    Tests the double-underscore methods for 1-d access in class Image.
    """
    print('Testing image operators for 1-dimensional access')
    p = [(0,0,0)]*4
    
    image = a6image.Image(p,2)
    introcs.assert_equals(4,len(image))

    p = [(255,0,0),(0,255,0),(0,0,255),(0,255,255),(255,0,255),(255,255,0)]
    rgb1 = (255,255,255)
    rgb2 = (64,128,192)
    
    image = a6image.Image(p,3)
    introcs.assert_equals(6,len(image))
    for n in range(6):
        introcs.assert_equals(p[n],image[n])
        introcs.assert_equals(id(p[n]),id(image[n]))
    
    image[4] = rgb1
    introcs.assert_equals(rgb1,image[4])
    image[4] = rgb2
    introcs.assert_equals(rgb2,image[4])
    introcs.assert_equals(rgb2,p[4])                # Because image has a reference to p
    
    introcs.assert_error(image.__getitem__,'a', message='__getitem__ does not enforce the precondition on type')
    introcs.assert_error(image.__getitem__,9,   message='__getitem__ does not enforce the precondition on range')
    introcs.assert_error(image.__setitem__,'a',(0,0,255), message='__setitem__ does not enforce the precondition on type')
    introcs.assert_error(image.__setitem__,9,(0,0,255),   message='__setitem__ does not enforce the precondition on range')
    introcs.assert_error(image.__setitem__,9,(0,0,'255'), message='__setitem__ does not enforce the precondition on pixel value')
Пример #2
0
def test_image_init():
    """
    Tests the __init__ method and getters for class Image
    """
    print('Testing image initializer')
    p = [(0,0,0)]*6
    
    image = a6image.Image(p,3)
    # Normally it is bad to test things that are hidden
    # But without this you will not find the error until test_image_operators
    introcs.assert_equals(id(p),id(image._data))
    introcs.assert_not_equals(id(p),id(image.getData()))
    introcs.assert_equals(p,image.getData())
    introcs.assert_equals(3,image.getWidth())
    introcs.assert_equals(2,image.getHeight())

    image = a6image.Image(p,2)
    introcs.assert_equals(id(p),id(image._data))
    introcs.assert_not_equals(id(p),id(image.getData()))
    introcs.assert_equals(p,image.getData())
    introcs.assert_equals(2,image.getWidth())
    introcs.assert_equals(3,image.getHeight())

    image = a6image.Image(p,1)
    introcs.assert_equals(id(p),id(image._data))
    introcs.assert_not_equals(id(p),id(image.getData()))
    introcs.assert_equals(p,image.getData())
    introcs.assert_equals(1,image.getWidth())
    introcs.assert_equals(6,image.getHeight())
    
    # Test enforcement
    introcs.assert_error(a6image.Image,'aaa',3,message='Image does not enforce the precondition on data')
    introcs.assert_error(a6image.Image,p,'a',  message='Image does not enforce the precondition width type')
    introcs.assert_error(a6image.Image,p,5,    message='Image does not enforce the precondition width validity')
Пример #3
0
def test_image_str():
    """
    Tests the __str__ method in class Image
    """
    print('Testing image __str__ method')
    p = [(255, 64, 0), (0, 255, 64), (64, 0, 255), (64, 255, 128),
         (128, 64, 255), (255, 128, 64)]

    str0 = '[[' + str(p[0]) + ', ' + str(p[1]) + '],\n[' + str(
        p[2]) + ', ' + str(p[3]) + ']]'
    str1 = '[[' + str(p[0]) + ', ' + str(p[1]) + '],\n[' + str(
        p[2]) + ', ' + str(p[3]) + '],\n[' + str(p[4]) + ', ' + str(
            p[5]) + ']]'
    str2 = '[[' + str(p[0]) + ', ' + str(p[1]) + ', ' + str(
        p[2]) + '],\n[' + 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]) + '],\n[' + str(p[1]) + '],\n[' + str(
        p[2]) + '],\n[' + str(p[3]) + '],\n[' + str(p[4]) + '],\n[' + str(
            p[5]) + ']]'

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

    image = a6image.Image(p, 2)
    introcs.assert_equals(str1, str(image))
    image.setWidth(3)
    introcs.assert_equals(str2, str(image))
    image.setWidth(6)
    introcs.assert_equals(str3, str(image))
    image.setWidth(1)
    introcs.assert_equals(str4, str(image))
Пример #4
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))
Пример #5
0
    def read_image(self, file):
        """
        Returns an Image object for the give file.
        
        If it cannot read the image (either Image is not defined or the file 
        is not an image file), this method returns None.
        
        Parameter file: An absolute path to an image file
        Precondition: file is a string
        """
        import a6image
        from PIL import Image as CoreImage

        try:
            image = CoreImage.open(file)
            image = image.convert("RGB")
            buffer = list(image.getdata())
            size = image.size[0] * image.size[1]
            width = image.size[0]
        except:
            traceback.print_exc()
            self.error('Could not load the image file')
            buffer = None

        result = None
        if not buffer is None:
            try:
                result = a6image.Image(buffer, width)
            except:
                traceback.print_exc()
                result = None
        return result
Пример #6
0
def load_image(file):
    """
    Returns an Image object for the give file in the tests folder.
    
    If it cannot read the image (either Image is not defined or the file 
    is not an image file), this method returns None.
    
    Parameter file: The image file (without the png suffix)
    Precondition: file is a string
    """
    import os.path
    from PIL import Image as CoreImage
    path = os.path.split(__file__)[0]
    path = os.path.join(path,'tests',file+'.png')
    
    try:
        image = CoreImage.open(path)
        image = image.convert("RGB")
        buffer = list(image.getdata())
        size  = image.size[0]*image.size[1]
        width = image.size[0]
    except:
        traceback.print_exc()
        print('Could not load the file '+path)
        buffer = None
    
    result = None
    if not buffer is None:
        try:
            result = a6image.Image(buffer,width)
        except:
            traceback.print_exc()
            result = None
    return result
Пример #7
0
def test_image_access():
    """
    Tests the methods the two-dimensional get/setPixel methods in class Image
    """
    print('Testing image get/setPixel methods')
    p = [(255,0,0),(0,255,0),(0,0,255),(0,255,255),(255,0,255),(255,255,0)]
    rgb1 = (255,255,255)
    rgb2 = (64,128,192)
    
    image = a6image.Image(p,2)
    for n in range(6):
        introcs.assert_equals(p[n],image.getPixel(n // 2, n % 2))
        introcs.assert_equals(id(p[n]),id(image.getPixel(n // 2, n % 2)))
    
    image.setPixel(2,1,rgb1)
    introcs.assert_equals(rgb1,image.getPixel(2,1))
    
    image.setPixel(2,1,rgb2)
    introcs.assert_equals(rgb2,image.getPixel(2,1))
    
    # Test enforcement
    introcs.assert_error(image.getPixel, 'a', 1, message='getPixel does not enforce the precondition on row type')
    introcs.assert_error(image.getPixel, 8, 1,   message='getPixel does not enforce the precondition on row value')
    introcs.assert_error(image.getPixel, 2, 'a', message='getPixel does not enforce the precondition on col value')
    introcs.assert_error(image.getPixel, 2, 8,   message='getPixel does not enforce the precondition on col value')
    introcs.assert_error(image.setPixel, 'a', 1, (0,0,255), message='setPixel does not enforce the precondition on row type')
    introcs.assert_error(image.setPixel, 8, 1, (0,0,255),   message='setPixel does not enforce the precondition on row value')
    introcs.assert_error(image.setPixel, 2, 'a', (0,0,255), message='setPixel does not enforce the precondition on col value')
    introcs.assert_error(image.setPixel, 2, 8, (0,0,255),   message='setPixel does not enforce the precondition on col value')
    introcs.assert_error(image.setPixel, 2, 1, (0,0,'255'), message='setPixel does not enforce the precondition on pixel value')
Пример #8
0
def test_image_setters():
    """
    Tests the width and height setters for class Image
    """
    print('Testing image setters for width/height')
    p = [(0,0,0)]*6
    
    image = a6image.Image(p,3)
    introcs.assert_equals(3,image.getWidth())
    introcs.assert_equals(2,image.getHeight())
    
    image.setWidth(2)
    introcs.assert_equals(2,image.getWidth())
    introcs.assert_equals(3,image.getHeight())
    
    image.setHeight(1)
    introcs.assert_equals(6,image.getWidth())
    introcs.assert_equals(1,image.getHeight())
    
    image.setWidth(1)
    introcs.assert_equals(1,image.getWidth())
    introcs.assert_equals(6,image.getHeight())
    
    # Test enforcement
    introcs.assert_error(image.setWidth,'a', message='setWidth does not enforce the precondition on width type')
    introcs.assert_error(image.setWidth,5,   message='setWidth does not enforce the precondition on width validity')
    introcs.assert_error(image.setHeight,'a',message='setHeight does not enforce the precondition on height type')
    introcs.assert_error(image.setHeight,5,  message='setHeight does not enforce the precondition on height validity')
Пример #9
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))
Пример #10
0
def test_image_init():
    """
    Tests the __init__ method and getters for class Image
    """
    print('Testing image initializer')
    import a6image
    p = pixels.Pixels(6)

    image = a6image.Image(p, 3)
    cornell.assert_equals(id(p), id(image.getPixels()))
    cornell.assert_equals(6, image.getLength())
    cornell.assert_equals(3, image.getWidth())
    cornell.assert_equals(2, image.getHeight())

    image = a6image.Image(p, 2)
    cornell.assert_equals(id(p), id(image.getPixels()))
    cornell.assert_equals(6, image.getLength())
    cornell.assert_equals(2, image.getWidth())
    cornell.assert_equals(3, image.getHeight())

    image = a6image.Image(p, 1)
    cornell.assert_equals(id(p), id(image.getPixels()))
    cornell.assert_equals(6, image.getLength())
    cornell.assert_equals(1, image.getWidth())
    cornell.assert_equals(6, image.getHeight())

    # Test enforcement
    good = test_assert(a6image.Image, ['aaa', 3],
                       'You are not enforcing the precondition on data')
    good = good and test_assert(
        a6image.Image, [p, 'a'],
        'You are not enforcing the precondition on width type')
    good = good and test_assert(
        a6image.Image, [p, 5],
        'You are not enforcing the precondition on width validity')
    if not good:
        exit()
Пример #11
0
def test_image_other():
    """
    Tests the copy and swapPixel methods in class Image
    """
    print('Testing image extra methods')
    p = [(255, 64, 0),(0, 255, 64),(64, 0, 255),(64, 255, 128),(128, 64, 255),(255, 128, 64)]
    q = p[:]  # Need to copy this
    
    # Test the copy
    image = a6image.Image(p,2)
    copy  = image.copy()
    introcs.assert_equals(len(image),len(copy))
    introcs.assert_equals(image.getWidth(),copy.getWidth())
    introcs.assert_not_equals(id(image), id(copy))
    introcs.assert_not_equals(id(image._data), id(copy._data))
    for pos in range(len(copy)):
        introcs.assert_equals(image[pos],copy[pos])
    
    # Test swap pixels
    image.swapPixels(0,0,2,1)
    introcs.assert_equals(q[5],image.getPixel(0,0))
    introcs.assert_equals(q[0],image.getPixel(2,1))
    image.swapPixels(0,0,2,1)
    introcs.assert_equals(q[0],image.getPixel(0,0))
    introcs.assert_equals(q[5],image.getPixel(2,1))
    image.swapPixels(0,1,2,0)
    introcs.assert_equals(q[4],image.getPixel(0,1))
    introcs.assert_equals(q[1],image.getPixel(2,0))
    image.swapPixels(0,1,2,0)
    introcs.assert_equals(q[1],image.getPixel(0,1))
    introcs.assert_equals(q[4],image.getPixel(2,0))
    image.swapPixels(0,0,0,0)
    introcs.assert_equals(q[0],image.getPixel(0,0))
    
    # Test enforcement
    introcs.assert_error(image.swapPixels, 'a', 1, 0, 0, message='swapPixels does not enforce the precondition on row type')
    introcs.assert_error(image.swapPixels, 8, 1, 0, 0,   message='swapPixels does not enforce the precondition on row value')
    introcs.assert_error(image.swapPixels, 0, 1, 'a', 0, message='swapPixels does not enforce the precondition on row type')
    introcs.assert_error(image.swapPixels, 0, 1, 8, 0,   message='swapPixels does not enforce the precondition on row value')
    introcs.assert_error(image.swapPixels, 0, 'a', 0, 0, message='swapPixels does not enforce the precondition on column type')
    introcs.assert_error(image.swapPixels, 0, 8, 0, 0,   message='swapPixels does not enforce the precondition on column value')
    introcs.assert_error(image.swapPixels, 0, 1, 0, 'a', message='swapPixels does not enforce the precondition on column type')
    introcs.assert_error(image.swapPixels, 0, 1, 0, 8,   message='swapPixels does not enforce the precondition on column value')
Пример #12
0
def test_image_setters():
    """
    Tests the setters for class Image
    """
    print('Testing image setters')
    import a6image
    p = pixels.Pixels(6)

    image = a6image.Image(p, 3)
    cornell.assert_equals(3, image.getWidth())
    cornell.assert_equals(2, image.getHeight())

    image.setWidth(2)
    cornell.assert_equals(2, image.getWidth())
    cornell.assert_equals(3, image.getHeight())

    image.setHeight(1)
    cornell.assert_equals(6, image.getWidth())
    cornell.assert_equals(1, image.getHeight())

    image.setWidth(1)
    cornell.assert_equals(1, image.getWidth())
    cornell.assert_equals(6, image.getHeight())

    # Test enforcement
    good = test_assert(image.setWidth, ['a'],
                       'You are not enforcing the precondition on width type')
    good = good and test_assert(
        image.setWidth, [5],
        'You are not enforcing the precondition on width validity')
    good = good and test_assert(
        image.setHeight, ['a'],
        'You are not enforcing the precondition on height type')
    good = good and test_assert(
        image.setHeight, [5],
        'You are not enforcing the precondition on height validity')
    if not good:
        exit()
Пример #13
0
def test_hist_edit():
    """
    Tests the edit (increment/undo/clear) methods in ImageHistory
    """
    print('Testing history edit methods')
    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)

    bottom = hist.getCurrent()
    bottom.setPixel(0, 0, (64, 128, 192))
    hist.increment()

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

    hist.undo()
    cornell.assert_equals(id(bottom), id(hist.getCurrent()))

    hist.increment()
    hist.increment()
    hist.increment()
    cornell.assert_equals(4, len(hist._history))
    current = hist.getCurrent()
    cornell.assert_equals(bottom.getLength(), current.getLength())
    cornell.assert_equals(bottom.getWidth(), current.getWidth())
    cornell.assert_not_equals(id(bottom), id(current))
    cornell.assert_not_equals(id(bottom.getPixels()), id(current.getPixels()))
    for pos in range(current.getLength()):
        cornell.assert_equals(bottom.getPixels()[pos],
                              current.getPixels()[pos])

    hist.clear()
    cornell.assert_not_equals(id(bottom), id(hist.getCurrent()))
    cornell.assert_equals(1, len(hist._history))

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

    bottom = hist.getCurrent()
    bottom.setPixel(0, 0, (64, 128, 192))
    for step in range(hist.MAX_HISTORY + 1):
        hist.increment()

    cornell.assert_equals(hist.MAX_HISTORY, len(hist._history))
    cornell.assert_not_equals(id(bottom), id(hist._history[0]))
Пример #14
0
def test_image_other():
    """
    Tests the copy and swapPixel methods in class Image
    """
    print('Testing image extras')
    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)
    q = p[:]  # Need to copy this

    # Test the copy
    image = a6image.Image(p, 2)
    copy = image.copy()
    cornell.assert_equals(image.getLength(), copy.getLength())
    cornell.assert_equals(image.getWidth(), copy.getWidth())
    cornell.assert_not_equals(id(image), id(copy))
    cornell.assert_not_equals(id(image.getPixels()), id(copy.getPixels()))
    for pos in range(copy.getLength()):
        cornell.assert_equals(image.getPixels()[pos], copy.getPixels()[pos])

    # Test swap pixels
    image.swapPixels(0, 0, 2, 1)
    cornell.assert_equals(q[5], image.getPixel(0, 0))
    cornell.assert_equals(q[0], image.getPixel(2, 1))
    image.swapPixels(0, 0, 2, 1)
    cornell.assert_equals(q[0], image.getPixel(0, 0))
    cornell.assert_equals(q[5], image.getPixel(2, 1))
    image.swapPixels(0, 1, 2, 0)
    cornell.assert_equals(q[4], image.getPixel(0, 1))
    cornell.assert_equals(q[1], image.getPixel(2, 0))
    image.swapPixels(0, 1, 2, 0)
    cornell.assert_equals(q[1], image.getPixel(0, 1))
    cornell.assert_equals(q[4], image.getPixel(2, 0))
    image.swapPixels(0, 0, 0, 0)
    cornell.assert_equals(q[0], image.getPixel(0, 0))

    # Test enforcement
    good = test_assert(image.swapPixels, ['a', 1, 0, 0],
                       'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.swapPixels, [8, 1, 0, 0],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.swapPixels, [0, 1, 'a', 0],
        'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.swapPixels, [0, 1, 8, 0],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.swapPixels, [0, 'a', 0, 0],
        'You are not enforcing the precondition on column type')
    good = good and test_assert(
        image.swapPixels, [0, 8, 0, 0],
        'You are not enforcing the precondition on column value')
    good = good and test_assert(
        image.swapPixels, [0, 1, 0, 'a'],
        'You are not enforcing the precondition on column type')
    good = good and test_assert(
        image.swapPixels, [0, 1, 0, 8],
        'You are not enforcing the precondition on column value')
    if not good:
        exit()
Пример #15
0
def test_image_access():
    """
    Tests the methods get/setPixel and get/setFlatPixel in class Image
    """
    print('Testing image pixel access')
    import a6image
    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)
    rgb1 = (255, 255, 255)
    rgb2 = (64, 128, 192)

    image = a6image.Image(p, 2)
    for n in range(6):
        cornell.assert_equals(p[n], image.getFlatPixel(n))
        cornell.assert_equals(id(p[n]), id(image.getFlatPixel(n)))

    image.setFlatPixel(4, rgb1)
    cornell.assert_equals(rgb1, image.getFlatPixel(4))
    image.setFlatPixel(4, rgb2)
    cornell.assert_equals(rgb2, image.getFlatPixel(4))

    for n in range(6):
        cornell.assert_equals(p[n], image.getPixel(n // 2, n % 2))
        cornell.assert_equals(id(p[n]), id(image.getPixel(n // 2, n % 2)))

    image.setPixel(2, 1, rgb1)
    cornell.assert_equals(rgb1, image.getPixel(2, 1))

    image.setPixel(2, 1, rgb2)
    cornell.assert_equals(rgb2, image.getPixel(2, 1))

    # Test enforcement
    good = test_assert(image.getPixel, ['a', 1],
                       'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.getPixel, [8, 1],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.getPixel, [2, 'a'],
        'You are not enforcing the precondition on col value')
    good = good and test_assert(
        image.getPixel, [2, 8],
        'You are not enforcing the precondition on col value')
    good = good and test_assert(
        image.setPixel, ['a', 1, p],
        'You are not enforcing the precondition on row type')
    good = good and test_assert(
        image.setPixel, [8, 1, p],
        'You are not enforcing the precondition on row value')
    good = good and test_assert(
        image.setPixel, [2, 'a', p],
        'You are not enforcing the precondition on col value')
    good = good and test_assert(
        image.setPixel, [2, 8, p],
        'You are not enforcing the precondition on col value')
    if not good:
        exit()