Though diffable is applicable to general F# debugging, DiffBundle's structuralEquiv field can be used as a tool for unit testing. Below is an example of a test written for the NUnit unit testing framework, and which uses FsUnit as well.

[<TestFixture>]
type DiffableExample () =
    [<Test>]
    member test.orderIndependent () =
        let values0 = [1;3;2;5]
        let values1 = [2;5;1;3]

        let tree0 = List.fold insert EmptyBST values0
        let tree1 = List.fold insert EmptyBST values1

        let compare t0 t1 =
            if diffHelpers.structuralEquiv t0 t1 then
                true
            else
                let seq0 = List.scan insert EmptyBST values0
                viewDOTGraph (treeListDOTCode seq0)
                
                let seq1 = List.scan insert EmptyBST values1
                viewDOTGraph (treeListDOTCode seq1)

                false
        
        (compare tree0 tree1) |> should be (equal true)

Last edited Jun 2, 2011 at 7:35 PM by kevinclancy, version 3

Comments

No comments yet.