Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Cimpl import create_color, create_image, get_color, set_color,\
- Image
- from test_invert import check_equal
- from L7_15_P5_horizontal import flip_horizontal
- def test_flip_horizontal() -> None:
- '''
- 101162929 Hiu Sum Jaime Yue
- A test function for flip_horizontal.
- >>> test_flip_horizontal()
- '''
- # Create an image with eight pixels. For testing the flip horizontal filter,
- # I picked eight random set of RGB colour codes, just to check if the filter
- # is working. For the RGB value of (0,0) should swap with the RGB
- # values in (0,3). The RGB value of (0,1) should swap with the RGB values
- # in (0,2). Check if anything in the code affect the x value, I create one
- # more column. For the RGB value of (1,0) should swap with the RGB
- # values in (1,3). The RGB value of (1,1) should swap with the RGB values
- # in (1,2).
- original = create_image(2, 4)
- set_color(original, 0, 0, create_color(0, 0, 0))
- set_color(original, 0, 1, create_color(128, 127, 128))
- set_color(original, 0, 2, create_color(0, 0, 1))
- set_color(original, 0, 3, create_color(255, 255, 255))
- set_color(original, 1, 0, create_color(254, 254, 254))
- set_color(original, 1, 1, create_color(128, 127, 128))
- set_color(original, 1, 2, create_color(254, 255, 254))
- set_color(original, 1, 3, create_color(0, 1, 0))
- # Create an image that's identical to the one a correct implementation of
- # flip_horizontal should produce when it is passed original.
- expected = create_image(2, 4)
- set_color(expected, 0, 0, create_color(255, 255, 255))
- set_color(expected, 0, 1, create_color(0, 0, 1))
- set_color(expected, 0, 2, create_color(128, 127, 128))
- set_color(expected, 0, 3, create_color(0, 0, 0))
- set_color(expected, 1, 0, create_color(0, 1, 0))
- set_color(expected, 1, 1, create_color(254, 255, 254))
- set_color(expected, 1, 2, create_color(128, 127, 128))
- set_color(expected, 1, 3, create_color(254, 254, 254))
- # Compare the transformed image returned by the filter with the
- # expected image, one pixel at a time.
- fliped = flip_horizontal(original)
- for x, y, col in fliped:
- check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')',
- col, get_color(expected, x, y))
- test_flip_horizontal()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement