module InfiniteSeq where import Data.List ones = repeat 1 nats = [0..] merge = concat . transpose merge2 x y = merge [x, y] ints = 0: merge2 [1..] [(-1),(-2)..] fibs = 1 : scanl (+) 1 fibs
- module InfiniteSeq where
- import Data.List
- ones = repeat 1
- nats = [0..]
- merge = concat . transpose
- merge2 x y = merge [x, y]
- ints = 0: merge2 [1..] [(-1),(-2)..]
- fibs = 1 : scanl (+) 1 fibs
module Codewars.InfiniteSeq.Test where import InfiniteSeq import Test.Hspec import Test.QuickCheck import Test.Hspec.QuickCheck main = hspec $ do describe "test infinite" $ do it "test ones" $ do take 3 ones `shouldBe` [1,1,1] it "test naturals" $ do take 11 InfiniteSeq.nats `shouldBe` [0..10] it "test ints" $ do 10 `elem` ints `shouldBe` True (-10) `elem` ints `shouldBe` True it "test fibs" $ do take 7 fibs `shouldBe` [1,1,2,3,5,8,13]
- module Codewars.InfiniteSeq.Test where
- import InfiniteSeq
- import Test.Hspec
- import Test.QuickCheck
- import Test.Hspec.QuickCheck
- main = hspec $ do
- describe "test infinite" $ do
- it "test ones" $ do
- take 3 ones `shouldBe` [1,1,1]
- it "test naturals" $ do
- take 11 InfiniteSeq.nats `shouldBe` [0..10]
- it "test ints" $ do
- 10 `elem` ints `shouldBe` True
(-10) `elem` ints `shouldBe` True- (-10) `elem` ints `shouldBe` True
- it "test fibs" $ do
- take 7 fibs `shouldBe` [1,1,2,3,5,8,13]