go-hep.org/x/hep@v0.38.1/groot/rtree/rfunc/rfunc_f64s_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 TestFuncF32sToF64s(t *testing.T) {
    15  
    16  	rvars := make([]string, 1)
    17  	rvars[0] = "name-0"
    18  
    19  	fct := func(arg00 []float32) []float64 {
    20  		return []float64{42}
    21  	}
    22  
    23  	form := NewFuncF32sToF64s(rvars, fct)
    24  
    25  	if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) {
    26  		t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want)
    27  	}
    28  
    29  	ptrs := make([]any, 1)
    30  	ptrs[0] = new([]float32)
    31  
    32  	{
    33  		bad := make([]any, len(ptrs))
    34  		copy(bad, ptrs)
    35  		for i := len(ptrs) - 1; i >= 0; i-- {
    36  			bad[i] = any(nil)
    37  			err := form.Bind(bad)
    38  			if err == nil {
    39  				t.Fatalf("expected an error for empty iface")
    40  			}
    41  		}
    42  		bad = append(bad, any(nil))
    43  		err := form.Bind(bad)
    44  		if err == nil {
    45  			t.Fatalf("expected an error for invalid args length")
    46  		}
    47  	}
    48  
    49  	err := form.Bind(ptrs)
    50  	if err != nil {
    51  		t.Fatalf("could not bind formula: %+v", err)
    52  	}
    53  
    54  	got := form.Func().(func() []float64)()
    55  	if got, want := got, []float64([]float64{42}); !reflect.DeepEqual(got, want) {
    56  		t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want)
    57  	}
    58  }
    59  
    60  func TestFuncF64sToF64s(t *testing.T) {
    61  
    62  	rvars := make([]string, 1)
    63  	rvars[0] = "name-0"
    64  
    65  	fct := func(arg00 []float64) []float64 {
    66  		return []float64{42}
    67  	}
    68  
    69  	form := NewFuncF64sToF64s(rvars, fct)
    70  
    71  	if got, want := form.RVars(), rvars; !reflect.DeepEqual(got, want) {
    72  		t.Fatalf("invalid rvars: got=%#v, want=%#v", got, want)
    73  	}
    74  
    75  	ptrs := make([]any, 1)
    76  	ptrs[0] = new([]float64)
    77  
    78  	{
    79  		bad := make([]any, len(ptrs))
    80  		copy(bad, ptrs)
    81  		for i := len(ptrs) - 1; i >= 0; i-- {
    82  			bad[i] = any(nil)
    83  			err := form.Bind(bad)
    84  			if err == nil {
    85  				t.Fatalf("expected an error for empty iface")
    86  			}
    87  		}
    88  		bad = append(bad, any(nil))
    89  		err := form.Bind(bad)
    90  		if err == nil {
    91  			t.Fatalf("expected an error for invalid args length")
    92  		}
    93  	}
    94  
    95  	err := form.Bind(ptrs)
    96  	if err != nil {
    97  		t.Fatalf("could not bind formula: %+v", err)
    98  	}
    99  
   100  	got := form.Func().(func() []float64)()
   101  	if got, want := got, []float64([]float64{42}); !reflect.DeepEqual(got, want) {
   102  		t.Fatalf("invalid output:\ngot= %v (%T)\nwant=%v (%T)", got, got, want, want)
   103  	}
   104  }