Skip to content

WIP: Add tests for flat-list module #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1d13c8b
flat list - first set of missing array APIs
rokklobster May 19, 2021
f2b637d
flat list - fix mapFold(+Back) and for loops
rokklobster May 19, 2021
f68ab1c
flat list - add unzip
rokklobster May 19, 2021
96466f7
flat list - find index, unfold, remove excessions
rokklobster May 19, 2021
6ce003b
flat list - another changes pack
rokklobster May 19, 2021
515f913
flat list - exactlyOne + try
rokklobster May 19, 2021
82dbf1d
flat-list - post-review fixes for first half
rokklobster May 20, 2021
b5dc6df
flat list - fix sorting (and helpers)
rokklobster May 20, 2021
3b9c912
general: vscode build task, move common funcs
rokklobster May 20, 2021
3cc77b1
flat list - remove sortInPlace*
rokklobster May 20, 2021
b200e5c
flat list - all APIs ported
rokklobster May 20, 2021
bbf1366
flat list - post-review fixes
rokklobster May 20, 2021
0ee37d5
flat list - update signatures: force main arg as FlatList
rokklobster May 20, 2021
697c5f8
flat-list - changes
rokklobster May 21, 2021
8af69b9
flat list - fix minor issues
rokklobster May 21, 2021
452bfb9
flat list - final post-review changes
rokklobster May 21, 2021
119b224
flat list tests - first pack
rokklobster May 24, 2021
49414df
flat list tests - fix invocation
rokklobster May 24, 2021
c020a36
add compiled name annotations
rokklobster Jun 8, 2021
c0d8313
fixes upon review
rokklobster Jun 22, 2021
b4f11a1
Merge branch 'feature/collection-methods' into feature/tests/flat-list
rokklobster Jun 22, 2021
64bd4ea
tests pack
rokklobster Jun 22, 2021
7be62fe
fix tests (remove dependency on same instance of lists), tests for se…
rokklobster Jun 28, 2021
d232b99
more tests
rokklobster Jul 12, 2021
3f80dad
more tests
rokklobster Jul 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
flat list tests - first pack
  • Loading branch information
rokklobster committed May 24, 2021
commit 119b2245e666da6be9293b44c4725d22e2f5c234
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Fuchu" Version="1.1.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="flat-list-tests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\FSharp.Collections.Immutable\FSharp.Collections.Immutable.fsproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions FSharp.Collections.Immutable.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
open Fuchu

module Program =
let [<EntryPoint>] main = defaultMainThisAssembly

88 changes: 88 additions & 0 deletions FSharp.Collections.Immutable.Tests/flat-list-tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module FSharp.Collections.Immutable.Tests

open NUnit.Framework
open Fuchu
open FSharp.Collections.Immutable

let nullList<'a> = new FlatList<'a>()
let emptyList<'a> = FlatList<'a>.Empty
let list0to9 = FlatList.init 10 id
let noopPredicate _ = true
let ignore2 _ _ = ()
let ignore3 _ _ _ = ()

let throwsOn item func =
fun () ->
Assert.Catch (fun () -> func item)
|> ignore

let doesNotThrowOn item func = fun () -> Assert.DoesNotThrow (fun () -> func item)

let throwsOnlyOnNullLists func = [
testCase "throws on null list" ((func >> ignore) |> throwsOn nullList<int>)
testCase "does not throw on empty list" ((func >> ignore) |> doesNotThrowOn emptyList<int>)
testCase "does not throw on non-empty list" ((func >> ignore) |> doesNotThrowOn list0to9)
]

let doesNotThrowOnlyOnFilledList func = [
testCase "throws on null list" ((func >> ignore) |> throwsOn nullList<int>)
testCase "throws on empty list" ((func >> ignore) |> throwsOn emptyList<int>)
testCase "does not throw on non-empty list" ((func >> ignore) |> doesNotThrowOn list0to9)
]

