1 package org.lcsim.geometry.util;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6
7 import org.lcsim.geometry.util.IDDescriptor.IDException;
8
9
10
11
12
13 public class IDDecoderTest extends TestCase
14 {
15
16 public IDDecoderTest(String testName)
17 {
18 super(testName);
19 }
20
21 public static Test suite()
22 {
23 return new TestSuite(IDDecoderTest.class);
24 }
25
26 public void testDecoder() throws IDException
27 {
28 String description = "layer:7,system:3,barrel:3,theta:32:11,phi:11";
29 IDDescriptor desc = new IDDescriptor(description);
30 IDDecoder ring = new IDDecoder(desc);
31
32 long[] ids = { 1, 2, 3, 400, 500 };
33 long id = ids[0] | ids[1]<<7 | ids[2]<<10 | ids[3]<<32 | ids[4]<<43;
34 ring.setID(id);
35
36 for (int i=0; i<ids.length; i++)
37 {
38 assertEquals(ids[i],ring.getValue(i));
39 }
40
41 int[] rids = new int[ids.length];
42 ring.getValues(rids);
43 for (int i=0; i<ids.length; i++) assertEquals(ids[i],rids[i]);
44 }
45 public void testSignedDecoder() throws IDException
46 {
47 String description = "layer:7,system:-3,barrel:3,theta:32:-11,phi:11";
48 IDDescriptor desc = new IDDescriptor(description);
49 IDDecoder ring = new IDDecoder(desc);
50
51 long[] ids = { 1, 2, 3, -400, 500 };
52 long id = ids[0] | ids[1]<<7 | ids[2]<<10 | (ids[3] & ((1<<11) - 1))<<32 | ids[4]<<43;
53 ring.setID(id);
54
55 for (int i=0; i<ids.length; i++)
56 {
57 assertEquals(ids[i],ring.getValue(i));
58 }
59
60 int[] rids = new int[ids.length];
61 ring.getValues(rids);
62 for (int i=0; i<ids.length; i++) assertEquals(ids[i],rids[i]);
63 }
64
65 }