conditioning_class.h 28.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2003  Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License   See LICENSE.txt for the full license.
#ifndef DLIB_TEST_CONDITIONING_CLASs_H_
#define DLIB_TEST_CONDITIONING_CLASs_H_


#include <sstream>
#include <string>
#include <ctime>
#include <cstdlib>

#include <dlib/conditioning_class.h>

#include "tester.h"

namespace  
{

    using namespace test;
    using namespace std;
    using namespace dlib;

    logger dlog("test.conditioning_class");

    template <
        typename cc,
        typename cc2
        >
    void conditioning_class_kernel_test (
    )
    /*!
        requires
            - cc is an implementation of conditioning_class/conditioning_class_kernel_abstract.h            
              the alphabet_size for cc is 256
            - cc2 is an implementation of conditioning_class/conditioning_class_kernel_abstract.h            
              the alphabet_size for cc2 is 2
        ensures
            - runs tests on cc for compliance with the specs 
    !*/
    {        

        srand(static_cast<unsigned int>(time(0)));



        typename cc::global_state_type gs;
        typename cc2::global_state_type gs2;




        for (int g = 0; g < 2; ++g)
        {
            print_spinner();
            unsigned long amount=g+1;
            cc2 test(gs2);
            cc2 test2(gs2);


60
            DLIB_TEST(test.get_memory_usage() != 0);
61
62
63
64

            const unsigned long alphabet_size = 2;                


65
            DLIB_TEST(test.get_total() == 1);
66

67
            DLIB_TEST(test.get_count(alphabet_size-1)==1);
68
69
70
            for (unsigned long i = 0; i < alphabet_size-1; ++i)
            {
                unsigned long low_count, high_count, total_count;
71
72
73
                DLIB_TEST_MSG(test.get_range(i,low_count,high_count,total_count) == 0,i);
                DLIB_TEST(test.get_count(i) == 0);
                DLIB_TEST(test.get_total() == 1);
74
75
76
77
78
79
80
81
82
83
84
            }



            for (unsigned long i = 0; i < alphabet_size; ++i)
            {
                test.increment_count(i,static_cast<unsigned short>(amount));
                unsigned long low_count = 0, high_count = 0, total_count = 0;

                if (i ==alphabet_size-1)
                {
85
                    DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == 1+amount);
86

87
88
                    DLIB_TEST(high_count == low_count+1+amount);
                    DLIB_TEST(total_count == test.get_total());
89
90


91
                    DLIB_TEST(test.get_count(i) == 1+amount);
92
93
94
                }
                else
                {
95
                    DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == amount);
96

97
98
                    DLIB_TEST(high_count == low_count+amount);
                    DLIB_TEST(total_count == test.get_total());
99
100


101
                    DLIB_TEST(test.get_count(i) == amount);
102
                }
103
                DLIB_TEST(test.get_total() == (i+1)*amount + 1);
104
105
106
107
108
109
110
111
112
113
114
            } 


            for (unsigned long i = 0; i < alphabet_size; ++i)
            {                
                unsigned long temp = static_cast<unsigned long>(::rand()%40);
                for (unsigned long j = 0; j < temp; ++j)
                {
                    test.increment_count(i,static_cast<unsigned short>(amount));
                    if (i == alphabet_size-1)
                    {
115
                        DLIB_TEST(test.get_count(i) == (j+1)*amount + 1 + amount);                    
116
117
118
                    }
                    else
                    {
119
                        DLIB_TEST(test.get_count(i) == (j+1)*amount + amount);                    
120
121
122
123
124
125
126
127
                    }
                }

                unsigned long target = test.get_total()/2;
                unsigned long symbol = i, low_count = 0, high_count = 0, total_count = 0;

                if (i == alphabet_size-1)
                {
128
129
                    DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==temp*amount+1+amount);
                    DLIB_TEST(high_count-low_count == temp*amount+1+amount);
130
131
132
                }
                else
                {
133
134
                    DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==temp*amount + amount);
                    DLIB_TEST(high_count-low_count == temp*amount + amount);
135
                }
136
                DLIB_TEST(total_count == test.get_total());
137
138

                test.get_symbol(target,symbol,low_count,high_count);