[<Tests>]
let flatListTests =
testList "FlatList" [
testList "toArray" (FlatList.toArray |> throwsOnlyOnNullLists)
testList "toList" (FlatList.toList |> throwsOnlyOnNullLists)
testList "toSeq" (FlatList.toSeq |> throwsOnlyOnNullLists)
testList "length" (FlatList.length |> throwsOnlyOnNullLists)
testList "append (first arg)" ((fun a -> FlatList.append a emptyList<int> |> ignore) |> throwsOnlyOnNullLists)
testList "append (second arg)" ((FlatList.append emptyList<int>) |> throwsOnlyOnNullLists)
testList "indexFromWith" ((FlatList.indexFromWith LanguagePrimitives.FastGenericEqualityComparer 0 1) |> throwsOnlyOnNullLists)
testList "indexFrom" ((FlatList.indexFrom 0 1) |> throwsOnlyOnNullLists)
testList "indexWith" ((FlatList.indexWith LanguagePrimitives.FastGenericEqualityComparer 1) |> throwsOnlyOnNullLists)
testList "index" ((FlatList.index 1) |> throwsOnlyOnNullLists)
testList "removeAllWith" ((FlatList.removeAllWith LanguagePrimitives.FastGenericEqualityComparer emptyList) |> throwsOnlyOnNullLists)
testList "removeAll" ((FlatList.removeAll emptyList) |> throwsOnlyOnNullLists)
testList "filter" ((FlatList.filter noopPredicate) |> throwsOnlyOnNullLists)
testList "where" ((FlatList.where noopPredicate) |> throwsOnlyOnNullLists)
testList "sortWithComparer" ((FlatList.sortWithComparer LanguagePrimitives.FastGenericComparer) |> throwsOnlyOnNullLists)
testList "sortWith" ((FlatList.sortWith LanguagePrimitives.GenericComparison) |> throwsOnlyOnNullLists)
testList "sort" (FlatList.sort |> throwsOnlyOnNullLists)
testList "map" (FlatList.map noopPredicate |> throwsOnlyOnNullLists)
testList "countBy" (FlatList.countBy noopPredicate |> throwsOnlyOnNullLists)
testList "indexed" (FlatList.indexed |> throwsOnlyOnNullLists)
testList "iter" (FlatList.iter ignore |> throwsOnlyOnNullLists)
testList "iter2 (first arg)" ((fun a -> FlatList.iter2 ignore2 a emptyList) |> throwsOnlyOnNullLists)
testList "iter2 (second arg)" ((FlatList.iter2 ignore2 emptyList) |> throwsOnlyOnNullLists)
testList "distinct" (FlatList.distinct |> throwsOnlyOnNullLists)
testList "distinctBy" (FlatList.distinctBy noopPredicate |> throwsOnlyOnNullLists)
testList "map2 (first arg)" ((fun a -> FlatList.map2 ignore2 a emptyList) |> throwsOnlyOnNullLists)
testList "map2 (second arg)" ((FlatList.map2 ignore2 emptyList) |> throwsOnlyOnNullLists)
testList "map3 (first arg)" ((fun a -> FlatList.map3 ignore3 a emptyList emptyList) |> throwsOnlyOnNullLists)
testList "map3 (second arg)" ((fun a -> FlatList.map3 ignore3 a emptyList emptyList) |> throwsOnlyOnNullLists)
testList "map3 (third arg)" ((FlatList.map3 ignore3 emptyList emptyList) |> throwsOnlyOnNullLists)
testList "mapi2 (first arg)" ((fun a -> FlatList.mapi2 ignore3 a emptyList) |> throwsOnlyOnNullLists)
testList "mapi2 (second arg)" ((FlatList.mapi2 ignore3 emptyList) |> throwsOnlyOnNullLists)
testList "iteri" ((FlatList.iteri ignore2) |> throwsOnlyOnNullLists)
testList "iteri2 (first arg)" ((fun a -> FlatList.iteri2 ignore3 a emptyList) |> throwsOnlyOnNullLists)
testList "iteri2 (second arg)" ((FlatList.iteri2 ignore3 emptyList) |> throwsOnlyOnNullLists)
testList "mapi" ((FlatList.mapi ignore2) |> throwsOnlyOnNullLists)

testList "item" ((FlatList.item 0) |> doesNotThrowOnlyOnFilledList)
testList "indexRangeWith" ((FlatList.indexRangeWith LanguagePrimitives.FastGenericEqualityComparer 0 1 1) |> doesNotThrowOnlyOnFilledList)
testList "indexRange" ((FlatList.indexRange 0 1 1) |> doesNotThrowOnlyOnFilledList)
testList "lastIndexRangeWith" ((FlatList.lastIndexRangeWith LanguagePrimitives.FastGenericEqualityComparer 0 1 1) |> doesNotThrowOnlyOnFilledList)
testList "lastIndexRange" ((FlatList.lastIndexRange 0 1 1) |> doesNotThrowOnlyOnFilledList)
testList "lastIndexFromWith" ((FlatList.lastIndexFromWith LanguagePrimitives.FastGenericEqualityComparer 0 1) |> doesNotThrowOnlyOnFilledList)
testList "lastIndexFrom" ((FlatList.lastIndexFrom 0 1) |> doesNotThrowOnlyOnFilledList)
testList "lastIndexWith" ((FlatList.lastIndexWith LanguagePrimitives.FastGenericEqualityComparer 1) |> doesNotThrowOnlyOnFilledList)
testList "lastIndex" ((FlatList.lastIndex 1) |> doesNotThrowOnlyOnFilledList)
testList "removeRange" ((FlatList.removeRange 0 1) |> doesNotThrowOnlyOnFilledList)
testList "blit" ((fun a -> FlatList.blit a 0 [|10;11;12|] 0 1) |> doesNotThrowOnlyOnFilledList)
testList "sortRangeWithComparer" ((FlatList.sortRangeWithComparer LanguagePrimitives.FastGenericComparer 0 1) |> doesNotThrowOnlyOnFilledList)
testList "sortRangeWith" ((FlatList.sortRangeWith LanguagePrimitives.GenericComparison 0 1) |> doesNotThrowOnlyOnFilledList)
testList "sortRange" ((FlatList.sortRange 0 1) |> doesNotThrowOnlyOnFilledList)

]
6 changes: 6 additions & 0 deletions FSharp.Collections.Immutable.sln
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.github\workflows\publish_release.yml = .github\workflows\publish_release.yml
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Collections.Immutable.Tests", "FSharp.Collections.Immutable.Tests\FSharp.Collections.Immutable.Tests.fsproj", "{2272CACE-DBCE-4BC8-BADD-11802BAF30EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
{9805E74C-D028-4D05-9256-5C2FDC9B6EA8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9805E74C-D028-4D05-9256-5C2FDC9B6EA8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9805E74C-D028-4D05-9256-5C2FDC9B6EA8}.Release|Any CPU.Build.0 = Release|Any CPU
{2272CACE-DBCE-4BC8-BADD-11802BAF30EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2272CACE-DBCE-4BC8-BADD-11802BAF30EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2272CACE-DBCE-4BC8-BADD-11802BAF30EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2272CACE-DBCE-4BC8-BADD-11802BAF30EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
2 changes: 1 addition & 1 deletion src/FSharp.Collections.Immutable/flat-list.fs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ module FlatList =
let inline ofArray (source : _ array) = FlatListFactory.CreateRange source
let inline ofList (source: _ list) = FlatListFactory.CreateRange source

let inline toSeq (flatList: FlatList<_>) = flatList :> seq<_>
let inline toSeq (flatList: FlatList<_>) = check flatList; flatList :> seq<_>
let inline toArray (list : FlatList<_>) = check list; Seq.toArray list
let inline toList list = check list; Seq.toList list

6 changes: 3 additions & 3 deletions src/FSharp.Collections.Immutable/functional-utils.fs
Original file line number Diff line number Diff line change
@@ -5,13 +5,13 @@ namespace FSharp.Collections.Immutable
#endif

[<AutoOpen>]
module internal FunctionalUtils =
module FunctionalUtils =
let inline flip f a b = f b a
let inline uncurry f (a, b) = f a b

let inline applyOverFuncs f g h x = f (g x) (h x)
let inline applyOverArgs f g x y = f (g x) (g y)

let inline fst3 (a, _, _) = a
let inline snd3 (_, a, _) = a
let inline thd3 (_, _, a) = a
let inline thd3 (_, _, a) = a