9c9d859d9b9772d17141725da8373af6c913606f
[master-thesis.git] / Parasitemia / Tests / ParasitemiaCore.Tests / KdTree.fs
1 namespace ParasitemiaCore.Tests
2
3 open Xunit
4 open Xunit.Abstractions
5
6 open ParasitemiaCore.KdTree
7
8 type Point (x : float32, y : float32) =
9 interface I2DCoords with
10 member this.X = x
11 member this.Y = y
12
13 override this.ToString () =
14 sprintf "(%.1f, %.1f)" x y
15
16 type KdTreeTests (output : ITestOutputHelper) =
17
18 // TODO: test with identical X or Y coords
19 [<Fact>]
20 member this.test () =
21 let pts =
22 [
23 Point(1.0f, 1.0f)
24 Point(2.0f, 2.0f)
25 Point(1.5f, 3.6f)
26 Point(3.0f, 3.2f)
27 Point(4.0f, 4.0f)
28 Point(3.5f, 1.5f)
29 Point(2.5f, 0.5f)
30 ]
31
32 let tree = Tree.BuildTree pts
33 output.WriteLine (sprintf "Tree: %A" tree)
34
35 let s1 = tree.Search { minX = 0.0f; maxX = 5.0f; minY = 0.0f; maxY = 5.0f } // All points.
36 output.WriteLine (sprintf "s1: %A" s1)
37
38 let s2 = tree.Search { minX = 2.8f; maxX = 4.5f; minY = 3.0f; maxY = 4.5f }
39 output.WriteLine (sprintf "s2: %A" s2)
40
41 let s3 = tree.Search { minX = 2.0f; maxX = 2.0f; minY = 2.0f; maxY = 2.0f }
42 output.WriteLine (sprintf "s3: %A" s3)
43
44 [<Fact>]
45 member this.test2 () =
46 let pts =
47 [
48 Point(1.0f, 1.0f)
49 Point(1.0f, 2.0f)
50 Point(1.0f, 3.0f)
51 ]
52
53 let tree = Tree.BuildTree pts
54 output.WriteLine (sprintf "Tree: %A" tree)
55
56 let s1 = tree.Search { minX = 1.0f; maxX = 1.0f; minY = 1.0f; maxY = 1.0f }
57 output.WriteLine (sprintf "s1: %A" s1)
58
59 let s2 = tree.Search { minX = 1.0f; maxX = 1.0f; minY = 2.0f; maxY = 2.0f }
60 output.WriteLine (sprintf "s2: %A" s2)
61
62 // This case result is wrong: FIXME
63 let s3 = tree.Search { minX = 1.0f; maxX = 1.0f; minY = 3.0f; maxY = 3.0f }
64 output.WriteLine (sprintf "s3: %A" s3)
65
66 let s4 = tree.Search { minX = 0.0f; maxX = 2.0f; minY = 0.0f; maxY = 4.0f }
67 output.WriteLine (sprintf "s4: %A" s4)
68
69
70
71