Sha256: db9fb9f5de25e5f5412c28ad7e4a952221994bb7a7c10b5b76d3afbfbc40dbe9

Contents?: true

Size: 1.58 KB

Versions: 229

Compression:

Stored size: 1.58 KB

Contents

{-# OPTIONS_GHC -fno-warn-type-defaults #-}

import Data.Foldable     (for_)
import Test.Hspec        (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import Triplet (isPythagorean, mkTriplet, pythagoreanTriplets)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = do
          describe "isPythagorean"       $ for_ isPythagoreanCases       isPythagoreanTest
          describe "pythagoreanTriplets" $ for_ pythagoreanTripletsCases pythagoreanTripletsTest
  where

    isPythagoreanTest ((a, b, c), expected) = it description assertion
      where
        description = unwords $ show <$> [a, b, c]
        assertion   = isPythagorean (mkTriplet a b c) `shouldBe` expected

    pythagoreanTripletsTest (x, y, ts) = it description assertion
      where
        description = unwords $ show <$> [x, y]
        assertion   = pythagoreanTriplets x y `shouldBe` uncurry3 mkTriplet <$> ts

    uncurry3 f (x, y, z) = f x y z

    isPythagoreanCases = [ ( (3, 4, 5), True )
                         , ( (3, 5, 4), True )
                         , ( (4, 3, 5), True )
                         , ( (4, 5, 3), True )
                         , ( (5, 3, 4), True )
                         , ( (5, 4, 3), True )
                         , ( (3, 3, 3), False)
                         , ( (5, 6, 7), False) ]

    pythagoreanTripletsCases = [ (1 , 10, [ ( 3,  4,  5), ( 6,  8, 10) ])
                               , (11, 20, [ (12, 16, 20)               ])
                               , (56, 95, [ (57, 76, 95), (60, 63, 87) ]) ]

Version data entries

229 entries across 229 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.158 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.157 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.156 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.155 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.154 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.153 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.152 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.151 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.150 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.149 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.148 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.147 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.146 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.145 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.144 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.143 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.142 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.141 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs
trackler-2.2.1.140 tracks/haskell/exercises/pythagorean-triplet/test/Tests.hs