Skip to content

Commit dac529d

Browse files
committed
add Problem7 and Problem7 Test Code of 99 Questions in Haskell Wiki
1 parent ca8e216 commit dac529d

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/Wiki_99_Questions/Problem8.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Problem8
2+
-- Eliminate consecutive duplicates of list elements.
3+
-- If a list contains repeated elements they should be replaced with a single copy of the element.
4+
-- The order of the elements should not be changed.
5+
6+
module Wiki_99_Questions.Problem8 where
7+
import Data.List
8+
9+
compress :: Eq a => [a] -> [a]
10+
compress = map head . group

studying-haskell.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ library
2222
, Wiki_99_Questions.Problem5
2323
, Wiki_99_Questions.Problem6
2424
, Wiki_99_Questions.Problem7
25+
, Wiki_99_Questions.Problem8
2526
, Lib
2627
build-depends: base >= 4.7 && < 5
2728
default-language: Haskell2010
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Wiki_99_Questions.Problem8Spec where
2+
3+
import Test.Hspec
4+
import Wiki_99_Questions.Problem8
5+
6+
spec :: Spec
7+
spec = do
8+
describe "Test1 for Problem8" $ do
9+
it "compress \"aaaabbbccc\" -> \"abc\" " $ do
10+
compress "aaaabbbccc" `shouldBe` "abc"
11+
12+
describe "Test2 for Problem9" $ do
13+
it "compress \"Haskellllll\" -> \"Haskel\"" $ do
14+
compress "Haskellllll" `shouldBe` "Haskel"

0 commit comments

Comments
 (0)