1 |
de8ed2a2
|
Jan Jirman
|
package test;
|
2 |
|
|
|
3 |
|
|
import static org.junit.Assert.assertArrayEquals;
|
4 |
|
|
import static org.junit.Assert.assertEquals;
|
5 |
|
|
|
6 |
|
|
import java.util.Arrays;
|
7 |
|
|
import java.util.Calendar;
|
8 |
|
|
import java.util.Date;
|
9 |
|
|
|
10 |
|
|
import org.apache.log4j.BasicConfigurator;
|
11 |
|
|
import org.apache.log4j.Level;
|
12 |
|
|
import org.apache.log4j.Logger;
|
13 |
|
|
import org.junit.Before;
|
14 |
|
|
import org.junit.BeforeClass;
|
15 |
|
|
import org.junit.Test;
|
16 |
|
|
|
17 |
|
|
import data.Bitmap;
|
18 |
|
|
import data.DataReader;
|
19 |
|
|
|
20 |
|
|
public class testBitmap {
|
21 |
|
|
private static final Logger log = Logger.getLogger(testJDFCaskodyRecord.class);
|
22 |
|
|
private static Bitmap bitmap;
|
23 |
|
|
private static Calendar dateFrom = Calendar.getInstance();
|
24 |
|
|
private static Calendar dateTo = Calendar.getInstance();
|
25 |
|
|
|
26 |
|
|
@BeforeClass
|
27 |
|
|
public static void setUpBeforeClass() {
|
28 |
|
|
|
29 |
|
|
BasicConfigurator.configure();
|
30 |
|
|
Logger.getRootLogger().setLevel(Level.INFO);
|
31 |
|
|
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
@Before
|
35 |
|
|
public void setUpBefore() {
|
36 |
|
|
|
37 |
|
|
dateFrom.setTime(new Date(2019-1900, 4, 1)); // -- Jen pro testování Deprecated --
|
38 |
|
|
dateTo.setTime(new Date(2019-1900, 4, 31)); // rok udáván od 1900, měsíc se počítá od 0
|
39 |
|
|
|
40 |
|
|
|
41 |
7cafefe1
|
Daniel Stuš
|
bitmap = new Bitmap(dateFrom, dateTo, "143440");
|
42 |
de8ed2a2
|
Jan Jirman
|
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
@Test
|
47 |
|
|
public void testgetDateRange(){
|
48 |
|
|
assertEquals(31,bitmap.getDateRange());
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
@Test
|
52 |
|
|
public void testsetDay() {
|
53 |
|
|
Calendar date = Calendar.getInstance();
|
54 |
|
|
date.setTime(new Date(2019-1900, 4, 3));
|
55 |
|
|
bitmap.setDay(date, 1);
|
56 |
|
|
date.setTime(new Date(2019-1900, 4, 4));
|
57 |
|
|
bitmap.setDay(date, 1);
|
58 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
@Test
|
62 |
|
|
public void testgetDatePosition() {
|
63 |
|
|
Calendar date = Calendar.getInstance();
|
64 |
|
|
date.setTime(new Date(2019-1900, 4, 3));
|
65 |
|
|
long position = bitmap.getDatePosition(date);
|
66 |
|
|
assertEquals(2,position);
|
67 |
|
|
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
@Test
|
71 |
|
|
public void testsetWorkdays() {
|
72 |
|
|
bitmap.setWorkdays(1);
|
73 |
7cafefe1
|
Daniel Stuš
|
// Přidáný svátky
|
74 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]"));
|
75 |
de8ed2a2
|
Jan Jirman
|
}
|
76 |
|
|
|
77 |
|
|
@Test
|
78 |
|
|
public void testsetSundaysAndHolidays() {
|
79 |
|
|
bitmap.setSundaysAndHolidays(1);
|
80 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1]"));
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
@Test
|
85 |
|
|
public void testsetOneDayOnly() {
|
86 |
|
|
Calendar date = Calendar.getInstance();
|
87 |
|
|
date.setTime(new Date(2019-1900, 4, 3));
|
88 |
|
|
bitmap.setOneDayOnly(date);
|
89 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
90 |
|
|
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
@Test
|
94 |
|
|
public void testsetDaysInRange() {
|
95 |
|
|
Calendar date1 = Calendar.getInstance();
|
96 |
|
|
date1.setTime(new Date(2019-1900, 4, 3));
|
97 |
|
|
Calendar date2 = Calendar.getInstance();
|
98 |
|
|
date2.setTime(new Date(2019-1900, 4, 5));
|
99 |
|
|
bitmap.setDaysInRange(date1,date2, 1);
|
100 |
7cafefe1
|
Daniel Stuš
|
// Opravdu chyba (poslední den včetně) - Opraveno
|
101 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
102 |
de8ed2a2
|
Jan Jirman
|
}
|
103 |
|
|
|
104 |
|
|
@Test
|
105 |
|
|
public void testsetDaysInWeek(){
|
106 |
|
|
bitmap.setDaysInWeek(2, 1); //kazde pondeli ... pondeli - 2
|
107 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]"));
|
108 |
|
|
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
@Test
|
112 |
|
|
public void testsetWeeks(){
|
113 |
|
|
bitmap.setWeeks(1, 1);
|
114 |
7cafefe1
|
Daniel Stuš
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]"));
|
115 |
de8ed2a2
|
Jan Jirman
|
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
@Test
|
119 |
|
|
public void testsetWeeksRange(){
|
120 |
|
|
Calendar date1 = Calendar.getInstance();
|
121 |
|
|
date1.setTime(new Date(2019-1900, 4, 1));
|
122 |
|
|
Calendar date2 = Calendar.getInstance();
|
123 |
|
|
date2.setTime(new Date(2019-1900, 4, 13));
|
124 |
|
|
bitmap.setWeeksRange(date1,date2, 1, 1);
|
125 |
7cafefe1
|
Daniel Stuš
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
126 |
de8ed2a2
|
Jan Jirman
|
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
@Test
|
130 |
|
|
public void testfillWithZeros(){
|
131 |
|
|
bitmap.fillWithZeros();
|
132 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
133 |
|
|
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
@Test
|
137 |
|
|
public void testvalidateValue(){
|
138 |
|
|
int value = -1;
|
139 |
|
|
int exceptedZero = Bitmap.validateValue(value);
|
140 |
|
|
assertEquals(0,exceptedZero);
|
141 |
|
|
value = 0;
|
142 |
|
|
exceptedZero = Bitmap.validateValue(value);
|
143 |
|
|
assertEquals(0,exceptedZero);
|
144 |
|
|
value = 1;
|
145 |
|
|
int exceptedOne = Bitmap.validateValue(value);
|
146 |
|
|
assertEquals(1,exceptedOne);
|
147 |
|
|
value = 2;
|
148 |
|
|
exceptedOne = Bitmap.validateValue(value);
|
149 |
|
|
assertEquals(1,exceptedOne);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
@Test
|
153 |
|
|
public void testgetDateFrom(){
|
154 |
|
|
assertEquals(0,bitmap.getDateFrom().getTime().toString().compareToIgnoreCase("Wed May 01 00:00:00 CEST 2019"));
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
@Test
|
158 |
|
|
public void testsetDateFrom(){
|
159 |
|
|
dateFrom.setTime(new Date(2019-1900, 4, 2));
|
160 |
|
|
assertEquals(0,bitmap.getDateFrom().getTime().toString().compareToIgnoreCase("Thu May 02 00:00:00 CEST 2019"));
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
@Test
|
164 |
|
|
public void testgetDateTo() {
|
165 |
|
|
assertEquals(0,bitmap.getDateTo().getTime().toString().compareToIgnoreCase("Fri May 31 00:00:00 CEST 2019"));
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
@Test
|
169 |
|
|
public void testsetDateTo() {
|
170 |
|
|
dateTo.setTime(new Date(2019-1900, 4, 30));
|
171 |
|
|
assertEquals(0,bitmap.getDateTo().getTime().toString().compareToIgnoreCase("Thu May 30 00:00:00 CEST 2019"));
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
@Test
|
175 |
|
|
public void testgetLineNumber() {
|
176 |
|
|
assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143440"));
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
@Test
|
180 |
|
|
public void testsetLineNumber() {
|
181 |
|
|
bitmap.setLineNumber("143441");
|
182 |
|
|
assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143441"));
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
@Test
|
186 |
|
|
public void testgetBitmap() {
|
187 |
|
|
int[] array = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
188 |
|
|
assertArrayEquals(array, bitmap.getBitmap());
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
@Test
|
192 |
|
|
public void testsetBitmap() {
|
193 |
|
|
int[] array = new int[] {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
194 |
|
|
int[] newBitmap = new int[] {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
195 |
|
|
bitmap.setBitmap(newBitmap);
|
196 |
|
|
assertArrayEquals(array, bitmap.getBitmap());
|
197 |
|
|
this.bitmap = bitmap;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
@Test
|
201 |
|
|
public void testtoString() {
|
202 |
|
|
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
}
|