• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Nov 22nd, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from Cimpl import create_color, create_image, get_color, set_color,\
2.                   Image
3.
4. from test_invert import check_equal
5.
6. from L7_15_P5_horizontal import flip_horizontal
7.
8. def test_flip_horizontal() -> None:
9.     '''
10.    101162929 Hiu Sum Jaime Yue
11.    A test function for flip_horizontal.
12.
13.    >>> test_flip_horizontal()
14.    '''
15.     # Create an image with eight pixels. For testing the flip horizontal filter,
16.     # I picked eight random set of RGB colour codes, just to check if the filter
17.     # is working. For the RGB value of (0,0) should swap with the RGB
18.     # values in (0,3). The RGB value of (0,1) should swap with the RGB values
19.     # in (0,2). Check if anything in the code affect the x value, I create one
20.     # more column. For the RGB value of (1,0) should swap with the RGB
21.     # values in (1,3). The RGB value of (1,1) should swap with the RGB values
22.     # in (1,2).
23.
24.     original = create_image(2, 4)
25.     set_color(original, 0, 0,  create_color(0, 0, 0))
26.     set_color(original, 0, 1,  create_color(128, 127, 128))
27.     set_color(original, 0, 2,  create_color(0, 0, 1))
28.     set_color(original, 0, 3,  create_color(255, 255, 255))
29.     set_color(original, 1, 0,  create_color(254, 254, 254))
30.     set_color(original, 1, 1,  create_color(128, 127, 128))
31.     set_color(original, 1, 2,  create_color(254, 255, 254))
32.     set_color(original, 1, 3,  create_color(0, 1, 0))
33.
34.     # Create an image that's identical to the one a correct implementation of
35.     # flip_horizontal should produce when it is passed original.
36.
37.     expected = create_image(2, 4)
38.     set_color(expected, 0, 0,  create_color(255, 255, 255))
39.     set_color(expected, 0, 1,  create_color(0, 0, 1))
40.     set_color(expected, 0, 2,  create_color(128, 127, 128))
41.     set_color(expected, 0, 3,  create_color(0, 0, 0))
42.     set_color(expected, 1, 0,  create_color(0, 1, 0))
43.     set_color(expected, 1, 1,  create_color(254, 255, 254))
44.     set_color(expected, 1, 2,  create_color(128, 127, 128))
45.     set_color(expected, 1, 3,  create_color(254, 254, 254))
46.
47.     # Compare the transformed image returned by the filter with the
48.     # expected image, one pixel at a time.
49.
50.     fliped = flip_horizontal(original)
51.     for x, y, col in fliped:
52.         check_equal('Checking pixel @(' + str(x) + ', ' + str(y) + ')',
53.                      col, get_color(expected, x, y))
54.
55. test_flip_horizontal()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top