139
140
141
142
                DLIB_TEST(test.get_count(symbol) == high_count-low_count);
                DLIB_TEST(low_count <= target);
                DLIB_TEST(target < high_count);
                DLIB_TEST(high_count <= test.get_total());
143
144
145
146
147
148
149
150
151
152

            }

            test.clear();


            for (unsigned long i = 0; i < alphabet_size-1; ++i)
            {
                test.increment_count(i);
                unsigned long low_count, high_count, total_count;
153
                DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == 1);
154

155
156
                DLIB_TEST(high_count == low_count+1);
                DLIB_TEST(total_count == test.get_total());
157

158
159
                DLIB_TEST(test.get_count(i) == 1);
                DLIB_TEST(test.get_total() == i+2);
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
            } 




            unsigned long counts[alphabet_size];


            print_spinner();
            for (int k = 0; k < 10; ++k)
            {
                unsigned long range = ::rand()%50000 + 2;

                test.clear();

                for (unsigned long i = 0; i < alphabet_size-1; ++i)
                    counts[i] = 0;
                unsigned long total = 1;
                counts[alphabet_size-1] = 1;


                for (unsigned long i = 0; i < alphabet_size; ++i)
                {                
                    unsigned long temp = static_cast<unsigned long>(::rand()%range);
                    for (unsigned long j = 0; j < temp; ++j)
                    {
                        test.increment_count(i);  


                        if (total >= 65535)
                        {
                            total = 0;
                            for (unsigned long i = 0; i < alphabet_size; ++i)
                            {
                                counts[i] >>= 1;
                                total += counts[i];
                            }
                            if (counts[alphabet_size-1]==0)
                            {
                                counts[alphabet_size-1] = 1;
                                ++total;
                            }
                        }
                        counts[i] = counts[i] + 1;
                        ++total;


                    }


                    unsigned long temp_total = 0;
                    for (unsigned long a = 0; a < alphabet_size; ++a)
                    {
                        temp_total += test.get_count(a);
                    }
215
                    DLIB_TEST_MSG(temp_total == test.get_total(),
216
217
218
219
                                 "temp_total == " << temp_total << endl <<
                                 "test.get_total() == " << test.get_total()
                    );

220
221
                    DLIB_TEST(test.get_count(alphabet_size-1) == counts[alphabet_size-1]);
                    DLIB_TEST_MSG(test.get_total() == total,
222
223
224
225
226
227
228
229
                                 "test.get_total() == " << test.get_total() << endl <<
                                 "total == " << total
                    );

                    unsigned long target = test.get_total()/2;
                    unsigned long symbol = i, low_count = 0, high_count = 0, total_count = 0;


230
                    DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==counts[symbol]);
231
232
233

                    if (counts[symbol] != 0)
                    {
234
                        DLIB_TEST(total_count == total);
235

236
237
238
239
                        DLIB_TEST(high_count <= total);
                        DLIB_TEST(low_count < high_count);
                        DLIB_TEST(high_count <= test.get_total());
                        DLIB_TEST(test.get_count(symbol) == high_count-low_count);
240
241
242
243
244
245
246
247
                    }


                    if (target < total)
                    {
                        test.get_symbol(target,symbol,low_count,high_count);


248
249
250
251
252
                        DLIB_TEST(high_count <= total);
                        DLIB_TEST(low_count < high_count);
                        DLIB_TEST(high_count <= test.get_total());
                        DLIB_TEST(test.get_count(symbol) == high_count-low_count);
                        DLIB_TEST(test.get_count(symbol) == counts[symbol]);
253
254
255
256
257
258
259
260
261
262
263
264
265
266
                    }




                }

            }

            print_spinner();

            for (unsigned long h = 0; h < 10; ++h)
            {
                test.clear();
267
                DLIB_TEST(test.get_total() == 1);
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288

                // fill out test with some numbers
                unsigned long temp = ::rand()%30000 + 50000;
                for (unsigned long j = 0; j < temp; ++j)
                {
                    unsigned long symbol = (unsigned long)::rand()%alphabet_size;
                    test.increment_count(symbol);                    
                }

                // make sure all symbols have a count of at least one
                for (unsigned long j = 0; j < alphabet_size; ++j)
                {   
                    if (test.get_count(j) == 0)
                        test.increment_count(j);
                }

                unsigned long temp_total = 0;
                for (unsigned long j = 0; j < alphabet_size; ++j)
                {
                    temp_total += test.get_count(j);
                }
289
                DLIB_TEST(temp_total == test.get_total());
290
291
292
293
294
295
296
297
298


                unsigned long low_counts[alphabet_size];
                unsigned long high_counts[alphabet_size];
                // iterate over all the symbols
                for (unsigned long j = 0; j < alphabet_size; ++j)
                {
                    unsigned long total;
                    unsigned long count = test.get_range(j,low_counts[j],high_counts[j],total);
299
300
                    DLIB_TEST(count == test.get_count(j));
                    DLIB_TEST(count == high_counts[j] - low_counts[j]);
301
302
303
304
305
306
307
308
309
310
311

                }


                // make sure get_symbol() matches what get_range() told us
                for (unsigned long j = 0; j < alphabet_size; ++j)
                {                    
                    for (unsigned long k = low_counts[j]; k < high_counts[j]; ++k)
                    {
                        unsigned long symbol, low_count, high_count;
                        test.get_symbol(k,symbol,low_count,high_count);
312
313
                        DLIB_TEST(high_count - low_count == test.get_count(symbol));
                        DLIB_TEST_MSG(j == symbol,
314
315
316
317
318
319
320
321
322
323
324
                                     "j == " << j << endl <<
                                     "k == " << k << endl <<
                                     "symbol == " << symbol << endl <<
                                     "low_counts[j] == " << low_counts[j] << endl <<
                                     "high_counts[j] == " << high_counts[j] << endl <<
                                     "low_counts[symbol] == " << low_counts[symbol] << endl <<
                                     "high_counts[symbol] == " << high_counts[symbol] << endl << 
                                     "low_count == " << low_count << endl << 
                                     "high_count == " << high_count << endl << 
                                     "temp.count(j) == " << test.get_count(j)
                        );
325
                        DLIB_TEST_MSG(low_count == low_counts[j],
326
327
328
329
                                     "symbol:        " << j << "\n" <<
                                     "target:        " << k << "\n" <<
                                     "low_count:     " << low_count << "\n" <<
                                     "low_counts[j]: " << low_counts[j]);
330
                        DLIB_TEST(high_count == high_counts[j]);
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
                    }

                }

            }



            print_spinner();

            for (int h = 0; h < 10; ++h)
            {


                test.clear();

                for (unsigned long k = 0; k < alphabet_size-1; ++k)
                {
                    counts[k] = 0;
                }
                counts[alphabet_size-1] = 1;
                unsigned long total = 1;
                unsigned long i = ::rand()%alphabet_size;

                unsigned long temp = 65536;
                for (unsigned long j = 0; j < temp; ++j)
                {
                    test.increment_count(i);  


                    if (total >= 65535)
                    {
                        total = 0;
                        for (unsigned long i = 0; i < alphabet_size; ++i)
                        {
                            counts[i] >>= 1;
                            total += counts[i];
                        }
                        if (counts[alphabet_size-1] == 0)
                        {
                            ++total;
                            counts[alphabet_size-1] = 1;
                        }
                    }
                    counts[i] = counts[i] + 1;
                    ++total;

                }


381
                DLIB_TEST(test.get_total() == total);
382
383
384
385
386

                unsigned long target = test.get_total()/2;
                unsigned long symbol = i, low_count = 0, high_count = 0, total_count = 0;


387
                DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==counts[symbol]);
