Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ obj/
*.vspscc
*.vssscc
Ankh.NoLoad
*.userprefs

# NuGet
!.nuget/*
Expand Down Expand Up @@ -88,4 +89,4 @@ _ReSharper*/

# Ignore the NuGet build folder, it's only needed when building the package
_NuGetBuild/*
.idea/
.idea/
5 changes: 3 additions & 2 deletions ExtCore.Tests/Collections.HashMap.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,9 @@ module MapModule =

// reference keys
let refMap = HashMap.ofSeq [for c in ["."; ".."; "..."; "...."] do yield (c, c.Length) ]
let resultRefMap = HashMap.foldBack (fun x y z -> x + y.ToString() + z) refMap "right"
Assert.AreEqual(".1..2...3....4right", resultRefMap)
let resultRefMap = HashMap.foldBack (fun x y z -> (x,y) :: z) refMap [("initial",83)]
CollectionAssert.AreEquivalent([("initial",83);("....",4);("...",3);("..",2);(".",1)], resultRefMap)
Assert.AreEqual(("initial",83), resultRefMap |> Array.ofSeq |> Array.last)

// One-element HashMap
let oeleMap = HashMap.ofSeq [(1, "one")]
Expand Down
133 changes: 133 additions & 0 deletions ExtCore.Tests/Control.Result.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
(*

Copyright 2013 Jack Pappas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*)

namespace Tests.ExtCore.Control

open System
open System.Runtime.CompilerServices
open ExtCore.Control
open NUnit.Framework
//open FsCheck
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it?



/// Test fixture which tests that the .Using() member of AsyncResultBuilder
/// disposes the supplied resource at the correct point in the program's execution.
[<TestFixture; Sealed>]
type AsyncResultBuilderDisposeFixture() =
let disposed = StrongBox (false)

let createDisposable (disposed : StrongBox<bool>) =
{ new IDisposable with
member __.Dispose () =
printfn "disposing!"
disposed.Value <- true }

let createAsyncResultDisposable() =
async { return Ok(createDisposable disposed) }

let waitAsyncResult() =
asyncResult {
printfn "waiting"
}

let shouldNotBeDisposed() =
printfn "Should not be disposed. Checking..."
Assert.IsFalse(disposed.Value)

let createAsyncDisposable() = async { return (createDisposable disposed) }

let waitAsync() =
async {
printfn "waiting"
}

[<SetUp>]
member __.Setup () : unit =
disposed.Value <- false

[<TearDown>]
member __.Teardown () : unit =
printfn "Should be disposed. Checking..."
Assert.IsTrue(disposed.Value)

// asyncResult wrong behavior
[<Test>]
member __.UsingAsyncChoice() : unit =
asyncResult {
use! d = createAsyncResultDisposable()
shouldNotBeDisposed()
let! a = waitAsyncResult()
shouldNotBeDisposed()
}
|> Async.RunSynchronously
|> Result.get
|> ignore

// async - expected behavior
[<Test>]
member __.UsingAsync() : unit =
async {
use! d = createAsyncDisposable()
shouldNotBeDisposed()
do! waitAsync()
shouldNotBeDisposed()
}
|> Async.RunSynchronously
|> ignore

/// <summary>
/// Tests for <see cref="ExtCore.Control.ResultBuilder"/>.
/// </summary>
module ResultBuilder =
/// <summary>Tests for <see cref="ExtCore.Control.ResultBuilder.For"/>.</summary>
module ``ResultBuilder_For`` =
[<Test>]
let ``simple test`` () : unit =
let count = ref 0
let data = [| 1..3 |]
let result = result {
for i in data do
incr count
return true
}

// Check the loop iteration count is correct.
assertEqual 3 !count

// Check the result of the computation.
assertEqual (Ok true) result

/// <summary>Tests for <see cref="ExtCore.Control.ResultBuilder.While"/>.</summary>
module ``ResultBuilder_While`` =
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove <summary> tag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit extra, that's why?

[<Test>]
let ``simple test`` () : unit =
let count = ref 0
let data = [| 1..3 |]
let result = result {
while !count < 3 do
incr count
return true
}

// Check the loop iteration count is correct.
assertEqual 3 !count

// Check the result of the computation.
assertEqual (Ok true) result


109 changes: 109 additions & 0 deletions ExtCore.Tests/ControlCollections.ReaderResult.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
(*

Copyright 2013 Jack Pappas

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*)

/// Unit tests for the ExtCore.Control.Collections.ReaderChoice module.
module Tests.ExtCore.Control.Collections.ReaderResult

open ExtCore.Control
open ExtCore.Control.Collections
open NUnit.Framework
//open FsCheck


/// Tests for the ExtCore.Control.Collections.ReaderChoice.Array module.
module Array =
[<Test>]
let map () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let mapi () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let map2 () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let fold () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let foldi () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let init () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let iter () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let iteri () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let reduce () : unit =
Assert.Ignore "Test not yet implemented."


/// Tests for the ExtCore.Control.Collections.ReaderChoice.List module.
module List =
[<Test>]
let fold () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let map2 () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let mapi2 () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let iter2 () : unit =
Assert.Ignore "Test not yet implemented."


/// Tests for the ExtCore.Control.Collections.ReaderChoice.Seq module.
module Seq =
[<Test>]
let iter () : unit =
Assert.Ignore "Test not yet implemented."


/// Tests for the ExtCore.Control.Collections.ReaderChoice.Set module.
module Set =
[<Test>]
let fold () : unit =
Assert.Ignore "Test not yet implemented."

[<Test>]
let mapToArray () : unit =
Assert.Ignore "Test not yet implemented."


/// Tests for the ExtCore.Control.Collections.ReaderChoice.ArrayView module.
module ArrayView =
[<Test>]
let fold () : unit =
Assert.Ignore "Test not yet implemented."

Loading