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