-
Notifications
You must be signed in to change notification settings - Fork 99
/
test_bitfieldcoder.cc
79 lines (53 loc) · 2.6 KB
/
test_bitfieldcoder.cc
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
#include "DD4hep/DDTest.h"
#include <exception>
#include <iostream>
#include <assert.h>
#include <cmath>
#include "DDSegmentation/BitFieldCoder.h"
using namespace std;
using namespace dd4hep;
using namespace DDSegmentation;
//=============================================================================
int main(int /* argc */, char** /* argv */ ){
// this should be the first line in your test
DDTest test( "bitfield64" );
try{
// ----- write your tests in here -------------------------------------
test.log( "test bitfieldcoder" );
// initialize with a string that uses all 64 bits :
const BitFieldCoder bf("system:5,side:-2,layer:9,module:8,sensor:8,x:32:-16,y:-16" ) ;
// set some 'random' values to bf2
CellID field = 0 ;
bf.set( field, "layer", 373 );
bf.set( field, "module", 254 );
bf.set( field, "sensor", 202 );
bf.set( field, "side", 1 );
bf.set( field, "system", 30 );
bf.set( field, "x", -310 );
bf.set( field, "y", -16710 );
test( field , CellID(0xbebafecacafebabeUL) , " same value 0xbebafecacafebabeUL from individual initialization " );
// make a copy for testing the access
const BitFieldCoder bf2 = bf ;
test( bf2.get( field, "layer") , 373 , " acces field value: layer" );
test( bf2.get( field, "module"), 254 , " acces field value: module" );
test( bf2.get( field, "sensor"), 202 , " acces field value: sensor" );
test( bf2.get( field, "side"), 1 , " acces field value: side" );
test( bf2.get( field, "system"), 30 , " acces field value: system" );
test( bf2.get( field, "x"), -310 , " acces field value: x" );
test( bf2.get( field, "y"), -16710 , " acces field value: y" );
test( bf2.get( field, bf2.index( "layer")) , 373 , " acces field value: layer" );
test( bf2.get( field, bf2.index( "module")), 254 , " acces field value: module" );
test( bf2.get( field, bf2.index( "sensor")), 202 , " acces field value: sensor" );
test( bf2.get( field, bf2.index( "side")), 1 , " acces field value: side" );
test( bf2.get( field, bf2.index( "system")), 30 , " acces field value: system" );
test( bf2.get( field, bf2.index( "x")), -310 , " acces field value: x" );
test( bf2.get( field, bf2.index( "y")), -16710 , " acces field value: y" );
// --------------------------------------------------------------------
} catch( exception &e ){
//} catch( ... ){
test.log( e.what() );
test.error( "exception occurred" );
}
return 0;
}
//=============================================================================