Small style stuff
[zxing.git] / core / test / src / com / google / zxing / oned / rss / expanded / BinaryUtilTest.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 com.google.zxing.common.BitArray;
30
31 import org.junit.Assert;
32 import org.junit.Test;
33
34 /**
35  * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
36  */
37 public final class BinaryUtilTest extends Assert {
38
39   @Test
40   public void testBuildBitArrayFromString(){
41
42     String data = " ..X..X.. ..XXX... XXXXXXXX ........";
43     check(data);
44
45     data = " XXX..X..";
46     check(data);
47
48     data = " XX";
49     check(data);
50
51     data = " ....XX.. ..XX";
52     check(data);
53
54     data = " ....XX.. ..XX..XX ....X.X. ........";
55     check(data);
56   }
57
58   private static void check(String data){
59     BitArray binary = BinaryUtil.buildBitArrayFromString(data);
60     assertEquals(data, binary.toString());
61   }
62
63   @Test
64   public void testBuildBitArrayFromStringWithoutSpaces(){
65     String data = " ..X..X.. ..XXX... XXXXXXXX ........";
66     checkWithoutSpaces(data);
67
68     data = " XXX..X..";
69     checkWithoutSpaces(data);
70
71     data = " XX";
72     checkWithoutSpaces(data);
73
74     data = " ....XX.. ..XX";
75     checkWithoutSpaces(data);
76
77     data = " ....XX.. ..XX..XX ....X.X. ........";
78     checkWithoutSpaces(data);
79   }
80
81   private static void checkWithoutSpaces(String data){
82     String dataWithoutSpaces = data.replaceAll(" ", "");
83     BitArray binary = BinaryUtil.buildBitArrayFromStringWithoutSpaces(dataWithoutSpaces);
84     assertEquals(data, binary.toString());
85   }
86 }