go-hep.org/x/hep@v0.38.1/lcio/cellid_test.go (about) 1 // Copyright ©2017 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 lcio 6 7 import ( 8 "testing" 9 ) 10 11 func TestCellIDDecoder(t *testing.T) { 12 { 13 dec := NewCellIDDecoder("layer:7,system:-3,barrel:3,theta:32:11,phi:11") 14 hit := CalorimeterHit{ 15 CellID0: 0x00ffffaa, 16 CellID1: 0x00aaffff, 17 } 18 19 for _, test := range []struct { 20 name string 21 want int64 22 }{ 23 {"layer", 42}, 24 {"system", -1}, 25 {"barrel", 7}, 26 {"theta", 2047}, 27 {"phi", 1375}, 28 } { 29 got := dec.Get(&hit, test.name) 30 if got != test.want { 31 t.Errorf("%s=%d. want=%d", test.name, got, test.want) 32 } 33 } 34 35 if str, want := dec.ValueString(&hit), "layer:42,system:-1,barrel:7,theta:2047,phi:1375"; str != want { 36 t.Errorf("value-string error.\n got=%q\nwant=%q", str, want) 37 } 38 } 39 { 40 codec := "M:3,S-1:3,I:9,J:9,K-1:6" 41 dec := NewCellIDDecoder(codec) 42 hit := CalorimeterHit{ 43 CellID0: 541065232, 44 } 45 if val, want := dec.Value(&hit), int64(hit.CellID0); val != want { 46 t.Errorf("value=%d. want=%d", val, want) 47 } 48 if str, want := dec.ValueString(&hit), "M:0,S-1:2,I:0,J:128,K-1:32"; str != want { 49 t.Errorf("value-string error.\n got=%q\nwant=%q", str, want) 50 } 51 52 } 53 } 54 55 func TestBitField(t *testing.T) { 56 const codec = "layer:7,system:-3,barrel:3,theta:32:11,phi:11" 57 bf := newBitField64(codec) 58 if descr, want := bf.Description(), "layer:0:7,system:7:-3,barrel:10:3,theta:32:11,phi:43:11"; descr != want { 59 t.Errorf("description error.\n got=%q\nwant=%q", descr, want) 60 } 61 if str, want := bf.valueString(), "layer:0,system:0,barrel:0,theta:0,phi:0"; str != want { 62 t.Errorf("value-string error.\n got=%q\nwant=%q", str, want) 63 } 64 bf.value = 0x00aaffff00ffffaa 65 if str, want := bf.valueString(), "layer:42,system:-1,barrel:7,theta:2047,phi:1375"; str != want { 66 t.Errorf("value-string error.\n got=%q\nwant=%q", str, want) 67 } 68 }