1module VerifyImageOps where
3import Graphics.Vty.Attributes
4import Graphics.Vty.Image.Internal
5import Verify.Graphics.Vty.Image
11two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
12two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
13 image_width (char def_attr c1 <|> char def_attr c2) == 2
15many_sw_horiz_concat :: [SingleColumnChar] -> Bool
16many_sw_horiz_concat cs =
17 let chars = [ char | SingleColumnChar char <- cs ]
18 l = fromIntegral $ length cs
19 in image_width ( horiz_cat $ map (char def_attr) chars ) == l
21two_sw_vert_concat :: SingleColumnChar -> SingleColumnChar -> Bool
22two_sw_vert_concat (SingleColumnChar c1) (SingleColumnChar c2) =
23 image_height (char def_attr c1 <-> char def_attr c2) == 2
25horiz_concat_sw_assoc :: SingleColumnChar -> SingleColumnChar -> SingleColumnChar -> Bool
26horiz_concat_sw_assoc (SingleColumnChar c0) (SingleColumnChar c1) (SingleColumnChar c2) =
27 (char def_attr c0 <|> char def_attr c1) <|> char def_attr c2
29 char def_attr c0 <|> (char def_attr c1 <|> char def_attr c2)
31two_dw_horiz_concat :: DoubleColumnChar -> DoubleColumnChar -> Bool
32two_dw_horiz_concat (DoubleColumnChar c1) (DoubleColumnChar c2) =
33 image_width (char def_attr c1 <|> char def_attr c2) == 4
35many_dw_horiz_concat :: [DoubleColumnChar] -> Bool
36many_dw_horiz_concat cs =
37 let chars = [ char | DoubleColumnChar char <- cs ]
38 l = fromIntegral $ length cs
39 in image_width ( horiz_cat $ map (char def_attr) chars ) == l * 2
41two_dw_vert_concat :: DoubleColumnChar -> DoubleColumnChar -> Bool
42two_dw_vert_concat (DoubleColumnChar c1) (DoubleColumnChar c2) =
43 image_height (char def_attr c1 <-> char def_attr c2) == 2
45horiz_concat_dw_assoc :: DoubleColumnChar -> DoubleColumnChar -> DoubleColumnChar -> Bool
46horiz_concat_dw_assoc (DoubleColumnChar c0) (DoubleColumnChar c1) (DoubleColumnChar c2) =
47 (char def_attr c0 <|> char def_attr c1) <|> char def_attr c2
49 char def_attr c0 <|> (char def_attr c1 <|> char def_attr c2)
51vert_contat_single_row :: NonEmptyList SingleRowSingleAttrImage -> Bool
52vert_contat_single_row (NonEmpty stack) =
53 let expected_height :: Int = length stack
54 stack_image = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack ]
55 in image_height stack_image == expected_height
57disjoint_height_horiz_join :: NonEmptyList SingleRowSingleAttrImage
58 -> NonEmptyList SingleRowSingleAttrImage
60disjoint_height_horiz_join (NonEmpty stack_0) (NonEmpty stack_1) =
61 let expected_height :: Int = max (length stack_0) (length stack_1)
62 stack_image_0 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
63 stack_image_1 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
64 in image_height (stack_image_0 <|> stack_image_1) == expected_height
67disjoint_height_horiz_join_bg_fill :: NonEmptyList SingleRowSingleAttrImage
68 -> NonEmptyList SingleRowSingleAttrImage
70disjoint_height_horiz_join_bg_fill (NonEmpty stack_0) (NonEmpty stack_1) =
71 let stack_image_0 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
72 stack_image_1 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
73 image = stack_image_0 <|> stack_image_1
74 expected_height = image_height image
76 HorizJoin {} -> ( expected_height == (image_height $ part_left image) )
78 ( expected_height == (image_height $ part_right image) )
81disjoint_width_vert_join :: NonEmptyList SingleRowSingleAttrImage
82 -> NonEmptyList SingleRowSingleAttrImage
84disjoint_width_vert_join (NonEmpty stack_0) (NonEmpty stack_1) =
85 let expected_width = maximum $ map image_width (stack_0_images ++ stack_1_images)
86 stack_0_images = [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
87 stack_1_images = [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
88 stack_0_image = vert_cat stack_0_images
89 stack_1_image = vert_cat stack_1_images
90 image = stack_0_image <-> stack_1_image
91 in image_width image == expected_width
93disjoint_width_vert_join_bg_fill :: NonEmptyList SingleRowSingleAttrImage
94 -> NonEmptyList SingleRowSingleAttrImage
96disjoint_width_vert_join_bg_fill (NonEmpty stack_0) (NonEmpty stack_1) =
97 let expected_width = maximum $ map image_width (stack_0_images ++ stack_1_images)
98 stack_0_images = [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
99 stack_1_images = [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
100 stack_0_image = vert_cat stack_0_images
101 stack_1_image = vert_cat stack_1_images
102 image = stack_0_image <-> stack_1_image
104 VertJoin {} -> ( expected_width == (image_width $ part_top image) )
106 ( expected_width == (image_width $ part_bottom image) )
109translation_is_linear_on_out_size :: Translation -> Bool
110translation_is_linear_on_out_size (Translation i (x,y) i') =
111 image_width i' == image_width i + x && image_height i' == image_height i + y
113padding_is_linear_on_out_size :: Image -> Gen Bool
114padding_is_linear_on_out_size i = do
119 let i' = pad l t r b i
120 return $ image_width i' == image_width i + l + r && image_height i' == image_height i + t + b
121 where offset = choose (1,1024)
123crop_left_limits_width :: Image -> Int -> Property
124crop_left_limits_width i v = v >= 0 ==>
125 v >= image_width (crop_left v i)
127crop_right_limits_width :: Image -> Int -> Property
128crop_right_limits_width i v = v >= 0 ==>
129 v >= image_width (crop_right v i)
131crop_top_limits_height :: Image -> Int -> Property
132crop_top_limits_height i v = v >= 0 ==>
133 v >= image_height (crop_top v i)
135crop_bottom_limits_height :: Image -> Int -> Property
136crop_bottom_limits_height i v = v >= 0 ==>
137 v >= image_height (crop_bottom v i)
139-- rediculous tests just to satisfy my desire for nice code coverage :-P
140can_show_image :: Image -> Bool
141can_show_image i = length (show i) > 0
143can_rnf_image :: Image -> Bool
144can_rnf_image i = rnf i == ()
146can_pp_image :: Image -> Bool
147can_pp_image i = length (pp_image_structure i) > 0
151 [ verify "two_sw_horiz_concat" two_sw_horiz_concat
152 , verify "many_sw_horiz_concat" many_sw_horiz_concat
153 , verify "two_sw_vert_concat" two_sw_vert_concat
154 , verify "horiz_concat_sw_assoc" horiz_concat_sw_assoc
155 , verify "many_dw_horiz_concat" many_dw_horiz_concat
156 , verify "two_dw_horiz_concat" two_dw_horiz_concat
157 , verify "two_dw_vert_concat" two_dw_vert_concat
158 , verify "horiz_concat_dw_assoc" horiz_concat_dw_assoc
159 , verify "single row vert concats to correct height" vert_contat_single_row
160 , verify "disjoint_height_horiz_join" disjoint_height_horiz_join
161 , verify "disjoint_height_horiz_join BG fill" disjoint_height_horiz_join_bg_fill
162 , verify "disjoint_width_vert_join" disjoint_width_vert_join
163 , verify "disjoint_width_vert_join BG fill" disjoint_width_vert_join_bg_fill
164 , verify "translation effects output dimensions linearly" translation_is_linear_on_out_size
165 , verify "padding effects output dimensions linearly" padding_is_linear_on_out_size
166 , verify "crop left limits width" crop_left_limits_width
167 , verify "crop right limits width" crop_right_limits_width
168 , verify "crop top limits height" crop_top_limits_height
169 , verify "crop bottom limits height" crop_bottom_limits_height
170 , verify "can show image" can_show_image
171 , verify "can rnf image" can_rnf_image
172 , verify "can pp image" can_pp_image
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list