go-hep.org/x/hep@v0.38.1/groot/rphys/vector2_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 TestVector2(t *testing.T) {
    15  	p2 := rphys.NewVector2(1, 2)
    16  
    17  	for _, tc := range []struct {
    18  		name string
    19  		fct  func() float64
    20  		want float64
    21  	}{
    22  		{
    23  			name: "x",
    24  			fct:  p2.X,
    25  			want: 1,
    26  		},
    27  		{
    28  			name: "y",
    29  			fct:  p2.Y,
    30  			want: 2,
    31  		},
    32  	} {
    33  		t.Run(tc.name, func(t *testing.T) {
    34  			got := tc.fct()
    35  			if got != tc.want {
    36  				t.Fatalf("invalid getter value: got=%v, want=%v", got, tc.want)
    37  			}
    38  		})
    39  	}
    40  	if got, want := fmt.Sprintf("%v", p2), "TVector2{1, 2}"; got != want {
    41  		t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
    42  	}
    43  
    44  	p2.SetX(-1)
    45  	p2.SetY(-2)
    46  
    47  	if got, want := fmt.Sprintf("%v", p2), "TVector2{-1, -2}"; got != want {
    48  		t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
    49  	}
    50  
    51  	for _, tc := range []struct {
    52  		name string
    53  		fct  func() float64
    54  		want float64
    55  	}{
    56  		{
    57  			name: "x",
    58  			fct:  p2.X,
    59  			want: -1,
    60  		},
    61  		{
    62  			name: "y",
    63  			fct:  p2.Y,
    64  			want: -2,
    65  		},
    66  	} {
    67  		t.Run(tc.name, func(t *testing.T) {
    68  			got := tc.fct()
    69  			if got != tc.want {
    70  				t.Fatalf("invalid getter value: got=%v, want=%v", got, tc.want)
    71  			}
    72  		})
    73  	}
    74  }