Projekt

Obecné

Profil

Stáhnout (6.45 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
6 17168608 Daniel Stuš
import java.time.DayOfWeek;
7
import java.time.LocalDate;
8
import java.util.ArrayList;
9 de8ed2a2 Jan Jirman
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 17168608 Daniel Stuš
    private static LocalDate dateFrom;
27
    private static LocalDate dateTo;
28 de8ed2a2 Jan Jirman
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 17168608 Daniel Stuš
        dateFrom = LocalDate.of(2019, 5, 1);
41
        dateTo = LocalDate.of(2019, 5, 31);
42 de8ed2a2 Jan Jirman
43 17168608 Daniel Stuš
        bitmap = new Bitmap(dateFrom, dateTo, "143440","1","34", "5", "1");
44 de8ed2a2 Jan Jirman
    
45
    }
46
47
 
48
    @Test
49
    public void testgetDateRange(){
50
       assertEquals(31,bitmap.getDateRange());
51
    }
52
    
53
    @Test
54
    public void testsetDay() {
55 17168608 Daniel Stuš
    	LocalDate date = LocalDate.of(2019, 5, 3);
56 de8ed2a2 Jan Jirman
    	bitmap.setDay(date, 1);
57 17168608 Daniel Stuš
    	date = LocalDate.of(2019, 5, 4);
58 de8ed2a2 Jan Jirman
    	bitmap.setDay(date, 1);
59 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]"));
60 de8ed2a2 Jan Jirman
    }
61
    
62
    @Test
63
    public void testgetDatePosition() {
64 17168608 Daniel Stuš
    	LocalDate date = LocalDate.of(2019, 5, 3);
65 de8ed2a2 Jan Jirman
    	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 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]"));
75 de8ed2a2 Jan Jirman
    }
76
    
77
    @Test
78
    public void testsetSundaysAndHolidays() {
79
    	bitmap.setSundaysAndHolidays(1);
80 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]"));
81 de8ed2a2 Jan Jirman
    }
82
    
83
    
84
    @Test
85
    public void testsetOneDayOnly() {
86 17168608 Daniel Stuš
    	LocalDate date = LocalDate.of(2019, 5, 3);
87 de8ed2a2 Jan Jirman
    	bitmap.setOneDayOnly(date);
88 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]"));
89 de8ed2a2 Jan Jirman
   
90
    }
91
    
92
    @Test
93
    public void testsetDaysInRange() {
94 17168608 Daniel Stuš
    	LocalDate date1 = LocalDate.of(2019, 5, 3);
95
    	LocalDate date2 = LocalDate.of(2019,5,5);
96 de8ed2a2 Jan Jirman
    	bitmap.setDaysInRange(date1,date2, 1);
97 7cafefe1 Daniel Stuš
    	// Opravdu chyba (poslední den včetně) - Opraveno
98 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]"));
99 de8ed2a2 Jan Jirman
    }
100
    
101
    @Test
102
    public void testsetDaysInWeek(){
103 17168608 Daniel Stuš
    	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 de8ed2a2 Jan Jirman
    	
106
    }
107
    
108
    @Test
109
    public void testsetWeeks(){
110
    	bitmap.setWeeks(1, 1);
111 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]"));
112 de8ed2a2 Jan Jirman
    	
113
    }
114
    
115
    @Test
116 17168608 Daniel Stuš
    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 de8ed2a2 Jan Jirman
    
122
    }
123
    
124
    @Test
125
    public void testfillWithZeros(){
126
    	bitmap.fillWithZeros();
127 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]"));
128 de8ed2a2 Jan Jirman
    	
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 17168608 Daniel Stuš
147
148 de8ed2a2 Jan Jirman
    @Test
149
    public void testgetDateFrom(){
150 17168608 Daniel Stuš
    	assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-01"));
151 de8ed2a2 Jan Jirman
    }
152
    
153
    @Test
154
    public void testsetDateFrom(){
155 17168608 Daniel Stuš
        dateFrom = LocalDate.of(2019, 5, 2);
156
        bitmap.setDateFrom(dateFrom);
157
    	assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-02"));
158 de8ed2a2 Jan Jirman
    }
159
    
160
    @Test
161
    public void testgetDateTo() {
162 17168608 Daniel Stuš
    	assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-31"));
163 de8ed2a2 Jan Jirman
    }
164
165
    @Test
166
    public void testsetDateTo() {
167 17168608 Daniel Stuš
        dateTo = LocalDate.of(2019, 5, 30);
168
        bitmap.setDateTo(dateTo);
169
    	assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-30"));
170 de8ed2a2 Jan Jirman
    }
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 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]"));
201 de8ed2a2 Jan Jirman
    }
202
    
203
    
204
}