Projekt

Obecné

Profil

Stáhnout (9.48 KB) Statistiky
| Větev: | Revize:
1 de8ed2a2 Jan Jirman
package test;
2
3
import static org.junit.Assert.assertArrayEquals;
4
import static org.junit.Assert.assertEquals;
5 bb5636cc Jan Jirman
import static org.junit.Assert.assertTrue;
6 de8ed2a2 Jan Jirman
7 17168608 Daniel Stuš
import java.time.DayOfWeek;
8
import java.time.LocalDate;
9 de8ed2a2 Jan Jirman
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
19
public class testBitmap {
20
	private static final Logger log = Logger.getLogger(testJDFCaskodyRecord.class);
21
    private static Bitmap bitmap;
22 17168608 Daniel Stuš
    private static LocalDate dateFrom;
23
    private static LocalDate dateTo;
24 bb5636cc Jan Jirman
    private char[] hardCodesChar;
25 de8ed2a2 Jan Jirman
26
    @BeforeClass
27
    public static void setUpBeforeClass() {
28
29
        BasicConfigurator.configure();
30
        Logger.getRootLogger().setLevel(Level.INFO);
31 bb5636cc Jan Jirman
        
32
        
33 de8ed2a2 Jan Jirman
    
34
    }
35
    
36
    @Before
37
    public void setUpBefore() {
38
39 17168608 Daniel Stuš
        dateFrom = LocalDate.of(2019, 5, 1);
40
        dateTo = LocalDate.of(2019, 5, 31);
41 bb5636cc Jan Jirman
        
42
       
43 de8ed2a2 Jan Jirman
44 17168608 Daniel Stuš
        bitmap = new Bitmap(dateFrom, dateTo, "143440","1","34", "5", "1");
45 bb5636cc Jan Jirman
        hardCodesChar = bitmap.getHardCodes().toCharArray();
46 de8ed2a2 Jan Jirman
    
47
    }
48
49
 
50
    @Test
51
    public void testgetDateRange(){
52
       assertEquals(31,bitmap.getDateRange());
53
    }
54
    
55
    @Test
56
    public void testsetDay() {
57 17168608 Daniel Stuš
    	LocalDate date = LocalDate.of(2019, 5, 3);
58 de8ed2a2 Jan Jirman
    	bitmap.setDay(date, 1);
59 17168608 Daniel Stuš
    	date = LocalDate.of(2019, 5, 4);
60 de8ed2a2 Jan Jirman
    	bitmap.setDay(date, 1);
61 17168608 Daniel Stuš
    	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]"));
62 de8ed2a2 Jan Jirman
    }
63
    
64
    @Test
65
    public void testgetDatePosition() {
66 17168608 Daniel Stuš
    	LocalDate date = LocalDate.of(2019, 5, 3);
67 de8ed2a2 Jan Jirman
    	long position = bitmap.getDatePosition(date);
68
    	assertEquals(2,position);
69
    	
70
    }
71
    
72
    @Test
73
    public void testsetWorkdays() {
74
    	bitmap.setWorkdays(1);
75 7cafefe1 Daniel Stuš
    	// Přidáný svátky
76 17168608 Daniel Stuš
    	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]"));
77 de8ed2a2 Jan Jirman
    }
78
    
79 bb5636cc Jan Jirman
    @Test
80
    public void testsetWorkdaysInRange(){
81
    	bitmap.setWorkdaysInRange(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15), 1);
82
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
83
    } 
84
    
85 de8ed2a2 Jan Jirman
    @Test
86
    public void testsetSundaysAndHolidays() {
87
    	bitmap.setSundaysAndHolidays(1);
88 17168608 Daniel Stuš
    	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]"));
89 de8ed2a2 Jan Jirman
    }
90
    
91 bb5636cc Jan Jirman
    @Test
92
    public void testsetSundaysAndHolidays2() {
93
    	bitmap.setSundaysAndHolidays(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15),1);
94
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
95
    }
96
    
97 de8ed2a2 Jan Jirman
    
98
    @Test
99
    public void testsetOneDayOnly() {
100 17168608 Daniel Stuš
    	LocalDate date = LocalDate.of(2019, 5, 3);
101 de8ed2a2 Jan Jirman
    	bitmap.setOneDayOnly(date);
102 17168608 Daniel Stuš
    	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]"));
103 de8ed2a2 Jan Jirman
   
104
    }
105
    
106
    @Test
107
    public void testsetDaysInRange() {
108 17168608 Daniel Stuš
    	LocalDate date1 = LocalDate.of(2019, 5, 3);
109
    	LocalDate date2 = LocalDate.of(2019,5,5);
110 de8ed2a2 Jan Jirman
    	bitmap.setDaysInRange(date1,date2, 1);
111 7cafefe1 Daniel Stuš
    	// Opravdu chyba (poslední den včetně) - Opraveno
112 17168608 Daniel Stuš
    	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]"));
113 de8ed2a2 Jan Jirman
    }
114
    
115 bb5636cc Jan Jirman
    @Test
116
    public void unsetDaysInRange() {
117
    	bitmap.setWorkdays(1);
118
          bitmap.unsetDaysInRange(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15));
119
          assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]"));
120
    }
121
    
122 de8ed2a2 Jan Jirman
    @Test
123
    public void testsetDaysInWeek(){
124 17168608 Daniel Stuš
    	bitmap.setDaysInWeek(DayOfWeek.MONDAY, 1); //kazde pondeli ... pondeli - 2
125
    	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]"));
