Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created July 22, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtchepak/62fe3c689700180777c2 to your computer and use it in GitHub Desktop.
Save dtchepak/62fe3c689700180777c2 to your computer and use it in GitHub Desktop.
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