Skip to content

Commit

Permalink
groot/rphys: make Vector{2,3} implement fmt.Stringer
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Dec 16, 2021
1 parent 4eac99c commit 7f0b7a4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions groot/rphys/vector2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package rphys

import (
"fmt"
"reflect"

"go-hep.org/x/hep/groot/rbase"
Expand Down Expand Up @@ -80,6 +81,10 @@ func (vec *Vector2) UnmarshalROOT(r *rbytes.RBuffer) error {
return r.Err()
}

func (vec *Vector2) String() string {
return fmt.Sprintf("TVector2{%v, %v}", vec.x, vec.y)
}

func init() {
{
f := func() reflect.Value {
Expand Down
8 changes: 8 additions & 0 deletions groot/rphys/vector2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package rphys_test

import (
"fmt"
"testing"

"go-hep.org/x/hep/groot/rphys"
Expand Down Expand Up @@ -36,10 +37,17 @@ func TestVector2(t *testing.T) {
}
})
}
if got, want := fmt.Sprintf("%v", p2), "TVector2{1, 2}"; got != want {
t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
}

p2.SetX(-1)
p2.SetY(-2)

if got, want := fmt.Sprintf("%v", p2), "TVector2{-1, -2}"; got != want {
t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
}

for _, tc := range []struct {
name string
fct func() float64
Expand Down
8 changes: 8 additions & 0 deletions groot/rphys/vector3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package rphys

import (
"fmt"
"reflect"

"go-hep.org/x/hep/groot/rbase"
Expand Down Expand Up @@ -86,6 +87,13 @@ func (vec *Vector3) UnmarshalROOT(r *rbytes.RBuffer) error {
return r.Err()
}

func (vec *Vector3) String() string {
return fmt.Sprintf(
"TVector3{%v, %v, %v}",
vec.x, vec.y, vec.z,
)
}

func init() {
{
f := func() reflect.Value {
Expand Down
9 changes: 9 additions & 0 deletions groot/rphys/vector3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package rphys_test

import (
"fmt"
"testing"

"go-hep.org/x/hep/groot/rphys"
Expand Down Expand Up @@ -42,10 +43,18 @@ func TestVector3(t *testing.T) {
})
}

if got, want := fmt.Sprintf("%v", p3), "TVector3{1, 2, 3}"; got != want {
t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
}

p3.SetX(-1)
p3.SetY(-2)
p3.SetZ(-3)

if got, want := fmt.Sprintf("%v", p3), "TVector3{-1, -2, -3}"; got != want {
t.Fatalf("invalid stringer value:\ngot= %q\nwant=%q", got, want)
}

for _, tc := range []struct {
name string
fct func() float64
Expand Down

0 comments on commit 7f0b7a4

Please sign in to comment.