go-hep.org/x/hep@v0.38.1/groot/rphys/vector3_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  package rphys_test
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"go-hep.org/x/hep/groot/rphys"
    12  )
    13  
    14  func TestVector3(t *testing.T) {
    15  	p3 := rphys.NewVector3(1, 2, 3)
    16  
    17  	for _, tc := range []struct {
    18  		name string
    19  		fct  func() float64
    20  		want float64
    21  	}{
    22  		{
    23  			name: "x",
    24  			fct:  p3.X,
    25  			want: 1,
    26  		},
    27  		{
    28  			name: "y",
    29  			fct:  p3.Y,
    30  			want: 2,
    31  		},
    32  		{
    33  			name: "z",
    34  			fct:  p3.Z,
    35  			want: 3,
    36  		},
    37  	} {
    38  		t.Run(tc.name, func(t *testing.T) {
    39  			got := tc.fct()
    40  			if got != tc.want {
    41  				t.Fatalf("invalid getter value: got=%v, want=%v", got, tc.want)
    42  			}
    43  		})
    44  	}
    45  
    46  	if got, want := fmt.Sprintf("%v", p3), "TVector3{1, 2, 3}"; got != want {
    47  		t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
    48  	}
    49  
    50  	p3.SetX(-1)
    51  	p3.SetY(-2)
    52  	p3.SetZ(-3)
    53  
    54  	if got, want := fmt.Sprintf("%v", p3), "TVector3{-1, -2, -3}"; got != want {
    55  		t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
    56  	}
    57  
    58  	for _, tc := range []struct {
    59  		name string
    60  		fct  func() float64
    61  		want float64
    62  	}{
    63  		{
    64  			name: "x",
    65  			fct:  p3.X,
    66  			want: -1,
    67  		},
    68  		{
    69  			name: "y",
    70  			fct:  p3.Y,
    71  			want: -2,
    72  		},
    73  		{
    74  			name: "z",
    75  			fct:  p3.Z,
    76  			want: -3,
    77  		},
    78  	} {
    79  		t.Run(tc.name, func(t *testing.T) {
    80  			got := tc.fct()
    81  			if got != tc.want {
    82  				t.Fatalf("invalid getter value: got=%v, want=%v", got, tc.want)
    83  			}
    84  		})
    85  	}
    86  }