-
Notifications
You must be signed in to change notification settings - Fork 35
/
rw_test.go
117 lines (111 loc) · 2.46 KB
/
rw_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2020 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package rphys
import (
"io"
"reflect"
"testing"
"go-hep.org/x/hep/groot/internal/rtests"
"go-hep.org/x/hep/groot/rbase"
"go-hep.org/x/hep/groot/rbytes"
"go-hep.org/x/hep/groot/rtypes"
)
func TestWRBuffer(t *testing.T) {
for _, tc := range []struct {
name string
want rtests.ROOTer
cmp func(a, b rtests.ROOTer) bool
}{
{
name: "TFeldmanCousins",
want: &FeldmanCousins{
obj: rbase.Object{ID: 0x0, Bits: 0x3000000},
CL: 1,
UpLim: 2,
LoLim: 3,
Nobs: 4,
Nbkg: 5,
MuMin: 6,
MuMax: 7,
MuStep: 8,
NMuStep: 9,
NMax: 10,
Quick: 11,
},
},
{
name: "TLorentzVector",
want: &LorentzVector{
obj: rbase.Object{ID: 0x0, Bits: 0x3000000},
p: Vector3{
obj: rbase.Object{ID: 0x0, Bits: 0x3000000},
x: 1, y: 2, z: 3,
},
e: 4,
},
},
{
name: "TVector2",
want: &Vector2{
obj: rbase.Object{ID: 0x0, Bits: 0x3000000},
x: 1, y: 2,
},
},
{
name: "TVector3",
want: &Vector3{
obj: rbase.Object{ID: 0x0, Bits: 0x3000000},
x: 1, y: 2, z: 3,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
{
wbuf := rbytes.NewWBuffer(nil, nil, 0, nil)
wbuf.SetErr(io.EOF)
_, err := tc.want.MarshalROOT(wbuf)
if err == nil {
t.Fatalf("expected an error")
}
if err != io.EOF {
t.Fatalf("got=%v, want=%v", err, io.EOF)
}
}
wbuf := rbytes.NewWBuffer(nil, nil, 0, nil)
_, err := tc.want.MarshalROOT(wbuf)
if err != nil {
t.Fatalf("could not marshal ROOT: %v", err)
}
rbuf := rbytes.NewRBuffer(wbuf.Bytes(), nil, 0, nil)
class := tc.want.Class()
obj := rtypes.Factory.Get(class)().Interface().(rbytes.Unmarshaler)
{
rbuf.SetErr(io.EOF)
err = obj.UnmarshalROOT(rbuf)
if err == nil {
t.Fatalf("expected an error")
}
if err != io.EOF {
t.Fatalf("got=%v, want=%v", err, io.EOF)
}
rbuf.SetErr(nil)
}
err = obj.UnmarshalROOT(rbuf)
if err != nil {
t.Fatalf("could not unmarshal ROOT: %v", err)
}
switch tc.cmp {
case nil:
if !reflect.DeepEqual(obj, tc.want) {
t.Fatalf("error\ngot= %+v\nwant=%+v\n", obj, tc.want)
}
default:
obj := obj.(rtests.ROOTer)
if !tc.cmp(obj, tc.want) {
t.Fatalf("error\ngot= %+v\nwant=%+v\n", obj, tc.want)
}
}
})
}
}