1
exercism fetch fsharp pov

PovTest.fs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
module PovTest

open Xunit
open FsUnit.Xunit

open Pov

let x = "x"
let leaf v = mkGraph v []

let singleton = mkGraph x []
let flat = mkGraph "root" (List.map leaf ["a"; "b"; x; "c"])
let nested = mkGraph "level-0" [mkGraph "level-1" [mkGraph "level-2" [mkGraph "level-3" [mkGraph x []]]]]
let kids = mkGraph "root" [mkGraph x [mkGraph "kid-0" []; mkGraph "kid-1" []]]
let cousins = mkGraph "grandparent" [
                mkGraph "parent" [
                    mkGraph x [leaf "kid-a"; leaf "kid-b"]; 
                    (leaf "sibling-0"); 
                    (leaf "sibling-1")];
                    mkGraph "uncle" [
                        (leaf "cousin-0");
                        (leaf "cousin-1")]]

let singleton' = singleton
let flat' = mkGraph x [mkGraph "root" (List.map leaf ["a"; "b"; "c"])]
let nested' = mkGraph x [mkGraph "level-3" [mkGraph "level-2" [mkGraph "level-1" [mkGraph "level-0" []]]]]
let kids' = mkGraph x [mkGraph "kid-0" []; mkGraph "kid-1" []; mkGraph "root" []]
let cousins' = mkGraph x [
                leaf "kid-a";
                leaf "kid-b";
                mkGraph "parent" [
                    mkGraph "sibling-0" [];
                    mkGraph "sibling-1" [];
                    mkGraph "grandparent" [
                        mkGraph "uncle" [
                            mkGraph "cousin-0" [];
                            mkGraph "cousin-1" []]]]]

[<Fact>]
let ``Reparent singleton`` () =
    fromPOV x singleton |> should equal <| Some singleton'

[<Fact(Skip = "Remove to run test")>]
let ``Reparent flat`` () =
    fromPOV x flat |> should equal <| Some flat'

[<Fact(Skip = "Remove to run test")>]
let ``Reparent nested`` () =
    fromPOV x nested |> should equal <| Some nested'

[<Fact(Skip = "Remove to run test")>]
let ``Reparent kids`` () =
    fromPOV x kids |> should equal <| Some kids'

[<Fact(Skip = "Remove to run test")>]
let ``Reparent cousins`` () =
    fromPOV x cousins |> should equal <| Some cousins'

[<Fact(Skip = "Remove to run test")>]
let ``Reparent from POV of non-existent node`` () =
    fromPOV x (leaf "foo") |> should equal None

[<Fact(Skip = "Remove to run test")>]
let ``Should not be able to find a missing node`` () =
    let nodes = [singleton; flat; kids; nested; cousins] |> List.map (fromPOV "NOT THERE")
    nodes |> List.iter (should equal None)

[<Fact(Skip = "Remove to run test")>]
let ``Cannot trace between un-connected nodes`` () =
    tracePathBetween x "NOT THERE" cousins |> should equal None

[<Fact(Skip = "Remove to run test")>]
let ``Can trace a path from x to cousin`` () = 
    tracePathBetween x "cousin-1" cousins |> should equal <| Some ["x"; "parent"; "grandparent"; "uncle"; "cousin-1"]

[<Fact(Skip = "Remove to run test")>]
let ``Can trace from a leaf to a leaf`` () =
    tracePathBetween "kid-a" "cousin-0" cousins |> should equal <| Some ["kid-a"; "x"; "parent"; "grandparent"; "uncle"; "cousin-0"]