Changes:
- refactoring
- Tests added
- Feedback implemented
module HeLlOwOrLd where import Data.Char (toUpper, toLower, isLetter) convert :: String -> String convert = zipWith ($) (cycle [toUpper, toLower]) . filter isLetter
- module HeLlOwOrLd where
import Data.Char (toUpper, toLower)- import Data.Char (toUpper, toLower, isLetter)
- convert :: String -> String
convert [] = []convert (' ':xs) = convert xsconvert (x:xs) = (toUpper x):(convert' xs) whereconvert' :: String -> Stringconvert' [] = []convert' (' ':xs) = convert' xsconvert' (x:xs) = (toLower x):(convert xs)- convert = zipWith ($) (cycle [toUpper, toLower]) . filter isLetter
module HeLlOwOrLdSpec where -- Tests can be written using Hspec http://hspec.github.io/ -- Replace this with your own tests. import Test.Hspec import HeLlOwOrLd -- `spec` of type `Spec` must exist spec :: Spec spec = do describe "convert" $ do it "basic tests" $ do convert "Hello World" `shouldBe` "HeLlOwOrLd" convert " Ola QueAse" `shouldBe` "OlAqUeAsE" convert "123!@#ABC" `shouldBe` "AbC" convert "" `shouldBe` "" -- the following line is optional for 8.2 main = hspec spec
- module HeLlOwOrLdSpec where
- -- Tests can be written using Hspec http://hspec.github.io/
- -- Replace this with your own tests.
- import Test.Hspec
- import HeLlOwOrLd
- -- `spec` of type `Spec` must exist
- spec :: Spec
- spec = do
- describe "convert" $ do
- it "basic tests" $ do
(convert "Hello World") `shouldBe` ("HeLlOwOrLd" :: String)(convert " Ola QueAse") `shouldBe` ("OlAqUeAsE" :: String)- convert "Hello World" `shouldBe` "HeLlOwOrLd"
- convert " Ola QueAse" `shouldBe` "OlAqUeAsE"
- convert "123!@#ABC" `shouldBe` "AbC"
- convert "" `shouldBe` ""
- -- the following line is optional for 8.2
- main = hspec spec