go-hep.org/x/hep@v0.38.1/groot/rtree/rfunc/rfunc_bool_gen_test.go (about) 1 // Copyright ©2020 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 // Automatically generated. DO NOT EDIT. 6 7 package rfunc 8 9 import ( 10 "reflect" 11 "testing" 12 ) 13 14 func TestFuncToBool(t *testing.T) { 15 16 var rvars []string 17 18 fct := func() bool { 19 return true 20 } 21 22 form := NewFuncToBool(rvars, fct) 23 24 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 25 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 26 } 27 28 var ptrs []any 29 30 { 31 bad := make([]any, 1) 32 err := form.Bind(bad) 33 if err == nil { 34 t.Fatalf("expected an error for invalid args length") 35 } 36 } 37 38 err := form.Bind(ptrs) 39 if err != nil { 40 t.Fatalf("could not bind formula: %+v", err) 41 } 42 43 got := form.Func().(func() bool)() 44 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 45 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 46 } 47 } 48 49 func TestFuncF32ToBool(t *testing.T) { 50 51 rvars := make([]string, 1) 52 rvars[0] = "name-0" 53 54 fct := func(arg00 float32) bool { 55 return true 56 } 57 58 form := NewFuncF32ToBool(rvars, fct) 59 60 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 61 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 62 } 63 64 ptrs := make([]any, 1) 65 ptrs[0] = new(float32) 66 67 { 68 bad := make([]any, len(ptrs)) 69 copy(bad, ptrs) 70 for i := len(ptrs) - 1; i >= 0; i-- { 71 bad[i] = any(nil) 72 err := form.Bind(bad) 73 if err == nil { 74 t.Fatalf("expected an error for empty iface") 75 } 76 } 77 bad = append(bad, any(nil)) 78 err := form.Bind(bad) 79 if err == nil { 80 t.Fatalf("expected an error for invalid args length") 81 } 82 } 83 84 err := form.Bind(ptrs) 85 if err != nil { 86 t.Fatalf("could not bind formula: %+v", err) 87 } 88 89 got := form.Func().(func() bool)() 90 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 91 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 92 } 93 } 94 95 func TestFuncF32F32ToBool(t *testing.T) { 96 97 rvars := make([]string, 2) 98 rvars[0] = "name-0" 99 rvars[1] = "name-1" 100 101 fct := func(arg00 float32, arg01 float32) bool { 102 return true 103 } 104 105 form := NewFuncF32F32ToBool(rvars, fct) 106 107 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 108 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 109 } 110 111 ptrs := make([]any, 2) 112 ptrs[0] = new(float32) 113 ptrs[1] = new(float32) 114 115 { 116 bad := make([]any, len(ptrs)) 117 copy(bad, ptrs) 118 for i := len(ptrs) - 1; i >= 0; i-- { 119 bad[i] = any(nil) 120 err := form.Bind(bad) 121 if err == nil { 122 t.Fatalf("expected an error for empty iface") 123 } 124 } 125 bad = append(bad, any(nil)) 126 err := form.Bind(bad) 127 if err == nil { 128 t.Fatalf("expected an error for invalid args length") 129 } 130 } 131 132 err := form.Bind(ptrs) 133 if err != nil { 134 t.Fatalf("could not bind formula: %+v", err) 135 } 136 137 got := form.Func().(func() bool)() 138 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 139 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 140 } 141 } 142 143 func TestFuncF32F32F32ToBool(t *testing.T) { 144 145 rvars := make([]string, 3) 146 rvars[0] = "name-0" 147 rvars[1] = "name-1" 148 rvars[2] = "name-2" 149 150 fct := func(arg00 float32, arg01 float32, arg02 float32) bool { 151 return true 152 } 153 154 form := NewFuncF32F32F32ToBool(rvars, fct) 155 156 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 157 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 158 } 159 160 ptrs := make([]any, 3) 161 ptrs[0] = new(float32) 162 ptrs[1] = new(float32) 163 ptrs[2] = new(float32) 164 165 { 166 bad := make([]any, len(ptrs)) 167 copy(bad, ptrs) 168 for i := len(ptrs) - 1; i >= 0; i-- { 169 bad[i] = any(nil) 170 err := form.Bind(bad) 171 if err == nil { 172 t.Fatalf("expected an error for empty iface") 173 } 174 } 175 bad = append(bad, any(nil)) 176 err := form.Bind(bad) 177 if err == nil { 178 t.Fatalf("expected an error for invalid args length") 179 } 180 } 181 182 err := form.Bind(ptrs) 183 if err != nil { 184 t.Fatalf("could not bind formula: %+v", err) 185 } 186 187 got := form.Func().(func() bool)() 188 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 189 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 190 } 191 } 192 193 func TestFuncF64ToBool(t *testing.T) { 194 195 rvars := make([]string, 1) 196 rvars[0] = "name-0" 197 198 fct := func(arg00 float64) bool { 199 return true 200 } 201 202 form := NewFuncF64ToBool(rvars, fct) 203 204 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 205 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 206 } 207 208 ptrs := make([]any, 1) 209 ptrs[0] = new(float64) 210 211 { 212 bad := make([]any, len(ptrs)) 213 copy(bad, ptrs) 214 for i := len(ptrs) - 1; i >= 0; i-- { 215 bad[i] = any(nil) 216 err := form.Bind(bad) 217 if err == nil { 218 t.Fatalf("expected an error for empty iface") 219 } 220 } 221 bad = append(bad, any(nil)) 222 err := form.Bind(bad) 223 if err == nil { 224 t.Fatalf("expected an error for invalid args length") 225 } 226 } 227 228 err := form.Bind(ptrs) 229 if err != nil { 230 t.Fatalf("could not bind formula: %+v", err) 231 } 232 233 got := form.Func().(func() bool)() 234 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 235 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 236 } 237 } 238 239 func TestFuncF64F64ToBool(t *testing.T) { 240 241 rvars := make([]string, 2) 242 rvars[0] = "name-0" 243 rvars[1] = "name-1" 244 245 fct := func(arg00 float64, arg01 float64) bool { 246 return true 247 } 248 249 form := NewFuncF64F64ToBool(rvars, fct) 250 251 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 252 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 253 } 254 255 ptrs := make([]any, 2) 256 ptrs[0] = new(float64) 257 ptrs[1] = new(float64) 258 259 { 260 bad := make([]any, len(ptrs)) 261 copy(bad, ptrs) 262 for i := len(ptrs) - 1; i >= 0; i-- { 263 bad[i] = any(nil) 264 err := form.Bind(bad) 265 if err == nil { 266 t.Fatalf("expected an error for empty iface") 267 } 268 } 269 bad = append(bad, any(nil)) 270 err := form.Bind(bad) 271 if err == nil { 272 t.Fatalf("expected an error for invalid args length") 273 } 274 } 275 276 err := form.Bind(ptrs) 277 if err != nil { 278 t.Fatalf("could not bind formula: %+v", err) 279 } 280 281 got := form.Func().(func() bool)() 282 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 283 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 284 } 285 } 286 287 func TestFuncF64F64F64ToBool(t *testing.T) { 288 289 rvars := make([]string, 3) 290 rvars[0] = "name-0" 291 rvars[1] = "name-1" 292 rvars[2] = "name-2" 293 294 fct := func(arg00 float64, arg01 float64, arg02 float64) bool { 295 return true 296 } 297 298 form := NewFuncF64F64F64ToBool(rvars, fct) 299 300 if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) { 301 t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want) 302 } 303 304 ptrs := make([]any, 3) 305 ptrs[0] = new(float64) 306 ptrs[1] = new(float64) 307 ptrs[2] = new(float64) 308 309 { 310 bad := make([]any, len(ptrs)) 311 copy(bad, ptrs) 312 for i := len(ptrs) - 1; i >= 0; i-- { 313 bad[i] = any(nil) 314 err := form.Bind(bad) 315 if err == nil { 316 t.Fatalf("expected an error for empty iface") 317 } 318 } 319 bad = append(bad, any(nil)) 320 err := form.Bind(bad) 321 if err == nil { 322 t.Fatalf("expected an error for invalid args length") 323 } 324 } 325 326 err := form.Bind(ptrs) 327 if err != nil { 328 t.Fatalf("could not bind formula: %+v", err) 329 } 330 331 got := form.Func().(func() bool)() 332 if got, want := got, bool(true); !reflect.DeepEqual(got, want) { 333 t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want) 334 } 335 }