Skip to content

Commit

Permalink
Remove use of head and tail.
Browse files Browse the repository at this point in the history
  • Loading branch information
chungyc committed Jun 2, 2024
1 parent 8a9d03c commit 6561af9
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions test/Problems/P08Spec.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{-# OPTIONS_GHC -Wno-x-partial -Wno-unrecognised-warning-flags #-}

{-|
Copyright: Copyright (C) 2023 Yoo Chung
License: GPL-3.0-or-later
Expand Down Expand Up @@ -28,19 +26,22 @@ properties compress name = describe name $ do
compress (xs ++ [x] ++ xs') `shouldSatisfy` elem x

prop "removes consecutive duplicates" $
\xs (Positive k) x ys ->
null xs || last xs /= x ==>
null ys || head ys /= x ==>
compress (xs ++ replicate k x ++ ys)
`shouldBe` compress xs ++ [x] ++ compress ys

prop "maintains order" $ \xs xs' ->
not (null xs) ==>
not (null xs') ==>
counterexample (show $ xs ++ xs') $
case last xs == head xs' of
True -> compress (xs ++ xs') `shouldBe` compress xs ++ tail (compress xs')
False -> compress (xs ++ xs') `shouldBe` compress xs ++ compress xs'
\xs x z y ys (Positive k) ->
x /= z && z /= y ==>
let xs' = xs ++ [x]
ys' = y : ys
vs = xs' ++ replicate k z ++ ys'
in counterexample (show vs) $
compress vs `shouldBe` compress xs' ++ [z] ++ compress ys'

prop "maintains order" $ \xs x y ys ->
let xs' = xs ++ [x]
ys' = y : ys
vs = xs' ++ ys'
in counterexample (show vs) $
case x == y of
True -> compress vs `shouldBe` compress xs' ++ drop 1 (compress ys')
False -> compress vs `shouldBe` compress xs' ++ compress ys'

examples :: Spec
examples = describe "Examples" $ do
Expand Down

0 comments on commit 6561af9

Please sign in to comment.