go-hep.org/x/hep@v0.38.1/fastjet/internal/predicates/orientation_test.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package predicates 6 7 import ( 8 "testing" 9 ) 10 11 func TestOrientation(t *testing.T) { 12 tests := []struct { 13 x1, y1, x2, y2, x, y float64 14 want OrientationKind 15 }{ 16 {1, 1, 1, 5, 1, 3, Colinear}, 17 {2, 2, 10, 2, 7, 2, Colinear}, 18 {2, 2, 4, 4, 3, 3, Colinear}, 19 {1, 1, 1, 5, 0, 3, CCW}, 20 {1, 1, 1, 5, 2, 3, CW}, 21 {2, 2, 10, 2, 7, 2.001, CCW}, 22 {2, 2, 10, 2, 7, 1.999, CW}, 23 {2, 2, 5, 3, 3, 2.334, CCW}, 24 {2, 2, 5, 3, 3, 2.333, CW}, 25 {0, 11, 4, 10, 7, 9.251, CCW}, 26 {0, 11, 4, 10, 7, 9.249, CW}, 27 } 28 for _, test := range tests { 29 got := Orientation(test.x1, test.y1, test.x2, test.y2, test.x, test.y) 30 if got != test.want { 31 t.Fatalf("Orientation(%v,%v,%v,%v,%v,%v) = %v, want = %v", test.x1, test.y1, test.x2, test.y2, test.x, test.y, got, test.want) 32 } 33 } 34 } 35 36 func TestSimpleVsRobustOrientation(t *testing.T) { 37 tests := []struct { 38 x1, y1, x2, y2, x, y float64 39 simple OrientationKind 40 robust OrientationKind 41 }{ 42 {2.1, 2.1, 1.1, 1.1, 0.1, 0.1, IndeterminateOrientation, Colinear}, 43 {2.1, 2.1, 1.1, 1.1, 100.1, 100.1, IndeterminateOrientation, Colinear}, 44 {2.1, 2.1, 1.1, 1.1, 1000.1, 1000.1, IndeterminateOrientation, Colinear}, 45 {0.5, 0.5, 12, 12, 24, 24, IndeterminateOrientation, Colinear}, 46 {1000, 2000, 2000, 3000, 10000, 11000, IndeterminateOrientation, Colinear}, 47 } 48 for _, test := range tests { 49 o := simpleOrientation(test.x1, test.y1, test.x2, test.y2, test.x, test.y) 50 if o != test.simple { 51 t.Errorf("x1 = %v, y1 = %v, x2 = %v, y2 = %v, x = %v, y = %v, want.Simple = %v. got= %v\n", test.x1, test.y1, test.x2, test.y2, test.x, test.y, test.simple, o) 52 } 53 o = robustOrientation(setBig(test.x1), setBig(test.y1), setBig(test.x2), setBig(test.y2), setBig(test.x), setBig(test.y)) 54 if o != test.robust { 55 t.Errorf("x1 = %v, y1 = %v, x2 = %v, y2 = %v, x = %v, y = %v, want.Robust = %v. got= %v\n", test.x1, test.y1, test.x2, test.y2, test.x, test.y, test.robust, o) 56 } 57 o = matOrientation(test.x1, test.y1, test.x2, test.y2, test.x, test.y) 58 if o != test.robust { 59 t.Errorf("x1 = %v, y1 = %v, x2 = %v, y2 = %v, x = %v, y = %v, want.Mat = %v. got= %v\n", test.x1, test.y1, test.x2, test.y2, test.x, test.y, test.robust, o) 60 } 61 } 62 } 63 64 func BenchmarkSimpleOrientation(b *testing.B) { 65 tests := []struct { 66 x1, y1, x2, y2, x, y float64 67 }{ 68 {1, 1, 1, 5, 1, 3}, 69 {2, 2, 10, 2, 7, 2}, 70 {2, 2, 4, 4, 3, 3}, 71 {1, 1, 1, 5, 0, 3}, 72 {1, 1, 1, 5, 2, 3}, 73 {2, 2, 10, 2, 7, 2.001}, 74 {2, 2, 10, 2, 7, 1.999}, 75 {2, 2, 5, 3, 3, 2.334}, 76 {2, 2, 5, 3, 3, 2.333}, 77 {0, 11, 4, 10, 7, 9.251}, 78 {0, 11, 4, 10, 7, 9.249}, 79 } 80 b.ResetTimer() 81 for i := 0; i < b.N; i++ { 82 for _, test := range tests { 83 simpleOrientation(test.x1, test.y1, test.x2, test.y2, test.x, test.y) 84 } 85 } 86 } 87 88 func BenchmarkMatOrientation(b *testing.B) { 89 tests := []struct { 90 x1, y1, x2, y2, x, y float64 91 }{ 92 {1, 1, 1, 5, 1, 3}, 93 {2, 2, 10, 2, 7, 2}, 94 {2, 2, 4, 4, 3, 3}, 95 {1, 1, 1, 5, 0, 3}, 96 {1, 1, 1, 5, 2, 3}, 97 {2, 2, 10, 2, 7, 2.001}, 98 {2, 2, 10, 2, 7, 1.999}, 99 {2, 2, 5, 3, 3, 2.334}, 100 {2, 2, 5, 3, 3, 2.333}, 101 {0, 11, 4, 10, 7, 9.251}, 102 {0, 11, 4, 10, 7, 9.249}, 103 } 104 b.ResetTimer() 105 for i := 0; i < b.N; i++ { 106 for _, test := range tests { 107 matOrientation(test.x1, test.y1, test.x2, test.y2, test.x, test.y) 108 } 109 } 110 } 111 112 func BenchmarkRobustOrientation(b *testing.B) { 113 tests := []struct { 114 x1, y1, x2, y2, x, y float64 115 }{ 116 {1, 1, 1, 5, 1, 3}, 117 {2, 2, 10, 2, 7, 2}, 118 {2, 2, 4, 4, 3, 3}, 119 {1, 1, 1, 5, 0, 3}, 120 {1, 1, 1, 5, 2, 3}, 121 {2, 2, 10, 2, 7, 2.001}, 122 {2, 2, 10, 2, 7, 1.999}, 123 {2, 2, 5, 3, 3, 2.334}, 124 {2, 2, 5, 3, 3, 2.333}, 125 {0, 11, 4, 10, 7, 9.251}, 126 {0, 11, 4, 10, 7, 9.249}, 127 } 128 b.ResetTimer() 129 for i := 0; i < b.N; i++ { 130 for _, test := range tests { 131 robustOrientation(setBig(test.x1), setBig(test.y1), setBig(test.x2), setBig(test.y2), setBig(test.x), setBig(test.y)) 132 } 133 } 134 }