1 #include <iostream>
2 #include <stdint.h>
3 #include <stdlib.h>
4 
5 #include "judyL2Array.h"
6 typedef judyL2Array< uint64_t, uint64_t > jl2a;
7 
testFind(jl2a & j,uint64_t key,unsigned int count)8 bool testFind( jl2a & j, uint64_t key, unsigned int count ) {
9     jl2a::cvector * v = j.find( key );
10     std::cout << "find: key " << key << " ..." << std::endl;
11     if( count > 0 ) {
12         if( !v || !j.success() || ( v->size() != count ) ) {
13             std::cout << "    false negative - v: " << v << " success: " << j.success();
14             if( v ) {
15                 std::cout << "    expected count: " << count << " actual: " << v->size();
16             }
17             std::cout << std::endl;
18             return false;
19         } else {
20             // note - this doesn't verify that the right keys are returned, just the right number!
21             jl2a::vector::const_iterator it = v->begin();
22             std::cout << "    correct number of values -";
23             for( ; it != v->end(); it++ ) {
24                 std::cout << " " << *it;
25             }
26             std::cout << std::endl;
27         }
28     } else {
29         if( v || j.success() ) {
30             std::cout << "    false positive - v: " << v << " success: " << j.success() << std::endl;
31             return false;
32         } else {
33             std::cout << "    not found, as expected." << std::endl;
34         }
35     }
36     return true;
37 }
38 
main()39 int main() {
40     bool pass = true;
41     jl2a jl;
42     std::cout.setf( std::ios::boolalpha );
43 //     std::cout << "size of judyL2Array: " << sizeof( jl ) << std::endl;
44     jl.insert( 5,  12 );
45     jl.insert( 6,  2 );
46     jl.insert( 7,  312 );
47     jl.insert( 11, 412 );
48     jl.insert( 7,  313 );
49     jl2a::cpair kv = jl.atOrAfter( 4 );
50     std::cout << "atOrAfter test ..." << std::endl;
51     if( kv.value != 0 && jl.success() ) {
52         std::cout << "    key " << kv.key << "    value " << kv.value->at( 0 ) << std::endl;
53     } else {
54         std::cout << "    failed" << std::endl;
55         pass = false;
56     }
57 
58     pass &= testFind( jl, 8,  0 );
59     pass &= testFind( jl, 11, 1 );
60     pass &= testFind( jl, 7,  2 );
61 
62     jl.clear();
63 
64     //TODO test all of judyL2Array
65     if( pass ) {
66         std::cout << "All tests passed." << std::endl;
67         exit( EXIT_SUCCESS );
68     } else {
69         std::cout << "At least one test failed." << std::endl;
70         exit( EXIT_FAILURE );
71     }
72 }