388
389
390

                if (counts[symbol] != 0)
                {
391
                    DLIB_TEST(total_count == total);
392

393
394
395
396
                    DLIB_TEST(high_count <= total);
                    DLIB_TEST(low_count < high_count);
                    DLIB_TEST(high_count <= test.get_total());
                    DLIB_TEST(test.get_count(symbol) == high_count-low_count);
397
398
399
400
401
402
403
                }



                test.get_symbol(target,symbol,low_count,high_count);


404
405
406
407
408
                DLIB_TEST(high_count <= total);
                DLIB_TEST(low_count < high_count);
                DLIB_TEST(high_count <= test.get_total());
                DLIB_TEST(test.get_count(symbol) == high_count-low_count);
                DLIB_TEST(test.get_count(symbol) == counts[symbol]);
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438







            }

        } // for (int g = 0; g < 2; ++g)













        for (int g = 0; g < 2; ++g)
        {
            print_spinner();
            unsigned long amount=g+1;
            cc test(gs);
            cc test2(gs);

439
            DLIB_TEST(test.get_memory_usage() != 0);
440
441
442
443

            const unsigned long alphabet_size = 256;                


444
            DLIB_TEST(test.get_total() == 1);
445

446
            DLIB_TEST(test.get_count(alphabet_size-1)==1);
447
448
449
            for (unsigned long i = 0; i < alphabet_size-1; ++i)
            {
                unsigned long low_count, high_count, total_count;
450
451
452
                DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == 0);
                DLIB_TEST(test.get_count(i) == 0);
                DLIB_TEST(test.get_total() == 1);
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
            }


            bool oom = false;
            for (unsigned long i = 0; i < alphabet_size; ++i)
            {
                bool status = test.increment_count(i,static_cast<unsigned short>(amount));
                unsigned long low_count = 0, high_count = 0, total_count = 0;
                if (!status)
                    oom = true;

                if (status)
                {
                    if (i ==alphabet_size-1)
                    {
468
                        DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == 1+amount);
469

470
471
                        DLIB_TEST(high_count == low_count+1+amount);
                        DLIB_TEST(total_count == test.get_total());
472
473


474
                        DLIB_TEST(test.get_count(i) == 1+amount);
475
476
477
                    }
                    else
                    {
478
                        DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == amount);
479

480
481
                        DLIB_TEST(high_count == low_count+amount);
                        DLIB_TEST(total_count == test.get_total());
482
483


484
                        DLIB_TEST(test.get_count(i) == amount);
485
486
                    }
                    if (!oom)
