Skip to content

Commit

Permalink
add resizearray tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DoganCK committed Nov 4, 2023
1 parent 066c414 commit 8eae9a9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/FSharpAux.Tests/FSharpAux.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<Compile Include="SeqTests.fs" />
<Compile Include="ArrayTests.fs" />
<Compile Include="ResizeArrayTests.fs" />
<Compile Include="Array2DTests.fs" />
<Compile Include="JaggedArrayTest.fs" />
<Compile Include="ListTests.fs" />
Expand Down
1 change: 1 addition & 0 deletions tests/FSharpAux.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let all =
[
SeqTests.seqTests
ArrayTests.arrayTests
ResizeArrayTests.resizeArrayTests
Array2DTests.array2dTests
JaggedArrayTest.main
ListTests.listTests
Expand Down
35 changes: 35 additions & 0 deletions tests/FSharpAux.Tests/ResizeArrayTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module ResizeArrayTests

open FSharpAux
open Expecto

let private emptyArray : ResizeArray<int> = ResizeArray()
let private intArray = [6; 5; 2; 3; 2; 8] |> ResizeArray.ofList

let resizeArrayTests =
testList "ResizeArrayTests" [
testList "ResizeArray.sum" [
testCase "Empty array sum is 0" (fun _ ->
Expect.equal (ResizeArray.sum emptyArray) 0 "ResizeArray.sum of empty array is not 0."
)
testCase "returns correct sum" (fun _ ->
Expect.equal (ResizeArray.sum intArray) 26 "ResizeArray.sum calculates incorrectly"
)
]
testList "ResizeArray.sumBy" [
testCase "Empty array sumBy is 0" (fun _ ->
Expect.equal (emptyArray |> ResizeArray.sumBy (fun x -> x * 2)) 0 "ResizeArray.sumBy of empty array is not 0."
)
testCase "returns correct sum" (fun _ ->
Expect.equal (intArray |> ResizeArray.sumBy (fun x -> x * 2)) 52 "ResizeArray.sumBy calculates incorrectly"
)
]
testList "ResizeArray.countIf" [
testCase "Empty array count is 0" (fun _ ->
Expect.equal (emptyArray |> ResizeArray.countIf (fun x -> x % 2 = 0)) 0 "ResizeArray.countIf of empty array is not 0."
)
testCase "returns correct count" (fun _ ->
Expect.equal (intArray |> ResizeArray.countIf (fun x -> x % 2 = 0)) 4 "ResizeArray.countIf calculates incorrectly"
)
]
]

0 comments on commit 8eae9a9

Please sign in to comment.