Skip to content

Instantly share code, notes, and snippets.

@ryan-senn
Created July 6, 2017 01:09
Show Gist options
  • Save ryan-senn/9bd84cc4479a14556a186b3169f43566 to your computer and use it in GitHub Desktop.
Save ryan-senn/9bd84cc4479a14556a186b3169f43566 to your computer and use it in GitHub Desktop.
array tests
module Helpers.ArrayTest exposing (suite)
import Test exposing (..)
import Expect exposing (Expectation)
import Array exposing (Array)
import Helpers.Array
suite : Test
suite =
describe "Array Helper Tests"
[ describe "getIndex"
[ test "It finds the first index" <|
\_ -> getFirstIndex testArray
, test "It finds the last index" <|
\_ -> getLastIndex testArray
, test "It finds the third index" <|
\_ -> getThirdIndex testArray
, test "It fails if missing" <|
\_ -> missingIndex testArray
, test "It fails if not unique" <|
\_ -> notUnique testArray
]
, describe "removeAt"
[ test "It removes the first index" <|
\_ -> removeFirstIndex testArray
]
]
testArray : Array String
testArray =
Array.fromList
[ "entry1"
, "entry2"
, "entry3"
, "entry4"
, "entry5"
, "entry6"
, "entry7"
, "entry8"
]
-- getIndex
getFirstIndex : Array String -> Expectation
getFirstIndex array =
Helpers.Array.getIndex "entry1" array
|> Expect.equal (Ok 0)
getLastIndex : Array String -> Expectation
getLastIndex array =
Helpers.Array.getIndex "entry8" array
|> Expect.equal (Ok 7)
getThirdIndex : Array String -> Expectation
getThirdIndex array =
Helpers.Array.getIndex "entry4" array
|> Expect.equal (Ok 3)
missingIndex : Array String -> Expectation
missingIndex array =
Helpers.Array.getIndex "entry9" array
|> Expect.equal (Err Helpers.Array.NotFound)
notUnique : Array String -> Expectation
notUnique array =
let
notUniqueArray =
["entry4"]
|> Array.fromList
|> Array.append array
in
Helpers.Array.getIndex "entry4" notUniqueArray
|> Expect.equal (Err Helpers.Array.NotUnique)
-- removeAt
removeFirstIndex : Array String -> Expectation
removeFirstIndex array =
let
expectedArray =
Array.fromList
[ "entry2"
, "entry3"
, "entry4"
, "entry5"
, "entry6"
, "entry7"
, "entry8"
]
in
Helpers.Array.removeAt 0 array
|> Expect.equal expectedArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment