Projekt

Obecné

Profil

Stáhnout (9.48 KB) Statistiky
| Větev: | Revize:
1
package test;
2

    
3
import static org.junit.Assert.assertArrayEquals;
4
import static org.junit.Assert.assertEquals;
5
import static org.junit.Assert.assertTrue;
6

    
7
import java.time.DayOfWeek;
8
import java.time.LocalDate;
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

    
19
public class testBitmap {
20
	private static final Logger log = Logger.getLogger(testJDFCaskodyRecord.class);
21
    private static Bitmap bitmap;
22
    private static LocalDate dateFrom;
23
    private static LocalDate dateTo;
24
    private char[] hardCodesChar;
25

    
26
    @BeforeClass
27
    public static void setUpBeforeClass() {
28

    
29
        BasicConfigurator.configure();
30
        Logger.getRootLogger().setLevel(Level.INFO);
31
        
32
        
33
    
34
    }
35
    
36
    @Before
37
    public void setUpBefore() {
38

    
39
        dateFrom = LocalDate.of(2019, 5, 1);
40
        dateTo = LocalDate.of(2019, 5, 31);
41
        
42
       
43

    
44
        bitmap = new Bitmap(dateFrom, dateTo, "143440","1","34", "5", "1");
45
        hardCodesChar = bitmap.getHardCodes().toCharArray();
46
    
47
    }
48

    
49
 
50
    @Test
51
    public void testgetDateRange(){
52
       assertEquals(31,bitmap.getDateRange());
53
    }
54
    
55
    @Test
56
    public void testsetDay() {
57
    	LocalDate date = LocalDate.of(2019, 5, 3);
58
    	bitmap.setDay(date, 1);
59
    	date = LocalDate.of(2019, 5, 4);
60
    	bitmap.setDay(date, 1);
61
    	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
    }
63
    
64
    @Test
65
    public void testgetDatePosition() {
66
    	LocalDate date = LocalDate.of(2019, 5, 3);
67
    	long position = bitmap.getDatePosition(date);
68
    	assertEquals(2,position);
69
    	
70
    }
71
    
72
    @Test
73
    public void testsetWorkdays() {
74
    	bitmap.setWorkdays(1);
75
    	// Přidáný svátky
76
    	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
    }
78
    
79
    @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
    @Test
86
    public void testsetSundaysAndHolidays() {
87
    	bitmap.setSundaysAndHolidays(1);
88
    	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
    }
90
    
91
    @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
    
98
    @Test
99
    public void testsetOneDayOnly() {
100
    	LocalDate date = LocalDate.of(2019, 5, 3);
101
    	bitmap.setOneDayOnly(date);
102
    	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
   
104
    }
105
    
106
    @Test
107
    public void testsetDaysInRange() {
108
    	LocalDate date1 = LocalDate.of(2019, 5, 3);
109
    	LocalDate date2 = LocalDate.of(2019,5,5);
110
    	bitmap.setDaysInRange(date1,date2, 1);
111
    	// Opravdu chyba (poslední den včetně) - Opraveno
112
    	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
    }
114
    
115
    @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
    @Test
123
    public void testsetDaysInWeek(){
124
    	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
    	
127
    }
128
    
129
    @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
    @Test
136
    public void testsetWeeks(){
137
    	bitmap.setWeeks(1, 1);
138
    	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
    	
140
    }
141
    
142
    @Test
143
    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
    
149
    }
150
    
151
    @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
    @Test
203
    public void testfillWithZeros(){
204
    	bitmap.fillWithZeros();
205
    	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
    	
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

    
225

    
226
    @Test
227
    public void testgetDateFrom(){
228
    	assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-01"));
229
    }
230
    
231
    @Test
232
    public void testsetDateFrom(){
233
        dateFrom = LocalDate.of(2019, 5, 2);
234
        bitmap.setDateFrom(dateFrom);
235
    	assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-02"));
236
    }
237
    
238
    @Test
239
    public void testgetDateTo() {
240
    	assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-31"));
241
    }
242

    
243
    @Test
244
    public void testsetDateTo() {
245
        dateTo = LocalDate.of(2019, 5, 30);
246
        bitmap.setDateTo(dateTo);
247
    	assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-30"));
248
    }
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
    	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
    }
280
    
281
    
282
}
(1-1/5)