Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduction to ranges #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hkata.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ library
hs-source-dirs: src
exposed-modules: HelloWorld
, ListKata.Extract
, ListKata.Ranges
build-depends: base >= 4.7 && < 5
default-language: Haskell2010

Expand Down
1 change: 1 addition & 0 deletions src/ListKata/Ranges.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module ListKata.Ranges where
21 changes: 21 additions & 0 deletions test/ListKata/RangesSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module ListKata.RangesSpec where

import Test.Hspec
import Test.QuickCheck
import ListKata.Ranges

spec :: Spec
spec = do
describe "range syntax and usage" $ do
it "gives a shorthand for a list" $
[1..10] `shouldBe` [1,2,3,4,5,6,7,8,9,10]
it "defines steps" $
[2,4..10] `shouldBe` [2,4,6,8,10]
describe "cycling through a range" $
it "goes forever, so remember to take" $
take 6 (cycle [1..3]) `shouldBe` [1,2,3,1,2,3]
describe "repeating an item" $ do
it "goes forever, so remember to take" $
take 6 (repeat 'a') `shouldBe` "aaaaaa"
it "better expressed by replicate" $
replicate 6 'a' `shouldBe` "aaaaaa"