Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Imms/ExtraFunctional/ExtraFunctional/Option.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module Option =
let orValue (v : 'v) = function Some u -> u | None -> v
let orMaybe (v : 'v option) = function Some u -> Some u | None -> v
let asNull = Option.toObj
let asNull (v : 'v option) = if v.IsNone then null else v.Value
let cast<'a,'b> (opt : 'a option) : 'b option = opt |> Option.map (fun a -> a :> obj :?> 'b)

[<AutoOpen>]
Expand Down
4 changes: 0 additions & 4 deletions Imms/Imms.FSharp/Imms.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>..\..\..\packages\FSharp.Core.4.0.0.1\lib\net40\FSharp.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion Imms/Imms.Tests.Integrity/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="4.0.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
Expand Down
24 changes: 22 additions & 2 deletions Imms/Imms.Tests.Integrity/Imms.Tests.Integrity.fsproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -16,6 +17,8 @@
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -42,8 +45,12 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="FSharp.Core">
<HintPath>..\..\..\packages\FSharp.Core.4.0.0.1\lib\net40\FSharp.Core.dll</HintPath>
<Reference Include="FsCheck">
<HintPath>..\packages\FsCheck.2.6.0\lib\net45\FsCheck.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FsCheck.Xunit">
<HintPath>..\packages\FsCheck.Xunit.2.6.0\lib\net45\FsCheck.Xunit.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
Expand All @@ -54,6 +61,18 @@
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="xunit.abstractions">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core">
<HintPath>..\packages\xunit.extensibility.core.2.1.0\lib\portable-net45+win8+wp8+wpa81\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop">
<HintPath>..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Definitions.fs" />
Expand Down Expand Up @@ -112,6 +131,7 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
79 changes: 78 additions & 1 deletion Imms/Imms.Tests.Integrity/MapTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,90 @@ type MapTests<'e when 'e : comparison>(items : 'e array, ?seed : int) =
member x.Find iters = create_test iters "Find" (x.find iters >> toList1 >> List.cast)
member x.Gen_disjoint iters = create_test iters "GenDisjoint" (x.gen_equal_keys_dif_values iters >> toList1 >> List.cast)

open Xunit
open FsCheck
open FsCheck.Xunit

module MapTestsFsCheck =
type [<RequireQualifiedAccess>] MapAction<'k, 'v> =
| SetKey of 'k * 'v
| RemoveRandom

/// Keeps a reference to all persistent collections returned after
/// performing an action, and after they are all applied, checks
/// that they equal what we would get from FSharp.Core.Map
let inline eqMapsAfterSteps
(fsMap:Map<'k, 'v>)
(testMap:'m)
(actions: MapAction<'k, 'v>[])
(setKey: 'k->'v->'m->'m when 'k: comparison and 'v: comparison)
(removeKey: 'k->'m->'m when 'k: comparison and 'v: comparison)
(eqMap: 'm->Map<'k, 'v>->bool) =

let applyAction fsMap testMap action =
match action with
| MapAction.SetKey(k, v) ->
(Map.add k v fsMap, setKey k v testMap)
| MapAction.RemoveRandom when Map.isEmpty fsMap ->
(fsMap, testMap)
| MapAction.RemoveRandom ->
let idx = Gen.choose(0, fsMap.Count - 1).Sample(0, 1).Head
let ary = Map.toArray fsMap
let key = fst ary.[idx]
(Map.remove key fsMap, removeKey key testMap)

let (fsMaps, testMaps) =
Array.fold
(fun acc action ->
match acc with
| (fsMap::fsMaps, testMap::testMaps) ->
let (newF, newT) = applyAction fsMap testMap action
(newF::fsMap::fsMaps, newT::testMap::testMaps)
| _ -> failwith "Logic error")
([fsMap], [testMap])
actions

List.forall2
eqMap
testMaps
fsMaps


let immMap2FsMap (m:ImmMap<_,_>) =
Seq.fold
(fun acc (KeyValue(k,v)) -> Map.add k v acc)
(Map.empty)
(m.ToArray())

[<Property>]
let immMapsEqualFsMapsAfterSteps (startFsMap:Map<int, int>) (actions: MapAction<int, int>[]) =
let testMap = ImmMap.ToImmMap startFsMap
let eqMap (m:ImmMap<_,_>) (fsMap:Map<_,_>) =
immMap2FsMap m = fsMap

eqMapsAfterSteps
startFsMap
testMap
actions
(ImmMap.set)
(ImmMap.remove)
eqMap

let sortedMap2FsMap (m:ImmSortedMap<_,_>) =
Seq.fold
(fun acc (KeyValue(k,v)) -> Map.add k v acc)
(Map.empty)
(m.ToArray())

[<Property>]
let immSortedMapsEqualFsMapsAfterSteps (startFsMap:Map<int, int>) (actions: MapAction<int, int>[]) =
let testMap = ImmSortedMap.ToImmSortedMap startFsMap
let eqMap (m:ImmSortedMap<_,_>) (fsMap:Map<_,_>) =
sortedMap2FsMap m = fsMap

eqMapsAfterSteps
startFsMap
testMap
actions
(ImmSortedMap.set)
(ImmSortedMap.remove)
eqMap
6 changes: 6 additions & 0 deletions Imms/Imms.Tests.Integrity/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FsCheck" version="2.6.0" targetFramework="net451" />
<package id="FsCheck.Xunit" version="2.6.0" targetFramework="net451" />
<package id="FSharp.Core" version="4.0.0.1" targetFramework="net451" />
<package id="Microsoft.Bcl.Immutable" version="1.0.34" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net451" />
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net451" />
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net451" />
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net451" />
</packages>