126 de8ed2a2 Jan Jirman
    	
127
    }
128
    
129 bb5636cc Jan Jirman
    @Test
130
    public void testsetDaysInWeek2(){
131
    	bitmap.setDaysInWeek(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15),DayOfWeek.MONDAY, 1); //kazde pondeli ... pondeli - 2
132
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
133
    }
134
    
135 de8ed2a2 Jan Jirman
    @Test
136
    public void testsetWeeks(){
137
    	bitmap.setWeeks(1, 1);
138 17168608 Daniel Stuš
    	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]"));
139 de8ed2a2 Jan Jirman
    	
140
    }
141
    
142
    @Test
143 17168608 Daniel Stuš
    public void testsetWeeksInRange(){
144
        LocalDate date1 = LocalDate.of(2019, 5, 1);
145
        LocalDate date2 = LocalDate.of(2019, 5, 13);
146
    	bitmap.setWeeksInRange(date1,date2, 1, 1);
147
    	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]"));
148 de8ed2a2 Jan Jirman
    
149
    }
150
    
151 bb5636cc Jan Jirman
    @Test
152
    public void setHolidays() {
153
    	bitmap.setHolidays(1);
154
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[1, 0, 0, 0, 0, 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]"));
155
    }
156
    
157
    @Test
158
    public void setHardCodeDays() {
159
    	bitmap.setHardCodeDays(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15), 1); 
160
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
161
        
162
    }
163
  
164
    
165
    @Test
166
    public void setHardCodeWeeks() {
167
    	bitmap.setHardCodeWeeks(1,1); 
168
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]"));
169
      
170
    }
171
    
172
    
173
    @Test
174
    public void setHardCodeWeeksInRange() {
175
    	bitmap.setHardCodeWeeksInRange(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15),1,1); 
176
    	assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
177
      
178
    }
179
    
180
    @Test
181
    public void testisHardCodeDay(){
182
    	assertTrue(bitmap.isHardCodeDay(LocalDate.of(2019, 5, 10), hardCodesChar[0]));
183
    }
184
    
185
    @Test
186
    public void isBankHoliday() {
187
    	assertTrue(bitmap.isBankHoliday(LocalDate.of(2019, 5, 1)));
188
    }
189
    
190
    /* @Test
191
    public void getEasterHolidays() {
192
    	bitmap.getEasterHolidays(2019);
193
    	bitmap.;
194
    } */
195
    
196
    @Test
197
    public void getBitmapString() {
198
    	bitmap.setWorkdays(1);
199
    	assertEquals(0,bitmap.getBitmapString().compareToIgnoreCase("0110011011001111100111110011111"));
200
    }
201
    
202 de8ed2a2 Jan Jirman
    @Test
203
    public void testfillWithZeros(){
204
    	bitmap.fillWithZeros();
205 17168608 Daniel Stuš
    	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]"));
206 de8ed2a2 Jan Jirman
    	
207
    }
208
    
209
    @Test
210
    public void testvalidateValue(){
211
    	int value = -1;
212
    	int exceptedZero = Bitmap.validateValue(value);
213
    	assertEquals(0,exceptedZero);
214
    	value = 0;
215
    	exceptedZero = Bitmap.validateValue(value);
216
    	assertEquals(0,exceptedZero);
217
    	value = 1;
218
    	int exceptedOne = Bitmap.validateValue(value);
219
    	assertEquals(1,exceptedOne);
220
    	value = 2;
221
    	exceptedOne = Bitmap.validateValue(value);
222
    	assertEquals(1,exceptedOne);   	
223
    }
224 17168608 Daniel Stuš
225
226 de8ed2a2 Jan Jirman
    @Test
227
    public void testgetDateFrom(){
228 17168608 Daniel Stuš
    	assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-01"));
229 de8ed2a2 Jan Jirman
    }
230
    
231
    @Test
232
    public void testsetDateFrom(){
233 17168608 Daniel Stuš
        dateFrom = LocalDate.of(2019, 5, 2);
234
        bitmap.setDateFrom(dateFrom);
235
    	assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-02"));
236 de8ed2a2 Jan Jirman
    }
237
    
238
    @Test
239
    public void testgetDateTo() {
240 17168608 Daniel Stuš
    	assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-31"));
241 de8ed2a2 Jan Jirman
    }
242
243
    @Test
244
    public void testsetDateTo() {
245 17168608 Daniel Stuš
        dateTo = LocalDate.of(2019, 5, 30);
246
        bitmap.setDateTo(dateTo);
247
    	assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-30"));
248 de8ed2a2 Jan Jirman
    }
249
250
    @Test
251
    public void testgetLineNumber() {
252
    	assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143440"));   
253
    }
254
255
    @Test
256
    public void testsetLineNumber() {
257
    	bitmap.setLineNumber("143441");
258
    	assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143441"));  
259
    }
260
261
    @Test
262
    public void testgetBitmap() {
263
    	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};
264
    	assertArrayEquals(array, bitmap.getBitmap());
265
    }
266
267
    @Test
268
    public void testsetBitmap() {
269
    	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};
270
    	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};
271
    	bitmap.setBitmap(newBitmap);
272
    	assertArrayEquals(array, bitmap.getBitmap());
273
        this.bitmap = bitmap;
274
    }
275
   
276
    @Test
277
    public void testtoString() {
278 17168608 Daniel Stuš
    	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]"));
279 de8ed2a2 Jan Jirman
    }
280
    
281
    
282
}