test map from uint to values of type double
1 version(showAssertTags) dbg(); 2 alias Key = uint; 3 alias Value = uint; 4 5 auto map = radixTreeMap!(Key, Value); 6 assert(map.empty); 7 8 static assert(map.hasValue); 9 10 static Value keyToValue(Key key) @safe pure nothrow @nogc { return cast(Value)((key + 1)*radix); } 11 12 foreach (immutable i; 0 .. SparseLeaf1!Value.maxCapacity) 13 { 14 assert(!map.contains(i)); 15 assert(map.length == i); 16 map[i] = keyToValue(i); 17 assert(map.contains(i)); 18 assert(*map.contains(i) == keyToValue(i)); 19 assert(i in map); 20 assert(*(i in map) == keyToValue(i)); 21 assert(map.length == i + 1); 22 } 23 24 foreach (immutable i; SparseLeaf1!Value.maxCapacity .. radix) 25 { 26 assert(!map.contains(i)); 27 assert(map.length == i); 28 map[i] = keyToValue(i); 29 assert(map.contains(i)); 30 assert(*map.contains(i) == keyToValue(i)); 31 assert(i in map); 32 assert(*(i in map) == keyToValue(i)); 33 assert(map.length == i + 1); 34 } 35 36 void testRange() @trusted 37 { 38 size_t i = 0; 39 foreach (immutable keyValue; map[]) 40 { 41 assert(keyValue.key == i); 42 assert(keyValue.value == keyToValue(cast(Key)i)); // TODO: use typed key instead of cast(Key) 43 ++i; 44 } 45 } 46 47 testRange();
Calculate and print statistics of tree.