Skip to content

Commit c926893

Browse files
committed
Improve tests
1 parent 6a7e95d commit c926893

File tree

2 files changed

+82
-30
lines changed

2 files changed

+82
-30
lines changed

src/test/TestEntropyCodec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
#include <iostream>
1716
#include <algorithm>
17+
#include <iostream>
1818
#include <time.h>
19+
#include <vector>
1920
#include "../types.hpp"
2021
#include "../entropy/HuffmanEncoder.hpp"
2122
#include "../entropy/RangeEncoder.hpp"

src/test/TestTransforms.cpp

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
*/
1515

16-
#include <iostream>
1716
#include <algorithm>
17+
#include <iostream>
1818
#include <time.h>
1919
#include "../types.hpp"
2020
#include "../transform/AliasCodec.hpp"
@@ -89,11 +89,15 @@ int testTransformsCorrectness(const string& name)
8989
int mod = (name == "ZRLT") ? 5 : 256;
9090
int res = 0;
9191

92-
for (int ii = 0; ii < 50; ii++) {
92+
for (int ii = 0; ii < 51; ii++) {
9393
cout << endl
9494
<< "Test " << ii << endl;
95-
int size = 80000;
96-
byte values[80000] = { byte(0xAA) };
95+
int size; // Declare size, will be set in conditions
96+
byte values[1024 * 1024] = { byte(0xAA) };
97+
98+
if (ii != 50) {
99+
size = 80000;
100+
}
97101

98102
if (name == "ALIAS")
99103
mod = 15 + 12 * ii;
@@ -109,7 +113,16 @@ int testTransformsCorrectness(const string& name)
109113

110114
memcpy(values, &arr[0], size);
111115
}
112-
else if (ii == 1) {
116+
else if (ii < 10) {
117+
size = ii;
118+
memset(values, ii, size);
119+
}
120+
else if (ii == 10) {
121+
size = 255;
122+
memset(values, ii, size);
123+
values[127] = 255;
124+
}
125+
else if (ii == 11) {
113126
size = 80000;
114127
byte arr[80000];
115128
arr[0] = byte(1);
@@ -119,12 +132,12 @@ int testTransformsCorrectness(const string& name)
119132

120133
memcpy(values, &arr[0], size);
121134
}
122-
else if (ii == 2) {
135+
else if (ii == 12) {
123136
size = 8;
124137
byte arr[8] = { (byte)0, (byte)0, (byte)1, (byte)1, (byte)2, (byte)2, (byte)3, (byte)3 };
125138
memcpy(values, &arr[0], size);
126139
}
127-
else if (ii == 3) {
140+
else if (ii == 13) {
128141
// For RLT
129142
size = 512;
130143
byte arr[512];
@@ -137,7 +150,7 @@ int testTransformsCorrectness(const string& name)
137150
arr[1] = byte(255); // force RLT escape to be first symbol
138151
memcpy(values, &arr[0], size);
139152
}
140-
else if (ii == 4) {
153+
else if (ii == 14) {
141154
// Lots of zeros
142155
size = 1024;
143156
byte arr[1024] = { byte(0) };
@@ -153,7 +166,7 @@ int testTransformsCorrectness(const string& name)
153166

154167
memcpy(values, &arr[0], size);
155168
}
156-
else if (ii == 5) {
169+
else if (ii == 15) {
157170
// Lots of zeros
158171
size = 2048;
159172
byte arr[2048] = { byte(0) };
@@ -169,7 +182,7 @@ int testTransformsCorrectness(const string& name)
169182

170183
memcpy(values, &arr[0], size);
171184
}
172-
else if (ii == 6) {
185+
else if (ii == 16) {
173186
// Totally random
174187
size = 512;
175188
byte arr[512] = { byte(0) };
@@ -180,7 +193,7 @@ int testTransformsCorrectness(const string& name)
180193

181194
memcpy(values, &arr[0], size);
182195
}
183-
else if (ii < 10) {
196+
else if (ii < 25) {
184197
size = 2048;
185198
byte arr[2048] = { byte(0) };
186199
const int step = max(ii - 5, 2);
@@ -193,10 +206,21 @@ int testTransformsCorrectness(const string& name)
193206
for (int j = 64; j + step < size; j += step) {
194207
for (int k = 0; k < step; k++)
195208
arr[j + k] = arr[j + k - step];
196-
}
209+
}
197210

198211
memcpy(values, &arr[0], size);
199212
}
213+
else if (ii == 50) {
214+
cout << "Large random data" << endl;
215+
size = 1024 * 1024;
216+
byte* arr = new byte[size];
217+
218+
for (int i = 0; i < size; i++)
219+
arr[i] = byte(rand() % 256);
220+
221+
memcpy(values, arr, size);
222+
delete[] arr;
223+
}
200224
else {
201225
size = 1024;
202226
byte arr[1024] = { byte(0) };
@@ -241,6 +265,7 @@ int testTransformsCorrectness(const string& name)
241265
byte* input = new byte[size];
242266
byte* output = new byte[dstSize];
243267
byte* reverse = new byte[size];
268+
244269
SliceArray<byte> iba1(input, size, 0);
245270
SliceArray<byte> iba2(output, dstSize, 0);
246271
SliceArray<byte> iba3(reverse, size, 0);
@@ -258,8 +283,13 @@ int testTransformsCorrectness(const string& name)
258283
cout << "1 8 (" << (size - 1) << " times)";
259284
}
260285
else {
261-
for (int i = 0; i < size; i++)
262-
cout << (int(input[i]) & 0xFF) << " ";
286+
if (size > 1024) {
287+
cout << "Large data block - not printing all values.";
288+
}
289+
else {
290+
for (int i = 0; i < size; i++)
291+
cout << (int(input[i]) & 0xFF) << " ";
292+
}
263293
}
264294

265295
if (ff->forward(iba1, iba2, size) == false) {
@@ -297,8 +327,13 @@ int testTransformsCorrectness(const string& name)
297327
cout << endl;
298328
cout << "Coded: " << endl;
299329

300-
for (int i = 0; i < iba2._index; i++)
301-
cout << (int(output[i]) & 0xFF) << " ";
330+
if (iba2._index > 1024) {
331+
cout << "Large data block - not printing all values.";
332+
}
333+
else {
334+
for (int i = 0; i < iba2._index; i++)
335+
cout << (int(output[i]) & 0xFF) << " ";
336+
}
302337

303338
cout << " (Compression ratio: " << (iba2._index * 100 / size) << "%)" << endl;
304339
count = iba2._index;
@@ -318,8 +353,13 @@ int testTransformsCorrectness(const string& name)
318353
cout << "1 8 (" << (size - 1) << " times)";
319354
}
320355
else {
321-
for (int i = 0; i < size; i++)
322-
cout << (int(reverse[i]) & 0xFF) << " ";
356+
if (size > 1024) {
357+
cout << "Large data block - not printing all values.";
358+
}
359+
else {
360+
for (int i = 0; i < size; i++)
361+
cout << (int(reverse[i]) & 0xFF) << " ";
362+
}
323363
}
324364

325365
cout << endl;
@@ -430,9 +470,10 @@ int testTransformsSpeed(const string& name)
430470
delete ff;
431471
}
432472

473+
int count = iba2._index;
474+
433475
for (int ii = 0; ii < iter; ii++) {
434476
Transform<byte>* fi = getByteTransform(name, ctx);
435-
int count = iba2._index;
436477
iba3._index = 0;
437478
iba2._index = 0;
438479
before = clock();
@@ -504,7 +545,14 @@ int TestTransforms_main(int argc, const char* argv[])
504545
string str = argv[1];
505546
transform(str.begin(), str.end(), str.begin(), ::toupper);
506547

507-
if (str == "-TYPE=ALL") {
548+
if (str != "-TYPE=ALL") {
549+
codecs.push_back(str.substr(6));
550+
551+
if (str.compare(0, 6, "-TYPE=") != 0) {
552+
cout << "Missing transform type" << endl;
553+
return 1;
554+
}
555+
} else {
508556
#if __cplusplus < 201103L
509557
string allCodecs[13] = { "LZ", "LZX", "LZP", "ROLZ", "ROLZX", "RLT", "ZRLT", "RANK", "SRT", "NONE", "ALIAS", "MM", "MTFT" };
510558

@@ -514,9 +562,6 @@ int TestTransforms_main(int argc, const char* argv[])
514562
codecs = { "LZ", "LZX", "LZP", "ROLZ", "ROLZX", "RLT", "ZRLT", "RANK", "SRT", "NONE", "ALIAS", "MM", "MTFT" };
515563
#endif
516564
}
517-
else {
518-
codecs.push_back(str.substr(6));
519-
}
520565

521566
if (argc > 2) {
522567
str = argv[2];
@@ -527,12 +572,19 @@ int TestTransforms_main(int argc, const char* argv[])
527572

528573
for (vector<string>::iterator it = codecs.begin(); it != codecs.end(); ++it) {
529574
cout << endl
530-
<< endl
531-
<< "Test" << *it << endl;
532-
res |= testTransformsCorrectness(*it);
575+
<< endl
576+
<< "Test" << *it << endl;
577+
res = testTransformsCorrectness(*it);
533578

534-
if ((doPerf == true) && (*it != "LZP") && (*it != "MM")) // skip codecs with no good data
535-
res |= testTransformsSpeed(*it);
579+
if (res)
580+
break;
581+
582+
if ((doPerf == true) && (*it != "LZP") && (*it != "MM")) { // skip codecs with no good data
583+
res = testTransformsSpeed(*it);
584+
585+
if (res)
586+
break;
587+
}
536588
}
537589

538590
}
@@ -546,4 +598,3 @@ int TestTransforms_main(int argc, const char* argv[])
546598
return res;
547599
}
548600

549-

0 commit comments

Comments
 (0)