Add new test case
module ExampleSpec where -- Tests can be written using Hspec http://hspec.github.io/ -- Replace this with your own tests. import Test.Hspec import ToUpperFirst -- `spec` of type `Spec` must exist spec :: Spec spec = do describe "toUpperFirst" $ do it "should capitalize first character of a string" $ do toUpperFirst "" `shouldBe` "" toUpperFirst "finn the human" `shouldBe` "Finn the human" toUpperFirst "alice" `shouldBe` "Alice" toUpperFirst "Joe" `shouldBe` "Joe" -- the following line is optional for 8.2 main = hspec spec
- module ExampleSpec where
- -- Tests can be written using Hspec http://hspec.github.io/
- -- Replace this with your own tests.
- import Test.Hspec
- import ToUpperFirst
- -- `spec` of type `Spec` must exist
- spec :: Spec
- spec = do
- describe "toUpperFirst" $ do
it "capitalize first character of a string" $ do- it "should capitalize first character of a string" $ do
- toUpperFirst "" `shouldBe` ""
- toUpperFirst "finn the human" `shouldBe` "Finn the human"
- toUpperFirst "alice" `shouldBe` "Alice"
- toUpperFirst "Joe" `shouldBe` "Joe"
- -- the following line is optional for 8.2
- main = hspec spec
add a new test case
module AddNumbersSpec where import Test.Hspec import AddNumbers spec :: Spec spec = do describe "add_arr" $ do it "sums 1..9" $ do (add_arr [1..9]) `shouldBe` (45) it "sums 1..2" $ do (add_arr [1..2]) `shouldBe` (3) it "sums 1..3,-4,5..9" $ do (add_arr [1,2,3,-4,5,6,7,8,9]) `shouldBe` (37)
- module AddNumbersSpec where
- import Test.Hspec
- import AddNumbers
- spec :: Spec
- spec = do
describe "add_arr" $ doit "1..9" $ do- describe "add_arr" $ do
- it "sums 1..9" $ do
- (add_arr [1..9]) `shouldBe` (45)
it "1..3,-4,5..9" $ do- it "sums 1..2" $ do
- (add_arr [1..2]) `shouldBe` (3)
- it "sums 1..3,-4,5..9" $ do
- (add_arr [1,2,3,-4,5,6,7,8,9]) `shouldBe` (37)
added a new test case
module TestSpec (spec) where import Solution import Test.Hspec import Test.QuickCheck import Control.Exception (evaluate) spec :: Spec spec = do it "works with 0" $ do fizzbuzz [] 0 0 `shouldBe` ["fizzbuzz"] it "works with 1" $ do fizzbuzz [] 0 1 `shouldBe` ["fizzbuzz", "1"] it "works with 2" $ do fizzbuzz [] 0 2 `shouldBe` ["fizzbuzz", "1", "2"] it "works with 11" $ do fizzbuzz [] 0 11 `shouldBe` ["fizzbuzz", "1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11"] it "works with 512" $ do fizzbuzz [] 0 512 `shouldBe` ["fizzbuzz","1","2","fizz","4","buzz","fizz","7","8","fizz","buzz","11","fizz","13","14","fizzbuzz","16","17","fizz","19","buzz","fizz","22","23","fizz","buzz","26","fizz","28","29","fizzbuzz","31","32","fizz","34","buzz","fizz","37","38","fizz","buzz","41","fizz","43","44","fizzbuzz","46","47","fizz","49","buzz","fizz","52","53","fizz","buzz","56","fizz","58","59","fizzbuzz","61","62","fizz","64","buzz","fizz","67","68","fizz","buzz","71","fizz","73","74","fizzbuzz","76","77","fizz","79","buzz","fizz","82","83","fizz","buzz","86","fizz","88","89","fizzbuzz","91","92","fizz","94","buzz","fizz","97","98","fizz","buzz","101","fizz","103","104","fizzbuzz","106","107","fizz","109","buzz","fizz","112","113","fizz","buzz","116","fizz","118","119","fizzbuzz","121","122","fizz","124","buzz","fizz","127","128","fizz","buzz","131","fizz","133","134","fizzbuzz","136","137","fizz","139","buzz","fizz","142","143","fizz","buzz","146","fizz","148","149","fizzbuzz","151","152","fizz","154","buzz","fizz","157","158","fizz","buzz","161","fizz","163","164","fizzbuzz","166","167","fizz","169","buzz","fizz","172","173","fizz","buzz","176","fizz","178","179","fizzbuzz","181","182","fizz","184","buzz","fizz","187","188","fizz","buzz","191","fizz","193","194","fizzbuzz","196","197","fizz","199","buzz","fizz","202","203","fizz","buzz","206","fizz","208","209","fizzbuzz","211","212","fizz","214","buzz","fizz","217","218","fizz","buzz","221","fizz","223","224","fizzbuzz","226","227","fizz","229","buzz","fizz","232","233","fizz","buzz","236","fizz","238","239","fizzbuzz","241","242","fizz","244","buzz","fizz","247","248","fizz","buzz","251","fizz","253","254","fizzbuzz","256","257","fizz","259","buzz","fizz","262","263","fizz","buzz","266","fizz","268","269","fizzbuzz","271","272","fizz","274","buzz","fizz","277","278","fizz","buzz","281","fizz","283","284","fizzbuzz","286","287","fizz","289","buzz","fizz","292","293","fizz","buzz","296","fizz","298","299","fizzbuzz","301","302","fizz","304","buzz","fizz","307","308","fizz","buzz","311","fizz","313","314","fizzbuzz","316","317","fizz","319","buzz","fizz","322","323","fizz","buzz","326","fizz","328","329","fizzbuzz","331","332","fizz","334","buzz","fizz","337","338","fizz","buzz","341","fizz","343","344","fizzbuzz","346","347","fizz","349","buzz","fizz","352","353","fizz","buzz","356","fizz","358","359","fizzbuzz","361","362","fizz","364","buzz","fizz","367","368","fizz","buzz","371","fizz","373","374","fizzbuzz","376","377","fizz","379","buzz","fizz","382","383","fizz","buzz","386","fizz","388","389","fizzbuzz","391","392","fizz","394","buzz","fizz","397","398","fizz","buzz","401","fizz","403","404","fizzbuzz","406","407","fizz","409","buzz","fizz","412","413","fizz","buzz","416","fizz","418","419","fizzbuzz","421","422","fizz","424","buzz","fizz","427","428","fizz","buzz","431","fizz","433","434","fizzbuzz","436","437","fizz","439","buzz","fizz","442","443","fizz","buzz","446","fizz","448","449","fizzbuzz","451","452","fizz","454","buzz","fizz","457","458","fizz","buzz","461","fizz","463","464","fizzbuzz","466","467","fizz","469","buzz","fizz","472","473","fizz","buzz","476","fizz","478","479","fizzbuzz","481","482","fizz","484","buzz","fizz","487","488","fizz","buzz","491","fizz","493","494","fizzbuzz","496","497","fizz","499","buzz","fizz","502","503","fizz","buzz","506","fizz","508","509","fizzbuzz","511","512"]
- module TestSpec (spec) where
- import Solution
- import Test.Hspec
- import Test.QuickCheck
- import Control.Exception (evaluate)
- spec :: Spec
- spec = do
- it "works with 0" $ do
- fizzbuzz [] 0 0 `shouldBe` ["fizzbuzz"]
- it "works with 1" $ do
- fizzbuzz [] 0 1 `shouldBe` ["fizzbuzz", "1"]
- it "works with 2" $ do
- fizzbuzz [] 0 2 `shouldBe` ["fizzbuzz", "1", "2"]
- it "works with 11" $ do
- fizzbuzz [] 0 11 `shouldBe` ["fizzbuzz", "1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11"]
- it "works with 512" $ do
- fizzbuzz [] 0 512 `shouldBe` ["fizzbuzz","1","2","fizz","4","buzz","fizz","7","8","fizz","buzz","11","fizz","13","14","fizzbuzz","16","17","fizz","19","buzz","fizz","22","23","fizz","buzz","26","fizz","28","29","fizzbuzz","31","32","fizz","34","buzz","fizz","37","38","fizz","buzz","41","fizz","43","44","fizzbuzz","46","47","fizz","49","buzz","fizz","52","53","fizz","buzz","56","fizz","58","59","fizzbuzz","61","62","fizz","64","buzz","fizz","67","68","fizz","buzz","71","fizz","73","74","fizzbuzz","76","77","fizz","79","buzz","fizz","82","83","fizz","buzz","86","fizz","88","89","fizzbuzz","91","92","fizz","94","buzz","fizz","97","98","fizz","buzz","101","fizz","103","104","fizzbuzz","106","107","fizz","109","buzz","fizz","112","113","fizz","buzz","116","fizz","118","119","fizzbuzz","121","122","fizz","124","buzz","fizz","127","128","fizz","buzz","131","fizz","133","134","fizzbuzz","136","137","fizz","139","buzz","fizz","142","143","fizz","buzz","146","fizz","148","149","fizzbuzz","151","152","fizz","154","buzz","fizz","157","158","fizz","buzz","161","fizz","163","164","fizzbuzz","166","167","fizz","169","buzz","fizz","172","173","fizz","buzz","176","fizz","178","179","fizzbuzz","181","182","fizz","184","buzz","fizz","187","188","fizz","buzz","191","fizz","193","194","fizzbuzz","196","197","fizz","199","buzz","fizz","202","203","fizz","buzz","206","fizz","208","209","fizzbuzz","211","212","fizz","214","buzz","fizz","217","218","fizz","buzz","221","fizz","223","224","fizzbuzz","226","227","fizz","229","buzz","fizz","232","233","fizz","buzz","236","fizz","238","239","fizzbuzz","241","242","fizz","244","buzz","fizz","247","248","fizz","buzz","251","fizz","253","254","fizzbuzz","256","257","fizz","259","buzz","fizz","262","263","fizz","buzz","266","fizz","268","269","fizzbuzz","271","272","fizz","274","buzz","fizz","277","278","fizz","buzz","281","fizz","283","284","fizzbuzz","286","287","fizz","289","buzz","fizz","292","293","fizz","buzz","296","fizz","298","299","fizzbuzz","301","302","fizz","304","buzz","fizz","307","308","fizz","buzz","311","fizz","313","314","fizzbuzz","316","317","fizz","319","buzz","fizz","322","323","fizz","buzz","326","fizz","328","329","fizzbuzz","331","332","fizz","334","buzz","fizz","337","338","fizz","buzz","341","fizz","343","344","fizzbuzz","346","347","fizz","349","buzz","fizz","352","353","fizz","buzz","356","fizz","358","359","fizzbuzz","361","362","fizz","364","buzz","fizz","367","368","fizz","buzz","371","fizz","373","374","fizzbuzz","376","377","fizz","379","buzz","fizz","382","383","fizz","buzz","386","fizz","388","389","fizzbuzz","391","392","fizz","394","buzz","fizz","397","398","fizz","buzz","401","fizz","403","404","fizzbuzz","406","407","fizz","409","buzz","fizz","412","413","fizz","buzz","416","fizz","418","419","fizzbuzz","421","422","fizz","424","buzz","fizz","427","428","fizz","buzz","431","fizz","433","434","fizzbuzz","436","437","fizz","439","buzz","fizz","442","443","fizz","buzz","446","fizz","448","449","fizzbuzz","451","452","fizz","454","buzz","fizz","457","458","fizz","buzz","461","fizz","463","464","fizzbuzz","466","467","fizz","469","buzz","fizz","472","473","fizz","buzz","476","fizz","478","479","fizzbuzz","481","482","fizz","484","buzz","fizz","487","488","fizz","buzz","491","fizz","493","494","fizzbuzz","496","497","fizz","499","buzz","fizz","502","503","fizz","buzz","506","fizz","508","509","fizzbuzz","511","512"]
Fundamentals
Functional Programming
add a new test case
module NumberPrintSpec where import Test.Hspec import NumberPrint spec :: Spec spec = do describe "Tests" $ do it "Fixed Tests" $ do numberprint 1 `shouldBe` 1 numberprint 2 `shouldBe` 121 numberprint 4 `shouldBe` 1234321 numberprint 10 `shouldBe` 12345678910987654321 numberprint 12 `shouldBe` 1234567891011121110987654321 numberprint 15 `shouldBe` 1234567891011121314151413121110987654321 main = hspec spec
- module NumberPrintSpec where
- import Test.Hspec
- import NumberPrint
- spec :: Spec
- spec = do
- describe "Tests" $ do
- it "Fixed Tests" $ do
- numberprint 1 `shouldBe` 1
- numberprint 2 `shouldBe` 121
- numberprint 4 `shouldBe` 1234321
- numberprint 10 `shouldBe` 12345678910987654321
- numberprint 12 `shouldBe` 1234567891011121110987654321
- numberprint 15 `shouldBe` 1234567891011121314151413121110987654321
- main = hspec spec
update tests
module AreThereThreeSpec where import Test.Hspec import AreThereThree spec :: Spec spec = do describe "Tests" $ do it "should return True if contains 3" $ do solution 354523 `shouldBe` True solution 35 `shouldBe` True it "should return False if doesn't contain 3" $ do solution 1 `shouldBe` False solution 264568 `shouldBe` False main = hspec spec
- module AreThereThreeSpec where
- import Test.Hspec
- import AreThereThree
- spec :: Spec
- spec = do
- describe "Tests" $ do
it "Fixed Tests" $ dosolution 525458 `shouldBe` Falsesolution 2222 `shouldBe` False- it "should return True if contains 3" $ do
- solution 354523 `shouldBe` True
- solution 35 `shouldBe` True
- it "should return False if doesn't contain 3" $ do
- solution 1 `shouldBe` False
- solution 264568 `shouldBe` False
- main = hspec spec
added another test case
module SumSpec (spec) where import Prelude hiding (sum) import qualified Prelude as Pre (sum) import Sum (sum) import Test.Hspec spec :: Spec spec = do it "works with a single Word" $ do Sum.sum [1] `shouldBe` Pre.sum [1] it "works with an Empty list" $ do Sum.sum [] `shouldBe` Pre.sum [] it "works with multiple Words" $ do Sum.sum [2, 3] `shouldBe` Pre.sum [2, 3]
- module SumSpec (spec) where
- import Prelude hiding (sum)
- import qualified Prelude as Pre (sum)
- import Sum (sum)
- import Test.Hspec
- spec :: Spec
- spec = do
it "tests" $ do- it "works with a single Word" $ do
- Sum.sum [1] `shouldBe` Pre.sum [1]
it "Empty list" $ doSum.sum [] `shouldBe` Pre.sum []- it "works with an Empty list" $ do
- Sum.sum [] `shouldBe` Pre.sum []
- it "works with multiple Words" $ do
- Sum.sum [2, 3] `shouldBe` Pre.sum [2, 3]