Skip to content

Instantly share code, notes, and snippets.

@dtchepak dtchepak/Sample.fs
Created Jul 22, 2014

Embed
What would you like to do?
module DaveSquared.Sample
open Xunit
let incr x = x+1
// Test using Unquote
open Swensen.Unquote
[<Fact>]
let ``map (+1) over list using Unquote`` () =
test <@ List.map incr [1;2;3] = [2;3;4] @>
// Test using Xunit assertions (or use FsUnit.Xunit for more F#y syntax)
open Xunit
[<Fact>]
let ``map (+1) over list using Xunit`` () =
let result = List.map incr [1;2;3]
Assert.Equal<int list>([2;3;4], result)
// Test using FsUnit.Xunit assertions
open FsUnit.Xunit
[<Fact>]
let ``map (+1) over list using FsUnit.Xunit`` () =
let result = List.map incr [1;2;3]
result |> should equal [2;3;4]
// Test properties
open FsCheck
open FsCheck.Xunit
[<Property>]
let ``map f . map g = map (f . g)`` (xs:int list) =
let f x = x*10
let g x = x+1
(List.map f << List.map g) xs = List.map (f << g) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.