Sha256: cb083eb5eab0db5ce2639eb5f9787724e2a08b66fd7fa9d75eea3719e72ea6f9

Contents?: true

Size: 1.92 KB

Versions: 141

Compression:

Stored size: 1.92 KB

Contents

module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Data.Maybe (Maybe(..))
import Test.Unit.Assert as Assert
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)
import BinarySearch (find)

main :: forall eff
  . Eff ( avar :: AVAR
        , console :: CONSOLE
        , testOutput :: TESTOUTPUT
        | eff                     
        )
        Unit
main = runTest suites

suites :: forall e. TestSuite e
suites = do
  suite "BinarySearch.find" do

    test "finds a value in an array with one element" $
      Assert.equal (Just 0)
                   (find 6 [6])

    test "finds a value in the middle of an array" $
      Assert.equal (Just 3)
                   (find 6 [1,3,4,6,8,9,11])

    test "finds a value at the beginning of an array" $
      Assert.equal (Just 0)
                   (find 1 [1,3,4,6,8,9,11])

    test "finds a value at the end of an array" $
      Assert.equal (Just 6)
                   (find 11 [1,3,4,6,8,9,11])

    test "finds a value in an array of odd length" $
      Assert.equal (Just 9)
                   (find 144 [1,3,5,8,13,21,34,55,89,144,233,377,634])

    test "finds a value in an array of even length" $
      Assert.equal (Just 5)
                   (find 21 [1,3,5,8,13,21,34,55,89,144,233,377])

    test "identifies that a value is not included in the array" $
      Assert.equal Nothing
                   (find 7 [1,3,4,6,8,9,11])

    test "a value smaller than the array's smallest value is not included" $
      Assert.equal Nothing
                   (find 0 [1,3,4,6,8,9,11])

    test "a value larger than the array's largest value is not included" $
      Assert.equal Nothing
                   (find 13 [1,3,4,6,8,9,11])

    test "nothing is included in an empty array" $
      Assert.equal Nothing
                   (find 1 [])

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.179 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.178 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.177 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.176 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.175 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.174 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.173 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.172 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.171 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.170 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.169 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.167 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.166 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.165 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.164 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.163 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.162 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.161 tracks/purescript/exercises/binary-search/test/Main.purs
trackler-2.2.1.160 tracks/purescript/exercises/binary-search/test/Main.purs