on master help sign in
Test center

--HG-- extra : convert_revision : 139aa0f10e78f9dcddf2cc3c5e67eaa8301ee5fc

commit46740502fdf1ed7baddc5a852cdcf4f07e5be6ae authorBryan O'Sullivan <bos@serpentine.com> dateSun 29 Aug 2010, 04:51 (16 years ago) parentea75ebc
1 file changed+16−3
tests/Properties.hs+16−3
tests/Properties.hs+16−3
@@ -264,8 +264,15 @@ t_toUpper_upper t = p (T.toUpper t) >= p t
264264tl_toUpper_upper t = p (TL.toUpper t) >= p t
265265 where p = TL.length . TL.filter isUpper
266266
267−justifyLeft k c s = s ++ L.replicate (k - length s) c
268−justifyRight m n s = L.replicate (m - length s) n ++ s
267+justifyLeft k c xs = xs ++ L.replicate (k - length xs) c
268+justifyRight m n xs = L.replicate (m - length xs) n ++ xs
269+center k c xs
270+ | len >= k = xs
271+ | otherwise = L.replicate l c ++ xs ++ L.replicate r c
272+ where len = length xs
273+ d = k - len
274+ r = d `div` 2
275+ l = d - r
269276
270277s_justifyLeft k c = justifyLeft j c `eqP` (unpackS . S.justifyLeftI j c)
271278 where j = fromIntegral (k :: Word8)
@@ -282,6 +289,10 @@ t_justifyRight k c = justifyRight j c `eqP` (unpackS . T.justifyRight j c)
282289 where j = fromIntegral (k :: Word8)
283290tl_justifyRight k c = justifyRight j c `eqP` (unpackS . TL.justifyRight (fromIntegral j) c)
284291 where j = fromIntegral (k :: Word8)
292+t_center k c = center j c `eqP` (unpackS . T.center j c)
293+ where j = fromIntegral (k :: Word8)
294+tl_center k c = center j c `eqP` (unpackS . TL.center (fromIntegral j) c)
295+ where j = fromIntegral (k :: Word8)
285296
286297sf_foldl p f z = (L.foldl f z . L.filter p) `eqP` (S.foldl f z . S.filter p)
287298 where _types = f :: Char -> Char -> Char
@@ -810,7 +821,9 @@ tests = [
810821 testProperty "t_justifyLeft" t_justifyLeft,
811822 testProperty "tl_justifyLeft" tl_justifyLeft,
812823 testProperty "t_justifyRight" t_justifyRight,
813− testProperty "tl_justifyRight" tl_justifyRight
824+ testProperty "tl_justifyRight" tl_justifyRight,
825+ testProperty "t_center" t_center,
826+ testProperty "tl_center" tl_center
814827 ]
815828 ],
816829