487
                        DLIB_TEST(test.get_total() == (i+1)*amount + 1);
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
                }
            } 


            oom = false;
            for (unsigned long i = 0; i < alphabet_size; ++i)
            {        
                unsigned long temp = static_cast<unsigned long>(::rand()%40);
                for (unsigned long j = 0; j < temp; ++j)
                {
                    bool status = test.increment_count(i,static_cast<unsigned short>(amount));
                    if (!status)
                        oom = true;
                    if (status)
                    {
                        if (i == alphabet_size-1)
                        {
505
                            DLIB_TEST(test.get_count(i) == (j+1)*amount + 1 + amount);                    
506
507
508
                        }
                        else
                        {
509
                            DLIB_TEST(test.get_count(i) == (j+1)*amount + amount);                    
510
511
512
513
514
515
516
517
518
519
520
                        }
                    }
                }

                unsigned long target = test.get_total()/2;
                unsigned long symbol = i, low_count = 0, high_count = 0, total_count = 0;

                if (!oom)
                {
                    if (i == alphabet_size-1)
                    {
521
522
                        DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==temp*amount+1+amount);
                        DLIB_TEST(high_count-low_count == temp*amount+1+amount);
523
524
525
                    }
                    else
                    {
526
527
                        DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==temp*amount + amount);
                        DLIB_TEST(high_count-low_count == temp*amount + amount);
528
                    }
529
                    DLIB_TEST(total_count == test.get_total());
530
531
532


                    test.get_symbol(target,symbol,low_count,high_count);
