760c97d56e24857a8298c89f5d885b86fb60c059
[zxing.git] / core / test / src / com / google / zxing / oned / rss / expanded / BitArrayBuilderTest.java
1 /*
2  * Copyright (C) 2010 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  * These authors would like to acknowledge the Spanish Ministry of Industry,
19  * Tourism and Trade, for the support in the project TSI020301-2008-2
20  * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21  * Mobile Dynamic Environments", led by Treelogic
22  * ( http://www.treelogic.com/ ):
23  *
24  *   http://www.piramidepse.com/
25  */
26
27 package com.google.zxing.oned.rss.expanded;
28
29 import java.util.Vector;
30
31 import com.google.zxing.common.BitArray;
32 import com.google.zxing.oned.rss.DataCharacter;
33
34 import org.junit.Assert;
35 import org.junit.Test;
36
37 /**
38  * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
39  * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
40  */
41 public final class BitArrayBuilderTest extends Assert {
42
43   @Test
44   public void testBuildBitArray1() {
45     int [][] pairValues = {
46         { 19 },
47         { 673, 16 }
48     };
49
50     String expected = " .......X ..XX..X. X.X....X .......X ....";
51
52     checkBinary(pairValues, expected);
53   }
54
55   private static void checkBinary(int[][] pairValues, String expected) {
56     BitArray binary = buildBitArray(pairValues);
57     assertEquals(expected, binary.toString());
58   }
59
60   private static BitArray buildBitArray(int[][] pairValues) {
61     Vector<ExpandedPair> pairs = new Vector<ExpandedPair>();
62     for(int i = 0; i < pairValues.length; ++i){
63       int [] pair = pairValues[i];
64
65       DataCharacter leftChar;
66       if(i == 0) {
67         leftChar = null;
68       } else {
69         leftChar = new DataCharacter(pair[0], 0);
70       }
71
72       DataCharacter rightChar;
73       if(i == 0) {
74         rightChar = new DataCharacter(pair[0], 0);
75       } else if(pair.length == 2) {
76         rightChar = new DataCharacter(pair[1], 0);
77       } else {
78         rightChar = null;
79       }
80
81       ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null, true);
82       pairs.add(expandedPair);
83     }
84
85     return BitArrayBuilder.buildBitArray(pairs);
86   }
87 }