xref: /aosp_15_r20/external/zxing/core/src/test/java/com/google/zxing/oned/rss/expanded/BitArrayBuilderTest.java (revision 513427e33d61bc67fc40bc261642ac0b2a686b45)
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 com.google.zxing.common.BitArray;
30 import com.google.zxing.oned.rss.DataCharacter;
31 
32 import org.junit.Assert;
33 import org.junit.Test;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 
38 /**
39  * @author Pablo Orduña, University of Deusto ([email protected])
40  * @author Eduardo Castillejo, University of Deusto ([email protected])
41  */
42 public final class BitArrayBuilderTest extends Assert {
43 
44   @Test
testBuildBitArray1()45   public void testBuildBitArray1() {
46     int[][] pairValues = {{19}, {673, 16}};
47 
48     String expected = " .......X ..XX..X. X.X....X .......X ....";
49 
50     checkBinary(pairValues, expected);
51   }
52 
checkBinary(int[][] pairValues, String expected)53   private static void checkBinary(int[][] pairValues, String expected) {
54     BitArray binary = buildBitArray(pairValues);
55     assertEquals(expected, binary.toString());
56   }
57 
buildBitArray(int[][] pairValues)58   private static BitArray buildBitArray(int[][] pairValues) {
59     List<ExpandedPair> pairs = new ArrayList<>();
60     for (int i = 0; i < pairValues.length; ++i) {
61       int [] pair = pairValues[i];
62 
63       DataCharacter leftChar;
64       if (i == 0) {
65         leftChar = null;
66       } else {
67         leftChar = new DataCharacter(pair[0], 0);
68       }
69 
70       DataCharacter rightChar;
71       if (i == 0) {
72         rightChar = new DataCharacter(pair[0], 0);
73       } else if (pair.length == 2) {
74         rightChar = new DataCharacter(pair[1], 0);
75       } else {
76         rightChar = null;
77       }
78 
79       ExpandedPair expandedPair = new ExpandedPair(leftChar, rightChar, null);
80       pairs.add(expandedPair);
81     }
82 
83     return BitArrayBuilder.buildBitArray(pairs);
84   }
85 }
86