533
534
535
536
                    DLIB_TEST(test.get_count(symbol) == high_count-low_count);
                    DLIB_TEST(low_count <= target);
                    DLIB_TEST(target < high_count);
                    DLIB_TEST(high_count <= test.get_total());
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
                }

            }

            test.clear();


            oom = false;
            for (unsigned long i = 0; i < alphabet_size-1; ++i)
            {
                if(!test.increment_count(i))
                    oom = true;
                unsigned long low_count, high_count, total_count;

                if (!oom)
                {
553
                    DLIB_TEST(test.get_range(i,low_count,high_count,total_count) == 1);
554

555
556
                    DLIB_TEST(high_count == low_count+1);
                    DLIB_TEST(total_count == test.get_total());
557

558
559
                    DLIB_TEST(test.get_count(i) == 1);
                    DLIB_TEST(test.get_total() == i+2);
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
                }
            } 



            unsigned long counts[alphabet_size];


            for (int k = 0; k < 10; ++k)
            {
                unsigned long range = ::rand()%50000 + 2;

                test.clear();

                for (unsigned long i = 0; i < alphabet_size-1; ++i)
                    counts[i] = 0;
                unsigned long total = 1;
                counts[alphabet_size-1] = 1;


                oom = false;
                for (unsigned long i = 0; i < alphabet_size; ++i)
                {                
                    unsigned long temp = static_cast<unsigned long>(::rand()%range);
                    for (unsigned long j = 0; j < temp; ++j)
                    {
                        if (!test.increment_count(i))
                            oom = true;


                        if (total >= 65535)
                        {

                            total = 0;
                            for (unsigned long i = 0; i < alphabet_size; ++i)
                            {
                                counts[i] >>= 1;
                                total += counts[i];
                            }
                            if (counts[alphabet_size-1]==0)
                            {
                                counts[alphabet_size-1] = 1;
                                ++total;
                            }
                        }
                        counts[i] = counts[i] + 1;
                        ++total;


                    }


                    unsigned long temp_total = 0;
                    for (unsigned long a = 0; a < alphabet_size; ++a)
                    {
                        temp_total += test.get_count(a);
                    }

                    if (!oom)
                    {
620
                        DLIB_TEST_MSG(temp_total == test.get_total(),
621
622
623
624
                                     "temp_total == " << temp_total << endl <<
                                     "test.get_total() == " << test.get_total()
                        );

625
626
                        DLIB_TEST(test.get_count(alphabet_size-1) == counts[alphabet_size-1]);
                        DLIB_TEST_MSG(test.get_total() == total,
627
628
629
630
631
632
633
634
635
636
637
                                     "test.get_total() == " << test.get_total() << endl <<
                                     "total == " << total
                        );
                    }

                    unsigned long target = test.get_total()/2;
                    unsigned long symbol = i, low_count = 0, high_count = 0, total_count = 0;

                    if (!oom)
                    {

638
                        DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==counts[symbol]);
639
640
641

                        if (counts[symbol] != 0)
                        {
642
                            DLIB_TEST(total_count == total);
643

644
645
646
647
                            DLIB_TEST(high_count <= total);
                            DLIB_TEST(low_count < high_count);
                            DLIB_TEST(high_count <= test.get_total());
                            DLIB_TEST(test.get_count(symbol) == high_count-low_count);
648
649
650
651
652
653
654
655
                        }


                        if (target < total)
                        {
                            test.get_symbol(target,symbol,low_count,high_count);


656
657
658
659
660
                            DLIB_TEST(high_count <= total);
                            DLIB_TEST(low_count < high_count);
                            DLIB_TEST(high_count <= test.get_total());
                            DLIB_TEST(test.get_count(symbol) == high_count-low_count);
                            DLIB_TEST(test.get_count(symbol) == counts[symbol]);
661
662
663
664
665
666
667
668
669
670
671
672
673
                        }
                    }



                }

            }

            oom = false;
            for (unsigned long h = 0; h < 10; ++h)
            {
                test.clear();
674
                DLIB_TEST(test.get_total() == 1);
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697

                // fill out test with some numbers
                unsigned long temp = ::rand()%30000 + 50000;
                for (unsigned long j = 0; j < temp; ++j)
                {
                    unsigned long symbol = (unsigned long)::rand()%alphabet_size;
                    if (!test.increment_count(symbol))
                        oom = true;
                }

                // make sure all symbols have a count of at least one
                for (unsigned long j = 0; j < alphabet_size; ++j)
                {   
                    if (test.get_count(j) == 0)
                        test.increment_count(j);
                }

                unsigned long temp_total = 0;
                for (unsigned long j = 0; j < alphabet_size; ++j)
                {
                    temp_total += test.get_count(j);
                }
                if (!oom)
698
                    DLIB_TEST(temp_total == test.get_total());
699
700
701
702
703
704
705
706
707
708
709
710
711


                unsigned long low_counts[alphabet_size];
                unsigned long high_counts[alphabet_size];

                if (!oom)
                {

                    // iterate over all the symbols
                    for (unsigned long j = 0; j < alphabet_size; ++j)
                    {
                        unsigned long total;
                        unsigned long count = test.get_range(j,low_counts[j],high_counts[j],total);
712
713
                        DLIB_TEST(count == test.get_count(j));
                        DLIB_TEST(count == high_counts[j] - low_counts[j]);
714
715
716
717
718
719
720
721
722
723
724
725
726

                    }




                    // make sure get_symbol() matches what get_range() told us
                    for (unsigned long j = 0; j < alphabet_size; ++j)
                    {                    
                        for (unsigned long k = low_counts[j]; k < high_counts[j]; ++k)
                        {
                            unsigned long symbol, low_count, high_count;
                            test.get_symbol(k,symbol,low_count,high_count);
727
728
                            DLIB_TEST(high_count - low_count == test.get_count(symbol));
                            DLIB_TEST_MSG(j == symbol,
729
730
731
732
733
734
735
736
737
738
739
                                         "j == " << j << endl <<
                                         "k == " << k << endl <<
                                         "symbol == " << symbol << endl <<
                                         "low_counts[j] == " << low_counts[j] << endl <<
                                         "high_counts[j] == " << high_counts[j] << endl <<
                                         "low_counts[symbol] == " << low_counts[symbol] << endl <<
                                         "high_counts[symbol] == " << high_counts[symbol] << endl << 
                                         "low_count == " << low_count << endl << 
                                         "high_count == " << high_count << endl << 
                                         "temp.count(j) == " << test.get_count(j)
                            );
740
                            DLIB_TEST_MSG(low_count == low_counts[j],
741
742
743
744
                                         "symbol:        " << j << "\n" <<
                                         "target:        " << k << "\n" <<
                                         "low_count:     " << low_count << "\n" <<
                                         "low_counts[j]: " << low_counts[j]);
745
                            DLIB_TEST(high_count == high_counts[j]);
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
                        }

                    }
                }

            }




            for (int h = 0; h < 10; ++h)
            {


                test.clear();

                for (unsigned long k = 0; k < alphabet_size-1; ++k)
                {
                    counts[k] = 0;
                }
                counts[alphabet_size-1] = 1;
                unsigned long total = 1;
                unsigned long i = ::rand()%alphabet_size;

                unsigned long temp = 65536;
                for (unsigned long j = 0; j < temp; ++j)
                {
                    test.increment_count(i);  


                    if (total >= 65535)
                    {
                        total = 0;
                        for (unsigned long i = 0; i < alphabet_size; ++i)
                        {
                            counts[i] >>= 1;
                            total += counts[i];
                        }
                        if (counts[alphabet_size-1] == 0)
                        {
                            ++total;
                            counts[alphabet_size-1] = 1;
                        }
                    }
                    counts[i] = counts[i] + 1;
                    ++total;

                }


796
                DLIB_TEST(test.get_total() == total);
797
798
799
800
801

                unsigned long target = test.get_total()/2;
                unsigned long symbol = i, low_count = 0, high_count = 0, total_count = 0;


802
                DLIB_TEST(test.get_range(symbol,low_count,high_count,total_count)==counts[symbol]);
803
804
805

                if (counts[symbol] != 0)
                {
806
                    DLIB_TEST(total_count == total);
807

808
809
810
811
                    DLIB_TEST(high_count <= total);
                    DLIB_TEST(low_count < high_count);
                    DLIB_TEST(high_count <= test.get_total());
                    DLIB_TEST(test.get_count(symbol) == high_count-low_count);
812
813
814
815
816
817
818
                }



                test.get_symbol(target,symbol,low_count,high_count);


819
820
821
822
823
                DLIB_TEST(high_count <= total);
                DLIB_TEST(low_count < high_count);
                DLIB_TEST(high_count <= test.get_total());
                DLIB_TEST(test.get_count(symbol) == high_count-low_count);
                DLIB_TEST(test.get_count(symbol) == counts[symbol]);
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841







            }

        } // for (int g = 0; g < 2; ++g)


    }

}

#endif // DLIB_TEST_CONDITIONING_CLASs_H_