diff --git a/README.md b/README.md index f61ade2..5a07c50 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This module considers two keys as different if and only if they do not compare e ### Data Structure ### - {MinimumSubtrees, MaximumKeys, NumberKeyValues, Tree} + {MinimumSubtrees, MaximumKeys, NumberKeyValues, SortFunction, Tree} Tree is composed of nodes of the form @@ -34,7 +34,7 @@ Since the trees are always balanced, there is no need for a balance operation. ## DATA TYPES ## - b_tree() = {pos_integer(), pos_integer(), non_neg_integer(), tree()} + b_tree() = {pos_integer(), pos_integer(), non_neg_integer(), sort_function(), tree()} A general balanced tree. @@ -70,7 +70,17 @@ Types: Order = pos_integer() B-Tree = b_tree() -Returns a new empty b-tree. Order is defined as the maximum number of children nodes a non-leaf node may hold. The minimum value is 4. +Returns a new empty b-tree. Order is defined as the maximum number of children nodes a non-leaf node may hold. The minimum value is 4. The sort order of the key values is ascending. + +### empty (Order, Function) -> B-Tree ### + +Types: + + Order = pos_integer() + Function = fun((Key1, Key2) -> equal | greater | less) + B-Tree = b_tree() + +Returns a new empty b-tree. Order is defined as the maximum number of children nodes a non-leaf node may hold. The minimum value is 4. The sort order of the key values is defined by the given function, which takes two key values and returns one of the atoms **equal**, **greater** or **less**. ### enter (Key, Value, B-Tree1) -> B-Tree2 ### @@ -233,6 +243,24 @@ Types: Returns tuple {Key, Value}, where Key is the smallest key in B-Tree, and Value is the value associated with this key. Assumes that B-Tree is not empty. +### sort_ascending (Key_1, Key_2) -> equal | greater | less ### + +Types: + + Key_1 = Key_2 = any() + equal = greater = less = atom() + +Returns **greater** if Key_1 > Key_2, **less** if Key_1 < Key_2 and **equal** elsewise. + +### sort_dscending (Key_1, Key_2) -> equal | greater | less ### + +Types: + + Key_1 = Key_2 = any() + equal = greater = less = atom() + +Returns **less** if Key_1 > Key_2, **greater** if Key_1 < Key_2 and **equal** elsewise. + ### take_largest (B-Tree1) -> {Key, Value, B-Tree2} ### Types: diff --git a/include/b_trees_templates.hrl b/include/b_trees_templates.hrl index 30b5095..9e26c1d 100644 --- a/include/b_trees_templates.hrl +++ b/include/b_trees_templates.hrl @@ -13,14 +13,14 @@ -define(B_TREE_04_00, { - 2, 3, 0, + 2, 3, 0, sort_function, nil } ). -define(B_TREE_04_01, { - 2, 3, 1, + 2, 3, 1, sort_function, {1, 0, [{"k_01", "v_01"}], [] } } @@ -28,7 +28,7 @@ -define(B_TREE_04_02, { - 2, 3, 2, + 2, 3, 2, sort_function, {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], [] } } @@ -36,7 +36,7 @@ -define(B_TREE_04_03, { - 2, 3, 3, + 2, 3, 3, sort_function, {3, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}], [] } } @@ -44,7 +44,7 @@ -define(B_TREE_04_04, { - 2, 3, 4, + 2, 3, 4, sort_function, {1, 2, [{"k_02", "v_02"}], [ {1, 0, [{"k_01", "v_01"}], []}, @@ -56,7 +56,7 @@ -define(B_TREE_04_05, { - 2, 3, 5, + 2, 3, 5, sort_function, {1, 2, [{"k_02", "v_02"}], [ {1, 0, [{"k_01", "v_01"}], []}, @@ -68,7 +68,7 @@ -define(B_TREE_04_06, { - 2, 3, 6, + 2, 3, 6, sort_function, {2, 3, [{"k_02", "v_02"}, {"k_04", "v_04"}], [ {1, 0, [{"k_01", "v_01"}], []}, @@ -81,7 +81,7 @@ -define(B_TREE_04_07, { - 2, 3, 7, + 2, 3, 7, sort_function, {2, 3, [{"k_02", "v_02"}, {"k_04", "v_04"}], [ {1, 0, [{"k_01", "v_01"}], []}, @@ -94,7 +94,7 @@ -define(B_TREE_04_08, { - 2, 3, 8, + 2, 3, 8, sort_function, {3, 4, [{"k_02", "v_02"}, {"k_04", "v_04"}, {"k_06", "v_06"}], [ {1, 0, [{"k_01", "v_01"}], []}, @@ -108,7 +108,7 @@ -define(B_TREE_04_09, { - 2, 3, 9, + 2, 3, 9, sort_function, {1, 2, [{"k_04", "v_04"}], [ {1, 2, [{"k_02", "v_02"}], @@ -130,7 +130,7 @@ -define(B_TREE_04_10, { - 2, 3, 10, + 2, 3, 10, sort_function, {1, 2, [{"k_04", "v_04"}], [ {1, 2, [{"k_02", "v_02"}], @@ -153,7 +153,7 @@ -define(B_TREE_04_10_MINUS_02, { - 2, 3, 9, + 2, 3, 9, sort_function, {1, 2, [{"k_06", "v_06"}], [ {1, 2, [{"k_04", "v_04"}], @@ -175,7 +175,7 @@ -define(B_TREE_04_11, { - 2, 3, 11, + 2, 3, 11, sort_function, {1, 2, [{"k_04", "v_04"}], [ {1, 2, [{"k_02", "v_02"}], @@ -198,7 +198,7 @@ -define(B_TREE_04_12, { - 2, 3, 12, + 2, 3, 12, sort_function, {1, 2, [{"k_04", "v_04"}], [ {1, 2, [{"k_02", "v_02"}], @@ -222,7 +222,7 @@ -define(B_TREE_04_13, { - 2, 3, 13, + 2, 3, 13, sort_function, {2, 3, [{"k_04", "v_04"}, {"k_08", "v_08"}], [ {1, 2, [{"k_02", "v_02"}], @@ -250,7 +250,7 @@ -define(B_TREE_04_14, { - 2, 3, 14, + 2, 3, 14, sort_function, {2, 3, [{"k_04", "v_04"}, {"k_08", "v_08"}], [ {1, 2, [{"k_02", "v_02"}], @@ -279,7 +279,7 @@ -define(B_TREE_04_15, { - 2, 3, 15, + 2, 3, 15, sort_function, {2, 3, [{"k_04", "v_04"}, {"k_08", "v_08"}], [ {1, 2, [{"k_02", "v_02"}], @@ -308,7 +308,7 @@ -define(B_TREE_04_15_UPDATE, { - 2, 3, 15, + 2, 3, 15, sort_function, {2, 3, [{"k_04", "v_04_new"}, {"k_08", "v_08_new"}], [ {1, 2, [{"k_02", "v_02_new"}], @@ -337,7 +337,7 @@ -define(B_TREE_04_16, { - 2, 3, 16, + 2, 3, 16, sort_function, {2, 3, [{"k_04", "v_04"}, {"k_08", "v_08"}], [ {1, 2, [{"k_02", "v_02"}], @@ -367,7 +367,7 @@ -define(B_TREE_04_17, { - 2, 3, 17, + 2, 3, 17, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}], [ {1, 2, [{"k_02", "v_02"}], @@ -401,7 +401,7 @@ -define(B_TREE_04_17_MINUS_02, { - 2, 3, 16, + 2, 3, 16, sort_function, {2, 3, [{"k_08", "v_08"}, {"k_12", "v_12"}], [ {2, 3, [{"k_04", "v_04"}, {"k_06", "v_06"}], @@ -430,7 +430,7 @@ -define(B_TREE_04_17_MINUS_02_04, { - 2, 3, 15, + 2, 3, 15, sort_function, {2, 3, [{"k_08", "v_08"}, {"k_12", "v_12"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -459,7 +459,7 @@ -define(B_TREE_04_17_MINUS_02_TILL_10, { - 2, 3, 12, + 2, 3, 12, sort_function, {1, 2, [{"k_12", "v_12"}], [ {2, 3, [{"k_03", "v_03"}, {"k_09", "v_09"}], @@ -482,7 +482,7 @@ -define(B_TREE_04_17_MINUS_02_TILL_12, { - 2, 3, 11, + 2, 3, 11, sort_function, {1, 2, [{"k_09", "v_09"}], [ {1, 2, [{"k_03", "v_03"}], @@ -504,7 +504,7 @@ -define(B_TREE_04_18, { - 2, 3, 18, + 2, 3, 18, sort_function, {1, 2, [{"k_08", "v_08"}], [ {1, 2, [{"k_04", "v_04"}], @@ -547,7 +547,7 @@ -define(B_TREE_04_19, { - 2, 3, 19, + 2, 3, 19, sort_function, {1, 2, [{"k_08", "v_08"}], [ {1, 2, [{"k_04", "v_04"}], @@ -590,7 +590,7 @@ -define(B_TREE_04_20, { - 2, 3, 20, + 2, 3, 20, sort_function, {1, 2, [{"k_08", "v_08"}], [ {1, 2, [{"k_04", "v_04"}], @@ -634,7 +634,7 @@ -define(B_TREE_04_20_MINUS_02, { - 2, 3, 19, + 2, 3, 19, sort_function, {2, 3, [{"k_08", "v_08"}, {"k_12", "v_12"}], [ {2, 3, [{"k_04", "v_04"}, {"k_06", "v_06"}], @@ -665,7 +665,7 @@ -define(B_TREE_04_20_MINUS_04, { - 2, 3, 19, + 2, 3, 19, sort_function, {2, 3, [{"k_08", "v_08"}, {"k_12", "v_12"}], [ {2, 3, [{"k_02", "v_02"}, {"k_06", "v_06"}], @@ -696,7 +696,7 @@ -define(B_TREE_04_20_MINUS_06, { - 2, 3, 19, + 2, 3, 19, sort_function, {2, 3, [{"k_04", "v_04"}, {"k_12", "v_12"}], [ {1, 2, [{"k_02", "v_02"}], @@ -727,7 +727,7 @@ -define(B_TREE_04_20_MINUS_08, { - 2, 3, 19, + 2, 3, 19, sort_function, {2, 3, [{"k_04", "v_04"}, {"k_12", "v_12"}], [ {1, 2, [{"k_02", "v_02"}], @@ -758,7 +758,7 @@ -define(B_TREE_04_20_MINUS_10, { - 2, 3, 19, + 2, 3, 19, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_14", "v_14"}], [ {1, 2, [{"k_02", "v_02"}], @@ -793,7 +793,7 @@ -define(B_TREE_04_20_MINUS_12, { - 2, 3, 19, + 2, 3, 19, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_14", "v_14"}], [ {1, 2, [{"k_02", "v_02"}], @@ -828,7 +828,7 @@ -define(B_TREE_04_20_MINUS_14, { - 2, 3, 19, + 2, 3, 19, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}], [ {1, 2, [{"k_02", "v_02"}], @@ -863,7 +863,7 @@ -define(B_TREE_04_20_MINUS_16, { - 2, 3, 19, + 2, 3, 19, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}], [ {1, 2, [{"k_02", "v_02"}], @@ -898,7 +898,7 @@ -define(B_TREE_04_20_MINUS_18, { - 2, 3, 19, + 2, 3, 19, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}], [ {1, 2, [{"k_02", "v_02"}], @@ -933,7 +933,8 @@ ). -define(B_TREE_04_32, - {2, 3, 32, + { + 2, 3, 32, sort_function, {2, 3, [{"k_08", "v_08"}, {"k_16", "v_16"}], [ {1, 2, [{"k_04", "v_04"}], @@ -998,7 +999,8 @@ ). -define(B_TREE_04_32_MINUS_07, - {2, 3, 31, + { + 2, 3, 31, sort_function, {1, 2, [{"k_16", "v_16"}], [ {2, 3, [{"k_04", "v_04"}, {"k_12", "v_12"}], @@ -1054,7 +1056,8 @@ ). -define(B_TREE_04_32_MINUS_07_01, - {2, 3, 30, + { + 2, 3, 30, sort_function, {1, 2, [{"k_16", "v_16"}], [ {2, 3, [{"k_06", "v_06"}, {"k_12", "v_12"}], @@ -1109,7 +1112,8 @@ ). -define(B_TREE_04_33_MINUS_02_TILL_16, - {2, 3, 25, + { + 2, 3, 25, sort_function, {1, 2, [{"k_24", "v_24"}], [ {2, 3, [{"k_09", "v_09"}, {"k_20", "v_20"}], @@ -1158,7 +1162,8 @@ ). -define(B_TREE_04_33_MINUS_02_TILL_18, - {2, 3, 24, + { + 2, 3, 24, sort_function, {1, 2, [{"k_24", "v_24"}], [ {2, 3, [{"k_09", "v_09"}, {"k_20", "v_20"}], @@ -1204,7 +1209,8 @@ ). -define(B_TREE_04_33_MINUS_02_TILL_20, - {2, 3, 23, + { + 2, 3, 23, sort_function, {1, 2, [{"k_24", "v_24"}], [ {2, 3, [{"k_09", "v_09"}, {"k_17", "v_17"}], @@ -1251,7 +1257,8 @@ ). -define(B_TREE_04_33_MINUS_02_TILL_22, - {2, 3, 22, + { + 2, 3, 22, sort_function, {1, 2, [{"k_24", "v_24"}], [ {1, 2, [{"k_09", "v_09"}], @@ -1294,7 +1301,8 @@ ). -define(B_TREE_04_33_MINUS_02_TILL_28, - {2, 3, 19, + { + 2, 3, 19, sort_function, {2, 3, [{"k_09", "v_09"}, {"k_25", "v_25"}], [ {1, 2, [{"k_03", "v_03"}], @@ -1323,7 +1331,8 @@ ). -define(B_TREE_04_33_MINUS_02_TILL_30, - {2, 3, 18, + { + 2, 3, 18, sort_function, {2, 3, [{"k_09", "v_09"}, {"k_21", "v_21"}], [ {1, 2, [{"k_03", "v_03"}], @@ -1352,7 +1361,8 @@ ). -define(B_TREE_04_64, - {2, 3, 64, + { + 2, 3, 64, sort_function, {2, 3, [{"k_16", "v_16"}, {"k_32", "v_32"}], [ {1, 2, [{"k_08", "v_08"}], @@ -1491,7 +1501,8 @@ ). -define(B_TREE_04_64_MINUS_08, - {2, 3, 63, + { + 2, 3, 63, sort_function, {1, 2, [{"k_32", "v_32"}], [ {2, 3, [{"k_16", "v_16"}, {"k_24", "v_24"}], @@ -1619,7 +1630,8 @@ ). -define(B_TREE_04_64_MINUS_16, - {2, 3, 63, + { + 2, 3, 63, sort_function, {1, 2, [{"k_32", "v_32"}], [ {2, 3, [{"k_08", "v_08"}, {"k_24", "v_24"}], @@ -1746,7 +1758,8 @@ -define(B_TREE_04_64_MINUS_32, - {2, 3, 63, + { + 2, 3, 63, sort_function, {2, 3, [{"k_16", "v_16"}, {"k_40", "v_40"}], [ {1, 2, [{"k_08", "v_08"}], @@ -1883,14 +1896,14 @@ -define(B_TREE_06_00, { - 3, 5, 0, + 3, 5, 0, sort_function, nil } ). -define(B_TREE_06_01, { - 3, 5, 1, + 3, 5, 1, sort_function, {1, 0, [{"k_01", "v_01"}], [] } } @@ -1898,7 +1911,7 @@ -define(B_TREE_06_02, { - 3, 5, 2, + 3, 5, 2, sort_function, {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], [] } } @@ -1906,7 +1919,7 @@ -define(B_TREE_06_03, { - 3, 5, 3, + 3, 5, 3, sort_function, {3, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}], [] } } @@ -1914,7 +1927,7 @@ -define(B_TREE_06_04, { - 3, 5, 4, + 3, 5, 4, sort_function, {4, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}], [] } } @@ -1922,7 +1935,7 @@ -define(B_TREE_06_05, { - 3, 5, 5, + 3, 5, 5, sort_function, {5, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}], [] } } @@ -1930,7 +1943,7 @@ -define(B_TREE_06_06, { - 3, 5, 6, + 3, 5, 6, sort_function, {1, 2, [{"k_03", "v_03"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -1942,7 +1955,7 @@ -define(B_TREE_06_06_MINUS_01, { - 3, 5, 5, + 3, 5, 5, sort_function, {1, 2, [{"k_04", "v_04"}], [ {2, 0, [{"k_02", "v_02"}, {"k_03", "v_03"}], []}, @@ -1954,7 +1967,7 @@ -define(B_TREE_06_06_MINUS_02, { - 3, 5, 5, + 3, 5, 5, sort_function, {1, 2, [{"k_04", "v_04"}], [ {2, 0, [{"k_01", "v_01"}, {"k_03", "v_03"}], []}, @@ -1966,7 +1979,7 @@ -define(B_TREE_06_06_MINUS_03, { - 3, 5, 5, + 3, 5, 5, sort_function, {1, 2, [{"k_04", "v_04"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -1978,7 +1991,7 @@ -define(B_TREE_06_06_MINUS_04, { - 3, 5, 5, + 3, 5, 5, sort_function, {1, 2, [{"k_03", "v_03"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -1990,7 +2003,7 @@ -define(B_TREE_06_06_MINUS_05, { - 3, 5, 5, + 3, 5, 5, sort_function, {1, 2, [{"k_03", "v_03"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2002,7 +2015,7 @@ -define(B_TREE_06_06_MINUS_06, { - 3, 5, 5, + 3, 5, 5, sort_function, {1, 2, [{"k_03", "v_03"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2014,7 +2027,7 @@ -define(B_TREE_06_07, { - 3, 5, 7, + 3, 5, 7, sort_function, {1, 2, [{"k_03", "v_03"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2026,7 +2039,7 @@ -define(B_TREE_06_08, { - 3, 5, 8, + 3, 5, 8, sort_function, {1, 2, [{"k_03", "v_03"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2038,7 +2051,7 @@ -define(B_TREE_06_09, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2051,7 +2064,7 @@ -define(B_TREE_06_09_MINUS_01, { - 3, 5, 8, + 3, 5, 8, sort_function, {1, 2, [{"k_06", "v_06"}], [ {4, 0, [{"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}], []}, @@ -2063,7 +2076,7 @@ -define(B_TREE_06_09_MINUS_02, { - 3, 5, 8, + 3, 5, 8, sort_function, {1, 2, [{"k_06", "v_06"}], [ {4, 0, [{"k_01", "v_01"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}], []}, @@ -2075,7 +2088,7 @@ -define(B_TREE_06_09_MINUS_03, { - 3, 5, 8, + 3, 5, 8, sort_function, {1, 2, [{"k_06", "v_06"}], [ {4, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_04", "v_04"}, {"k_05", "v_05"}], []}, @@ -2087,7 +2100,7 @@ -define(B_TREE_06_09_MINUS_04, { - 3, 5, 8, + 3, 5, 8, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_07", "v_07"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2100,7 +2113,7 @@ -define(B_TREE_06_09_MINUS_05, { - 3, 5, 8, + 3, 5, 8, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_07", "v_07"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2113,7 +2126,7 @@ -define(B_TREE_06_09_MINUS_06, { - 3, 5, 8, + 3, 5, 8, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_07", "v_07"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2126,7 +2139,7 @@ -define(B_TREE_06_09_MINUS_07, { - 3, 5, 8, + 3, 5, 8, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2139,7 +2152,7 @@ -define(B_TREE_06_09_MINUS_08, { - 3, 5, 8, + 3, 5, 8, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2152,7 +2165,7 @@ -define(B_TREE_06_09_MINUS_09, { - 3, 5, 8, + 3, 5, 8, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2165,7 +2178,7 @@ -define(B_TREE_06_10, { - 3, 5, 10, + 3, 5, 10, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2178,7 +2191,7 @@ -define(B_TREE_06_10_MINUS_01, { - 3, 5, 9, + 3, 5, 9, sort_function, {1, 2, [{"k_06", "v_06"}], [ {4, 0, [{"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}], []}, @@ -2190,7 +2203,7 @@ -define(B_TREE_06_10_MINUS_02, { - 3, 5, 9, + 3, 5, 9, sort_function, {1, 2, [{"k_06", "v_06"}], [ {4, 0, [{"k_01", "v_01"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}], []}, @@ -2202,7 +2215,7 @@ -define(B_TREE_06_10_MINUS_03, { - 3, 5, 9, + 3, 5, 9, sort_function, {1, 2, [{"k_06", "v_06"}], [ {4, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_04", "v_04"}, {"k_05", "v_05"}], []}, @@ -2214,7 +2227,7 @@ -define(B_TREE_06_10_MINUS_04, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_07", "v_07"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2227,7 +2240,7 @@ -define(B_TREE_06_10_MINUS_05, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_07", "v_07"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2240,7 +2253,7 @@ -define(B_TREE_06_10_MINUS_06, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_07", "v_07"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2253,7 +2266,7 @@ -define(B_TREE_06_10_MINUS_07, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2266,7 +2279,7 @@ -define(B_TREE_06_10_MINUS_08, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2279,7 +2292,7 @@ -define(B_TREE_06_10_MINUS_09, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2292,7 +2305,7 @@ -define(B_TREE_06_10_MINUS_10, { - 3, 5, 9, + 3, 5, 9, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2305,7 +2318,7 @@ -define(B_TREE_06_11, { - 3, 5, 11, + 3, 5, 11, sort_function, {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2318,7 +2331,7 @@ -define(B_TREE_06_12, { - 3, 5, 12, + 3, 5, 12, sort_function, {3, 4, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2332,7 +2345,7 @@ -define(B_TREE_06_13, { - 3, 5, 13, + 3, 5, 13, sort_function, {3, 4, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2346,7 +2359,7 @@ -define(B_TREE_06_14, { - 3, 5, 14, + 3, 5, 14, sort_function, {3, 4, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2360,7 +2373,7 @@ -define(B_TREE_06_15, { - 3, 5, 15, + 3, 5, 15, sort_function, {4, 5, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2375,7 +2388,7 @@ -define(B_TREE_06_16, { - 3, 5, 16, + 3, 5, 16, sort_function, {4, 5, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2390,7 +2403,7 @@ -define(B_TREE_06_17, { - 3, 5, 17, + 3, 5, 17, sort_function, {4, 5, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2405,7 +2418,7 @@ -define(B_TREE_06_18, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}, {"k_15", "v_15"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2421,7 +2434,7 @@ -define(B_TREE_06_18_MINUS_18_17, { - 3, 5, 17, + 3, 5, 17, sort_function, {5, 6, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}, {"k_15", "v_15"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2437,7 +2450,7 @@ -define(B_TREE_06_19, { - 3, 5, 19, + 3, 5, 19, sort_function, {5, 6, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}, {"k_15", "v_15"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2453,7 +2466,7 @@ -define(B_TREE_06_20, { - 3, 5, 20, + 3, 5, 20, sort_function, {5, 6, [{"k_03", "v_03"}, {"k_06", "v_06"}, {"k_09", "v_09"}, {"k_12", "v_12"}, {"k_15", "v_15"}], [ {2, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}], []}, @@ -2469,7 +2482,7 @@ -define(B_TREE_06_21, { - 3, 5, 21, + 3, 5, 21, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2494,7 +2507,7 @@ -define(B_TREE_06_22, { - 3, 5, 22, + 3, 5, 22, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2519,7 +2532,7 @@ -define(B_TREE_06_23, { - 3, 5, 23, + 3, 5, 23, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2544,7 +2557,7 @@ -define(B_TREE_06_24, { - 3, 5, 24, + 3, 5, 24, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2570,7 +2583,7 @@ -define(B_TREE_06_25, { - 3, 5, 25, + 3, 5, 25, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2596,7 +2609,7 @@ -define(B_TREE_06_26, { - 3, 5, 26, + 3, 5, 26, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2622,7 +2635,7 @@ -define(B_TREE_06_27, { - 3, 5, 27, + 3, 5, 27, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2649,7 +2662,7 @@ -define(B_TREE_06_28, { - 3, 5, 28, + 3, 5, 28, sort_function, {1, 2, [{"k_09", "v_09"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2676,7 +2689,7 @@ -define(B_TREE_06_29, { - 3, 5, 29, + 3, 5, 29, sort_function, {2, 3, [{"k_09", "v_09"}, {"k_18", "v_18"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2707,7 +2720,7 @@ -define(B_TREE_06_30, { - 3, 5, 30, + 3, 5, 30, sort_function, {2, 3, [{"k_09", "v_09"}, {"k_18", "v_18"}], [ {2, 3, [{"k_03", "v_03"}, {"k_06", "v_06"}], @@ -2743,14 +2756,14 @@ -define(B_TREE_08_00, { - 4, 7, 0, + 4, 7, 0, sort_function, nil } ). -define(B_TREE_08_16, { - 4, 7, 16, + 4, 7, 16, sort_function, {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}], [ {3, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}], []}, @@ -2764,7 +2777,7 @@ -define(B_TREE_08_32, { - 4, 7, 32, + 4, 7, 32, sort_function, {7, 8, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}, {"k_16", "v_16"}, {"k_20", "v_20"}, {"k_24", "v_24"}, {"k_28", "v_28"}], [ {3, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}], []}, @@ -2782,7 +2795,7 @@ -define(B_TREE_08_64, { - 4, 7, 64, + 4, 7, 64, sort_function, {2, 3, [{"k_16", "v_16"}, {"k_32", "v_32"}], [ {3, 4, [{"k_04", "v_04"}, {"k_08", "v_08"}, {"k_12", "v_12"}], @@ -2824,7 +2837,7 @@ -define(B_TREE_10_10, { - 5, 9, 10, + 5, 9, 10, sort_function, {1, 2, [{"k_05", "v_05"}], [ {4, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}], []}, @@ -2840,7 +2853,7 @@ -define(B_TREE_12_13, { - 6, 11, 13, + 6, 11, 13, sort_function, {1, 2, [{"k_07", "v_07"}], [ {6, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}, {"k_06", "v_06"}], []}, @@ -2856,7 +2869,7 @@ -define(B_TREE_16_16, { - 8, 15, 16, + 8, 15, 16, sort_function, {1, 2, [{"k_08", "v_08"}], [ {7, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}, {"k_06", "v_06"}, {"k_07", "v_07"}], []}, @@ -2872,7 +2885,7 @@ -define(B_TREE_18_19, { - 9, 17, 19, + 9, 17, 19, sort_function, {1, 2, [{"k_09", "v_09"}], [ {8, 0, [{"k_01", "v_01"}, {"k_02", "v_02"}, {"k_03", "v_03"}, {"k_04", "v_04"}, {"k_05", "v_05"}, {"k_06", "v_06"}, {"k_07", "v_07"}, {"k_08", "v_08"}], []}, @@ -2888,14 +2901,14 @@ -define(B_TREE_32_00, { - 16, 31, 0, + 16, 31, 0, sort_function, nil } ). -define(B_TREE_32_01, { - 16, 31, 1, + 16, 31, 1, sort_function, {1, 0, [{"k_01", "v_01"}], [] } } @@ -2907,7 +2920,7 @@ -define(B_TREE_CLRS_498, { - 3, 5, 19, + 3, 5, 19, sort_function, {4, 5, [{"k_g", "v_g"}, {"k_m", "v_m"}, {"k_p", "v_p"}, {"k_x", "v_x"}], [ {4, 0, [{"k_a", "v_a"}, {"k_c", "v_c"}, {"k_d", "v_d"}, {"k_e", "v_e"}], []}, @@ -2922,7 +2935,7 @@ -define(B_TREE_CLRS_498_PLUS_B, { - 3, 5, 20, + 3, 5, 20, sort_function, {4, 5, [{"k_g", "v_g"}, {"k_m", "v_m"}, {"k_p", "v_p"}, {"k_x", "v_x"}], [ {5, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}, {"k_c", "v_c"}, {"k_d", "v_d"}, {"k_e", "v_e"}], []}, @@ -2937,7 +2950,7 @@ -define(B_TREE_CLRS_498_PLUS_B_Q, { - 3, 5, 21, + 3, 5, 21, sort_function, {5, 6, [{"k_g", "v_g"}, {"k_m", "v_m"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {5, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}, {"k_c", "v_c"}, {"k_d", "v_d"}, {"k_e", "v_e"}], []}, @@ -2953,7 +2966,7 @@ -define(B_TREE_CLRS_498_PLUS_B_Q_L, { - 3, 5, 22, + 3, 5, 22, sort_function, {1, 2, [{"k_p", "v_p"}], [ {2, 3, [{"k_g", "v_g"}, {"k_m", "v_m"}], @@ -2977,7 +2990,7 @@ -define(B_TREE_CLRS_498_PLUS_B_Q_L_F, { - 3, 5, 23, + 3, 5, 23, sort_function, {1, 2, [{"k_p", "v_p"}], [ {3, 4, [{"k_c", "v_c"}, {"k_g", "v_g"}, {"k_m", "v_m"}], @@ -3006,7 +3019,7 @@ -define(B_TREE_CLRS_500, { - 3, 5, 23, + 3, 5, 23, sort_function, {1, 2, [{"k_p", "v_p"}], [ {3, 4, [{"k_c", "v_c"}, {"k_g", "v_g"}, {"k_m", "v_m"}], @@ -3031,7 +3044,7 @@ -define(B_TREE_CLRS_500_MINUS_F, { - 3, 5, 22, + 3, 5, 22, sort_function, {1, 2, [{"k_p", "v_p"}], [ {3, 4, [{"k_c", "v_c"}, {"k_g", "v_g"}, {"k_m", "v_m"}], @@ -3056,7 +3069,7 @@ -define(B_TREE_CLRS_500_MINUS_F_2, { - 3, 5, 22, + 3, 5, 22, sort_function, {1, 2, [{"k_p", "v_p"}], [ {3, 4, [{"k_c", "v_c"}, {"k_g", "v_g"}, {"k_l", "v_l"}], @@ -3081,7 +3094,7 @@ -define(B_TREE_CLRS_500_MINUS_F_L, { - 3, 5, 21, + 3, 5, 21, sort_function, {1, 2, [{"k_p", "v_p"}], [ {3, 4, [{"k_c", "v_c"}, {"k_g", "v_g"}, {"k_m", "v_m"}], @@ -3106,7 +3119,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M, { - 3, 5, 21, + 3, 5, 21, sort_function, {1, 2, [{"k_p", "v_p"}], [ {3, 4, [{"k_c", "v_c"}, {"k_g", "v_g"}, {"k_l", "v_l"}], @@ -3131,7 +3144,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G, { - 3, 5, 20, + 3, 5, 20, sort_function, {1, 2, [{"k_p", "v_p"}], [ {2, 3, [{"k_c", "v_c"}, {"k_l", "v_l"}], @@ -3155,7 +3168,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D, { - 3, 5, 19, + 3, 5, 19, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3171,7 +3184,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D_A, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_e", "v_e"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_b", "v_b"}, {"k_c", "v_c"}], []}, @@ -3187,7 +3200,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D_B, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_e", "v_e"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_c", "v_c"}], []}, @@ -3203,7 +3216,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D_N, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_k", "v_k"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3219,7 +3232,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D_O, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_k", "v_k"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3235,7 +3248,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D_U, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_s", "v_s"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3251,7 +3264,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_D_V, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_s", "v_s"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3267,7 +3280,7 @@ -define(B_TREE_CLRS_500_2_MINUS_F_M_G_D, { - 3, 5, 19, + 3, 5, 19, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_k", "v_k"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3283,7 +3296,7 @@ -define(B_TREE_CLRS_500_2_MINUS_F_M_G_D_E, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3299,7 +3312,7 @@ -define(B_TREE_CLRS_500_2_MINUS_F_M_G_D_J, { - 3, 5, 18, + 3, 5, 18, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_t", "v_t"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, @@ -3315,7 +3328,7 @@ -define(B_TREE_CLRS_500_MINUS_F_M_G_U, { - 3, 5, 19, + 3, 5, 19, sort_function, {5, 6, [{"k_c", "v_c"}, {"k_l", "v_l"}, {"k_p", "v_p"}, {"k_s", "v_s"}, {"k_x", "v_x"}], [ {2, 0, [{"k_a", "v_a"}, {"k_b", "v_b"}], []}, diff --git a/src/b_trees.app.src b/src/b_trees.app.src index 3f5b25d..278b2bf 100644 --- a/src/b_trees.app.src +++ b/src/b_trees.app.src @@ -13,6 +13,6 @@ b_trees ] }, - {vsn, "1.0.0"} + {vsn, "1.1.0"} ] }. diff --git a/src/b_trees.erl b/src/b_trees.erl index 5fcd334..11882f8 100644 --- a/src/b_trees.erl +++ b/src/b_trees.erl @@ -39,7 +39,12 @@ %% %% - empty(O): returns a new empty B-tree of order O. Order is defined as the %% maximum number of children nodes a non-leaf node may hold. The minimum -%% value is 4. +%% value is 4. The sort order of the key values is ascending. +%% +%% - empty(O, F): returns a new empty B-tree of order O. Order is defined as +%% the maximum number of children nodes a non-leaf node may hold. The +%% minimum value is 4. The sort order of the key values is defined in +%% function F(K, K) -> equal | greater | less. %% %% - enter(K, V, B): inserts key K with value V into B-tree B if the key is not %% present in the tree, otherwise updates key K to value V in B. Returns the @@ -101,6 +106,12 @@ %% and V is the value associated with K in B. Assumes that the B-tree B is %% non-empty. %% +%% - sort_ascending(K1, K2): returns greater if K1 > K2, less if K1 < K2 and +%% equal elsewise. +%% +%% - sort_descending(K1, K2): returns greater if K1 < K2, less if K1 > K2 and +%% equal elsewise. +%% %% - take_largest(B): returns {K, V, B1}, where K is the largest key in B-tree %% B, V is the value associated with K in B, and B1 is the tree B with key K %% deleted. Assumes that the tree B is non-empty. @@ -125,6 +136,7 @@ delete/2, delete_any/2, empty/1, + empty/2, enter/3, from_dict/2, get/2, @@ -142,6 +154,8 @@ number_key_values/1, size/1, smallest/1, + sort_ascending/2, + sort_descending/2, take_smallest/1, take_largest/1, to_list/1, @@ -151,7 +165,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Data structure: -%% - {MinimumSubtrees, MaximumKeys, NumberKeyValues, Tree}, +%% - {MinimumSubtrees, MaximumKeys, NumberKeyValues, SortFunction, Tree}, %% where `Tree' is composed of : %% - {KeyNo, SubtreeNo, [{Key, Value}], [Tree]}. @@ -159,7 +173,7 @@ %% Some types. -export_type([b_tree/0]). --type b_tree() :: {pos_integer(), pos_integer(), non_neg_integer(), tree()}. +-type b_tree() :: {pos_integer(), pos_integer(), non_neg_integer(), sort_function(), tree()}. -export_type([iterator/0]). -type iterator() :: [{key_values(), subtrees()}]. @@ -172,6 +186,10 @@ -type map_function() :: fun((key(), value()) -> value()). +-type sort_function() :: fun((key(), key()) -> sort_result()). + +-type sort_result() :: less | equal | greater. + -type subtrees() :: [tree()]. -type tree() :: 'nil' @@ -188,29 +206,29 @@ -spec delete(key(), b_tree()) -> b_tree(). % Empty tree. -delete(Key, {_, _, 0, nil} = _BTree) -> +delete(Key, {_, _, 0, _, nil} = _BTree) -> erlang:error({key_not_found, Key}); % Root node is leaf node. -delete(Key, {SubtreeNoMin, KeyNoMax, NumberKeyValues, {KeyNo, 0, KeyValues, []}} = _BTree) -> - {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +delete(Key, {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, {KeyNo, 0, KeyValues, []}} = _BTree) -> + {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> erlang:error({key_not_found, Key}); _ -> - {SubtreeNoMin, KeyNoMax, NumberKeyValues - 1, case KeyNo == 1 of - true -> - nil; - _ -> - { - KeyNo - 1, - 0, - lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo), - [] - } - end} + {SubtreeNoMin, KeyNoMax, NumberKeyValues - 1, SortFunction, case KeyNo == 1 of + true -> + nil; + _ -> + { + KeyNo - 1, + 0, + lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo), + [] + } + end} end; -delete(Key, {SubtreeNoMin, KeyNoMax, NumberKeyValues, Tree} = _BTree) -> - {SubtreeNoMin, KeyNoMax, NumberKeyValues - 1, delete_1(Key, Tree, SubtreeNoMin, KeyNoMax)}. +delete(Key, {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, Tree} = _BTree) -> + {SubtreeNoMin, KeyNoMax, NumberKeyValues - 1, SortFunction, delete_1(Key, Tree, SubtreeNoMin, KeyNoMax, SortFunction)}. -spec combine(tree(), tree()) -> tree(). @@ -229,11 +247,11 @@ combine({LeftKeyNo, LeftSubtreeNo, LeftKeyValues, LeftSubtrees} = _LeftTree, {Ri lists:sublist(LeftSubtrees, 1, LeftKeyNo) ++ [combine(lists:nth(LeftSubtreeNo, LeftSubtrees), lists:nth(1, RightSubtrees))] ++ lists:sublist(RightSubtrees, 2, RightSubtreeNo) }. --spec delete_1(key(), tree(), pos_integer(), pos_integer()) -> tree(). +-spec delete_1(key(), tree(), pos_integer(), pos_integer(), sort_function()) -> tree(). % Leaf node. -delete_1(Key, {KeyNo, 0, KeyValues, []} = _Tree, _, _) -> - {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +delete_1(Key, {KeyNo, 0, KeyValues, []} = _Tree, _, _, SortFunction) -> + {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> erlang:error({key_not_found, Key}); @@ -246,11 +264,11 @@ delete_1(Key, {KeyNo, 0, KeyValues, []} = _Tree, _, _) -> [] } end; -delete_1(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, KeyNoMax) -> - {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +delete_1(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, KeyNoMax, SortFunction) -> + {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> - delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyPos); + delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyPos, SortFunction); _ -> delete_1_2(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyPos) end. @@ -399,9 +417,9 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, end end. --spec delete_1_3(key(), tree(), pos_integer(), pos_integer(), pos_integer()) -> tree(). +-spec delete_1_3(key(), tree(), pos_integer(), pos_integer(), pos_integer(), sort_function()) -> tree(). -delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, KeyNoMax, KeyPos) -> +delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, KeyNoMax, KeyPos, SortFunction) -> {KeyNoXCLeft, SubtreeNoXCLeft, KeyValuesXCLeft, SubtreesXCLeft} = _TreeXCLeft = case KeyPos == 1 of true -> {0, 0, [], []}; @@ -447,7 +465,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K []; _ -> [lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)] - end ++ SubtreesXC}, SubtreeNoMin, KeyNoMax) + end ++ SubtreesXC}, SubtreeNoMin, KeyNoMax, SortFunction) ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo) }; KeyNoXCRight >= SubtreeNoMin -> @@ -467,7 +485,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K []; _ -> [lists:nth(1, SubtreesXCRight)] - end}, SubtreeNoMin, KeyNoMax), + end}, SubtreeNoMin, KeyNoMax, SortFunction), {KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of true -> 0; @@ -486,7 +504,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K % CLRS: case 3b left case KeyNo == 1 of true -> - delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, SubtreeNoXCLeft + SubtreeNoXC, KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax); + delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, SubtreeNoXCLeft + SubtreeNoXC, KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax, SortFunction); _ -> { KeyNo - 1, @@ -499,7 +517,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K 0; _ -> SubtreeNoXCLeft + SubtreeNoXC - end, KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax) + end, KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax, SortFunction) ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo) } end; @@ -507,7 +525,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K % CLRS: case 3b right case KeyNo == 1 of true -> - delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, SubtreeNoXC + SubtreeNoXCRight, KeyValuesXC ++ KeyValues ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax); + delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, SubtreeNoXC + SubtreeNoXCRight, KeyValuesXC ++ KeyValues ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax, SortFunction); _ -> { KeyNo - 1, @@ -520,7 +538,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K 0; _ -> SubtreeNoXC + SubtreeNoXCRight - end, KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax) + end, KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax, SortFunction) ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo) } end @@ -531,7 +549,7 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, K KeyNo, SubtreeNo, KeyValues, - lists:sublist(Subtrees, 1, KeyPos - 1) ++ [delete_1(Key, TreeXC, SubtreeNoMin, KeyNoMax)] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo) + lists:sublist(Subtrees, 1, KeyPos - 1) ++ [delete_1(Key, TreeXC, SubtreeNoMin, KeyNoMax, SortFunction)] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo) } end. @@ -550,9 +568,13 @@ delete_any(Key, BTree) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec empty(pos_integer()) -> b_tree(). +-spec empty(pos_integer(), sort_function()) -> b_tree(). empty(Order) when Order > 3 -> - {Order div 2, Order - 1, 0, nil}. + empty(Order, fun sort_ascending/2). + +empty(Order, Function) when Order > 3, is_function(Function, 2) -> + {Order div 2, Order - 1, 0, Function, nil}. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -586,10 +608,10 @@ from_dict_1([{Key, Value} | Tail], BTree) -> -spec get(key(), b_tree()) -> value(). -get(Key, {_, _, 0, nil}) -> +get(Key, {_, _, 0, _, nil}) -> erlang:error({key_not_found, Key}); -get(Key, {_, _, _, Tree}) -> - case lookup_1(Key, Tree) of +get(Key, {_, _, _, SortFunction, Tree}) -> + case lookup_1(Key, Tree, SortFunction) of {value, Value} -> Value; _ -> @@ -600,9 +622,9 @@ get(Key, {_, _, _, Tree}) -> -spec height(b_tree()) -> non_neg_integer(). -height({_, _, 0, nil} = BTree) -> +height({_, _, 0, _, nil} = BTree) -> erlang:error({empty_tree, BTree}); -height({_, _, _, Tree}) -> +height({_, _, _, _, Tree}) -> height_1(Tree, 0). -spec height_1(tree(), non_neg_integer()) -> non_neg_integer(). @@ -619,21 +641,21 @@ height_1({_, _, _, [Tree | _]}, Number) -> -spec insert(key(), value(), b_tree()) -> b_tree(). % First entry. -insert(Key, Value, {SubtreeNoMin, KeyNoMax, 0, nil}) -> - {SubtreeNoMin, KeyNoMax, 1, {1, 0, [{Key, Value}], []}}; +insert(Key, Value, {SubtreeNoMin, KeyNoMax, 0, SortFunction, nil}) -> + {SubtreeNoMin, KeyNoMax, 1, SortFunction, {1, 0, [{Key, Value}], []}}; % Split root node. -insert(Key, Value, {SubtreeNoMin, KeyNoMax, NumberKeyValues, {KeyNo, _, _, _} = Tree}) when KeyNo == KeyNoMax -> - {SubtreeNoMin, KeyNoMax, NumberKeyValues + 1, insert_1({Key, Value}, split_node_root(Tree, SubtreeNoMin), SubtreeNoMin, KeyNoMax)}; -insert(Key, Value, {SubtreeNoMin, KeyNoMax, NumberKeyValues, Tree}) -> - {SubtreeNoMin, KeyNoMax, NumberKeyValues + 1, insert_1({Key, Value}, Tree, SubtreeNoMin, KeyNoMax)}. +insert(Key, Value, {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, {KeyNo, _, _, _} = Tree}) when KeyNo == KeyNoMax -> + {SubtreeNoMin, KeyNoMax, NumberKeyValues + 1, SortFunction, insert_1({Key, Value}, split_node_root(Tree, SubtreeNoMin), SubtreeNoMin, KeyNoMax, SortFunction)}; +insert(Key, Value, {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, Tree}) -> + {SubtreeNoMin, KeyNoMax, NumberKeyValues + 1, SortFunction, insert_1({Key, Value}, Tree, SubtreeNoMin, KeyNoMax, SortFunction)}. --spec insert_1(key_value(), tree(), pos_integer(), pos_integer()) -> tree(). +-spec insert_1(key_value(), tree(), pos_integer(), pos_integer(), sort_function()) -> tree(). % Leaf node. -insert_1(KeyValue, {KeyNo, 0, KeyValues, []}, _, _) -> - {KeyNo + 1, 0, insert_key_value(KeyValue, KeyValues, KeyNo), []}; -insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax) -> - {ValueFound, SubtreePos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +insert_1(KeyValue, {KeyNo, 0, KeyValues, []}, _, _, SortFunction) -> + {KeyNo + 1, 0, insert_key_value(KeyValue, KeyValues, KeyNo, SortFunction), []}; +insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, SortFunction) -> + {ValueFound, SubtreePos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> % Look ahead. @@ -641,22 +663,22 @@ insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNo case SubtreeKeyNo == KeyNoMax of % Split node. true -> - {SplitKeyValues, SplitSubtrees1, SplitTree1, SplitTree2, SplitSubtrees2} = split_node_non_root(KeyNo, KeyValues, Subtrees, Subtree, SubtreePos, SubtreeNoMin), + {SplitKeyValues, SplitSubtrees1, SplitTree1, SplitTree2, SplitSubtrees2} = split_node_non_root(KeyNo, KeyValues, Subtrees, Subtree, SubtreePos, SubtreeNoMin, SortFunction), { KeyNo + 1, SubtreeNo + 1, SplitKeyValues, SplitSubtrees1 ++ - case KeyValue < lists:nth(SubtreeNoMin, SubtreeKeyValues) of - true -> + case SortFunction(KeyValue, lists:nth(SubtreeNoMin, SubtreeKeyValues)) of + less -> [ - insert_1(KeyValue, SplitTree1, SubtreeNoMin, KeyNoMax), + insert_1(KeyValue, SplitTree1, SubtreeNoMin, KeyNoMax, SortFunction), SplitTree2 ]; _ -> [ SplitTree1, - insert_1(KeyValue, SplitTree2, SubtreeNoMin, KeyNoMax) + insert_1(KeyValue, SplitTree2, SubtreeNoMin, KeyNoMax, SortFunction) ] end ++ SplitSubtrees2 @@ -667,7 +689,7 @@ insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNo SubtreeNo, KeyValues, lists:sublist(Subtrees, 1, SubtreePos - 1) ++ - [insert_1(KeyValue, Subtree, SubtreeNoMin, KeyNoMax)] ++ + [insert_1(KeyValue, Subtree, SubtreeNoMin, KeyNoMax, SortFunction)] ++ lists:sublist(Subtrees, SubtreePos + 1, KeyNo + 1) } end; @@ -675,10 +697,10 @@ insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNo erlang:error({key_exists, Key}) end. --spec insert_key_value(key_value(), key_values(), pos_integer()) -> key_values(). +-spec insert_key_value(key_value(), key_values(), pos_integer(), sort_function()) -> key_values(). -insert_key_value({Key, _} = KeyValue, KeyValues, KeyNo) -> - {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +insert_key_value({Key, _} = KeyValue, KeyValues, KeyNo, SortFunction) -> + {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> lists:sublist(KeyValues, 1, KeyPos - 1) ++ [KeyValue] ++ lists:sublist(KeyValues, KeyPos, KeyNo); @@ -686,12 +708,12 @@ insert_key_value({Key, _} = KeyValue, KeyValues, KeyNo) -> erlang:error({key_exists, Key}) end. --spec split_node_non_root(pos_integer(), key_values(), subtrees(), tree(), pos_integer(), pos_integer()) -> {key_values(), subtrees(), tree(), tree(), subtrees()}. +-spec split_node_non_root(pos_integer(), key_values(), subtrees(), tree(), pos_integer(), pos_integer(), sort_function()) -> {key_values(), subtrees(), tree(), tree(), subtrees()}. -split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeKeyValues, TreeSubtrees}, SubtreePos, SubtreeNoMin) -> +split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeKeyValues, TreeSubtrees}, SubtreePos, SubtreeNoMin, SortFunction) -> { % SplitKeyValues ....................................................... - insert_key_value(lists:nth(SubtreeNoMin, TreeKeyValues), KeyValues, KeyNo), + insert_key_value(lists:nth(SubtreeNoMin, TreeKeyValues), KeyValues, KeyNo, SortFunction), % SplitSubtrees1 ....................................................... lists:sublist(Subtrees, 1, SubtreePos - 1), % SplitTree 1 .......................................................... @@ -784,10 +806,10 @@ split_node_root({KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin) -> -spec is_defined(key(), b_tree()) -> boolean(). -is_defined(_, {_, _, 0, nil}) -> +is_defined(_, {_, _, 0, _, nil}) -> false; -is_defined(Key, {_, _, _, Tree}) -> - case lookup_1(Key, Tree) == none of +is_defined(Key, {_, _, _, SortFunction, Tree}) -> + case lookup_1(Key, Tree, SortFunction) == none of true -> false; _ -> @@ -798,7 +820,7 @@ is_defined(Key, {_, _, _, Tree}) -> -spec is_empty(b_tree()) -> boolean(). -is_empty({_, _, 0, nil}) -> +is_empty({_, _, 0, _, nil}) -> true; is_empty(_) -> false. @@ -807,9 +829,9 @@ is_empty(_) -> -spec iterator(b_tree()) -> iterator(). -iterator({_, _, 0, nil}) -> +iterator({_, _, 0, _, nil}) -> []; -iterator({_, _, _, {_, _, KeyValues, Subtrees}}) -> +iterator({_, _, _, _, {_, _, KeyValues, Subtrees}}) -> iterator_1({KeyValues, Subtrees}, []). % The iterator structure is really just a list corresponding to @@ -829,30 +851,30 @@ iterator_1({KeyValues, Subtrees}, Iterator) -> -spec iterator_from(key(), b_tree()) -> iterator(). -iterator_from(_Key, {_, _, 0, nil}) -> +iterator_from(_Key, {_, _, 0, _, nil}) -> []; -iterator_from(Key, {_, _, _, Tree}) -> - iterator_from_1(Key, Tree, []). +iterator_from(Key, {_, _, _, SortFunction, Tree}) -> + iterator_from_1(Key, Tree, [], SortFunction). --spec iterator_from_1(key(), tree(), iterator()) -> iterator(). +-spec iterator_from_1(key(), tree(), iterator(), sort_function()) -> iterator(). % The most left key / value. -iterator_from_1(Key, {KeyNo, 0, KeyValues, []} = _Next, Iterator) -> - {_, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +iterator_from_1(Key, {KeyNo, 0, KeyValues, []} = _Next, Iterator, SortFunction) -> + {_, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), [{lists:sublist(KeyValues, Pos, KeyNo), []} | Iterator]; % The most left subtree. -iterator_from_1(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Next, Iterator) -> - {_, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +iterator_from_1(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Next, Iterator, SortFunction) -> + {_, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), {KeyNo_1, SubtreeNo_1, KeyValues_1, Subtrees_1} = _NextIterator = lists:nth(Pos, Subtrees), - iterator_from_1(Key, {KeyNo_1, SubtreeNo_1, KeyValues_1, Subtrees_1}, [{lists:sublist(KeyValues, Pos, KeyNo), lists:sublist(Subtrees, Pos, SubtreeNo)} | Iterator]). + iterator_from_1(Key, {KeyNo_1, SubtreeNo_1, KeyValues_1, Subtrees_1}, [{lists:sublist(KeyValues, Pos, KeyNo), lists:sublist(Subtrees, Pos, SubtreeNo)} | Iterator], SortFunction). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec keys(b_tree()) -> keys(). -keys({_, _, 0, nil}) -> +keys({_, _, 0, _, nil}) -> []; -keys({_, _, _, {_, _, KeyValues, Subtrees}}) -> +keys({_, _, _, _, {_, _, KeyValues, Subtrees}}) -> keys_1(KeyValues, Subtrees, []). -spec keys_1(key_values(), subtrees(), keys()) -> keys(). @@ -873,9 +895,9 @@ keys_1([{Key, _} | TailKeyValues], [{_, _, KeyValues, Subtrees} | TailTrees], Ke -spec largest(b_tree()) -> key_value(). -largest({_, _, 0, nil} = BTree) -> +largest({_, _, 0, _, nil} = BTree) -> erlang:error({empty_tree, BTree}); -largest({_, _, _, Tree}) -> +largest({_, _, _, _, Tree}) -> largest_1(Tree). -spec largest_1(tree()) -> key_value(). @@ -891,19 +913,19 @@ largest_1({_, SubtreeNo, _, Subtrees}) -> -spec lookup(key(), b_tree()) -> 'none' | {'value', value()}. -lookup(_, {_, _, 0, nil}) -> +lookup(_, {_, _, 0, _, nil}) -> none; -lookup(Key, {_, _, _, Tree}) -> - lookup_1(Key, Tree). +lookup(Key, {_, _, _, SortFunction, Tree}) -> + lookup_1(Key, Tree, SortFunction). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec map(map_function(), b_tree()) -> b_tree(). -map(_, {_, _, 0, nil} = BTree) -> +map(_, {_, _, 0, _, nil} = BTree) -> erlang:error({empty_tree, BTree}); -map(Function, {SubtreeNoMin, KeyNoMax, NumberKeyValues, Tree}) when is_function(Function, 2) -> - {SubtreeNoMin, KeyNoMax, NumberKeyValues, map_tree(Function, Tree)}. +map(Function, {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, Tree}) when is_function(Function, 2) -> + {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, map_tree(Function, Tree)}. -spec map_key_values(map_function(), key_values(), key_values()) -> key_values(). @@ -951,16 +973,16 @@ next([]) -> -spec number_key_values(b_tree()) -> non_neg_integer(). -number_key_values({_, _, NumberKeyValues, _}) -> +number_key_values({_, _, NumberKeyValues, _, _}) -> NumberKeyValues. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec size(b_tree()) -> non_neg_integer(). -size({_, _, 0, nil}) -> +size({_, _, 0, _, nil}) -> 0; -size({_, _, _, Tree}) -> +size({_, _, _, _, Tree}) -> size_tree(Tree, 0). -spec size_tree(tree(), non_neg_integer()) -> non_neg_integer(). @@ -982,9 +1004,9 @@ size_subtrees([Tree | Tail], Number) -> -spec smallest(b_tree()) -> key_value(). -smallest({_, _, 0, nil} = BTree) -> +smallest({_, _, 0, _, nil} = BTree) -> erlang:error({empty_tree, BTree}); -smallest({_, _, _, Tree}) -> +smallest({_, _, _, _, Tree}) -> smallest_1(Tree). -spec smallest_1(tree()) -> key_value(). @@ -1016,9 +1038,9 @@ take_smallest(BTree) -> -spec to_list(b_tree()) -> key_values(). -to_list({_, _, 0, nil} = BTree) -> +to_list({_, _, 0, _, nil} = BTree) -> erlang:error({empty_tree, BTree}); -to_list({_, _, _, {_, _, KeyValues, Subtrees}}) -> +to_list({_, _, _, _, {_, _, KeyValues, Subtrees}}) -> to_list_1(KeyValues, Subtrees, []). -spec to_list_1(key_values(), subtrees(), key_values()) -> key_values(). @@ -1039,16 +1061,16 @@ to_list_1([KeyValue | TailKeyValues], [{_, _, KeyValues, Subtrees} | TailTrees], -spec update(key(), value(), b_tree()) -> b_tree(). -update(Key, _, {_, _, 0, nil}) -> +update(Key, _, {_, _, 0, _, nil}) -> erlang:error({key_not_found, Key}); -update(Key, Value, {SubtreeNoMin, KeyNoMax, NumberKeyValues, Tree}) -> - {SubtreeNoMin, KeyNoMax, NumberKeyValues, update_1({Key, Value}, Tree)}. +update(Key, Value, {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, Tree}) -> + {SubtreeNoMin, KeyNoMax, NumberKeyValues, SortFunction, update_1({Key, Value}, Tree, SortFunction)}. --spec update_1(key_value(), tree()) -> tree(). +-spec update_1(key_value(), tree(), sort_function()) -> tree(). % Leaf node. -update_1({Key, _} = KeyValue, {KeyNo, 0, KeyValues, []}) -> - {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +update_1({Key, _} = KeyValue, {KeyNo, 0, KeyValues, []}, SortFunction) -> + {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> erlang:error({key_not_found, Key}); @@ -1062,8 +1084,8 @@ update_1({Key, _} = KeyValue, {KeyNo, 0, KeyValues, []}) -> [] } end; -update_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}) -> - {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +update_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SortFunction) -> + {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case ValueFound of none -> { @@ -1071,7 +1093,7 @@ update_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}) -> SubtreeNo, KeyValues, lists:sublist(Subtrees, 1, KeyPos - 1) ++ - [update_1(KeyValue, lists:nth(KeyPos, Subtrees))] ++ + [update_1(KeyValue, lists:nth(KeyPos, Subtrees), SortFunction)] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo) }; _ -> @@ -1089,9 +1111,9 @@ update_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}) -> -spec values(b_tree()) -> values(). -values({_, _, 0, nil}) -> +values({_, _, 0, _, nil}) -> []; -values({_, _, _, {_, _, KeyValues, Subtrees}}) -> +values({_, _, _, _, {_, _, KeyValues, Subtrees}}) -> values_1(KeyValues, Subtrees, []). -spec values_1(key_values(), subtrees(), values()) -> values(). @@ -1112,9 +1134,9 @@ values_1([{_, Value} | TailKeyValues], [{_, _, KeyValues, Subtrees} | TailTrees] %% Helper functions. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec binary_search(key(), key_values(), pos_integer(), pos_integer(), pos_integer()) -> {none, pos_integer()} | {any(), pos_integer()}. +-spec binary_search(key(), key_values(), pos_integer(), pos_integer(), pos_integer(), sort_function()) -> {none, pos_integer()} | {any(), pos_integer()}. -binary_search(Key, KeyValues, KeyNo, Lower, Upper) when Lower > Upper -> +binary_search(Key, KeyValues, KeyNo, Lower, Upper, SortFunction) when Lower > Upper -> TreeNo = case Lower > KeyNo of true -> Upper; @@ -1122,21 +1144,21 @@ binary_search(Key, KeyValues, KeyNo, Lower, Upper) when Lower > Upper -> Lower end, {KeyLast, _} = lists:nth(TreeNo, KeyValues), - case Key < KeyLast of - true -> + case SortFunction(Key, KeyLast) of + less -> {none, TreeNo}; _ -> {none, TreeNo + 1} end; -binary_search(Key, KeyValues, KeyNo, Lower, Upper) -> +binary_search(Key, KeyValues, KeyNo, Lower, Upper, SortFunction) -> Mid = (Upper + Lower) div 2, {MidKey, MidValue} = lists:nth(Mid, KeyValues), - if - Key > MidKey -> - binary_search(Key, KeyValues, KeyNo, Mid + 1, Upper); - Key < MidKey -> - binary_search(Key, KeyValues, KeyNo, Lower, Mid - 1); - true -> + case SortFunction(Key, MidKey) of + greater -> + binary_search(Key, KeyValues, KeyNo, Mid + 1, Upper, SortFunction); + less -> + binary_search(Key, KeyValues, KeyNo, Lower, Mid - 1, SortFunction); + _ -> {MidValue, Mid} end. @@ -1149,23 +1171,45 @@ binary_search(Key, KeyValues, KeyNo, Lower, Upper) -> %% equality, and also allows us to skip the test completely in the %% remaining case. --spec lookup_1(key(), tree()) -> 'none' | {'value', value()}. +-spec lookup_1(key(), tree(), sort_function()) -> 'none' | {'value', value()}. % Leaf node. -lookup_1(Key, {KeyNo, 0, KeyValues, []}) -> - {Value, _} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +lookup_1(Key, {KeyNo, 0, KeyValues, []}, SortFunction) -> + {Value, _} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case Value == none of true -> Value; _ -> {value, Value} end; -lookup_1(Key, {KeyNo, _, KeyValues, ChildTrees}) -> - {Value, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo), +lookup_1(Key, {KeyNo, _, KeyValues, ChildTrees}, SortFunction) -> + {Value, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), case Value == none of true -> ChildTree = lists:nth(Pos, ChildTrees), - lookup_1(Key, ChildTree); + lookup_1(Key, ChildTree, SortFunction); _ -> {value, Value} end. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec sort_ascending(key(), key()) -> sort_result(). + +sort_ascending(Key_1, Key_2) -> + if + Key_1 < Key_2 -> less; + Key_1 > Key_2 -> greater; + true -> equal + end. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec sort_descending(key(), key()) -> sort_result(). + +sort_descending(Key_1, Key_2) -> + if + Key_1 < Key_2 -> greater; + Key_1 > Key_2 -> less; + true -> equal + end. diff --git a/src/test_generator.erl b/src/test_generator.erl index ae50c40..afb4181 100644 --- a/src/test_generator.erl +++ b/src/test_generator.erl @@ -9,7 +9,10 @@ -module(test_generator). +-include_lib("eunit/include/eunit.hrl"). + -export([ + check_equal/2, delete_b_tree_from/3, delete_b_tree_from/4, delete_b_tree_from_even/4, @@ -37,6 +40,9 @@ generate_keys_from_odd/2, generate_keys_random/2, generate_keys_till/2, + iterate_next_b_tree/3, + map_value_to_new/2, + prepare_template/1, take_largest_b_tree/3, take_largest_gb_tree/2, take_smallest_b_tree/3, @@ -223,7 +229,42 @@ take_smallest_gb_tree(Number, Width) when Number > 0 -> take_smallest_gb_tree_1(Number, GBTree). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Helper functions. +%% Eunit & Common Test helper functions. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec check_equal(any(), any()) -> boolean(). + +check_equal(Value_1, Value_2) when is_tuple(Value_2), tuple_size(Value_2) == 5 -> + ?assertEqual(Value_1, setelement(4, Value_2, sort_function)); +check_equal(Value_1, Value_2) -> + ?assertEqual(Value_1, Value_2). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec iterate_next_b_tree(b_trees:iterator(), non_neg_integer(), b_trees:key_values()) -> b_trees:key_values(). + +iterate_next_b_tree(_, 0, KeyValues) -> + KeyValues; +iterate_next_b_tree(Iterator, Count, KeyValues) -> + {Key, Value, IteratorNew} = b_trees:next(Iterator), + iterate_next_b_tree(IteratorNew, Count - 1, KeyValues ++ [{Key, Value}]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec map_value_to_new(b_trees:key(), b_trees:value()) -> b_trees:key_value(). + +map_value_to_new(_, Value) -> + Value ++ "_new". + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +-spec prepare_template(b_trees:b_tree()) -> b_trees:b_tree(). + +prepare_template(BTree) -> + setelement(4, BTree, fun b_trees:sort_ascending/2). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Generator helper functions. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spec compare(any(), any()) -> boolean(). diff --git a/test/b_trees_SUITE.erl b/test/b_trees_SUITE.erl index 138a561..401a4b8 100644 --- a/test/b_trees_SUITE.erl +++ b/test/b_trees_SUITE.erl @@ -85,11 +85,11 @@ all() -> %%-------------------------------------------------------------------- delete_any_test(_Config) -> - ?assertEqual(?B_TREE_06_00, b_trees:delete_any("k_00", ?B_TREE_06_00)), - ?assertEqual(?B_TREE_06_00, b_trees:delete_any("k_01", ?B_TREE_06_01)), - ?assertEqual(?B_TREE_06_01, b_trees:delete_any("k_00", ?B_TREE_06_01)), - ?assertEqual(?B_TREE_06_03, b_trees:delete_any("k_04", ?B_TREE_06_04)), - ?assertEqual(?B_TREE_06_06, b_trees:delete_any("k_07", ?B_TREE_06_07)), + test_generator:check_equal(?B_TREE_06_00, b_trees:delete_any("k_00", test_generator:prepare_template(?B_TREE_06_00))), + test_generator:check_equal(?B_TREE_06_00, b_trees:delete_any("k_01", test_generator:prepare_template(?B_TREE_06_01))), + test_generator:check_equal(?B_TREE_06_01, b_trees:delete_any("k_00", test_generator:prepare_template(?B_TREE_06_01))), + test_generator:check_equal(?B_TREE_06_03, b_trees:delete_any("k_04", test_generator:prepare_template(?B_TREE_06_04))), + test_generator:check_equal(?B_TREE_06_06, b_trees:delete_any("k_07", test_generator:prepare_template(?B_TREE_06_07))), ok. @@ -98,30 +98,30 @@ delete_any_test(_Config) -> %%-------------------------------------------------------------------- delete_b_tree_order_4_test(_Config) -> - ?assertEqual(?B_TREE_04_10_MINUS_02, b_trees:delete("k_02", ?B_TREE_04_10)), - - ?assertEqual(?B_TREE_04_17_MINUS_02, b_trees:delete("k_02", ?B_TREE_04_17)), - ?assertEqual(?B_TREE_04_17_MINUS_02_04, b_trees:delete("k_04", ?B_TREE_04_17_MINUS_02)), - ?assertEqual(?B_TREE_04_17_MINUS_02_TILL_12, b_trees:delete("k_12", ?B_TREE_04_17_MINUS_02_TILL_10)), - - ?assertEqual(?B_TREE_04_20_MINUS_02, b_trees:delete("k_02", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_04, b_trees:delete("k_04", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_06, b_trees:delete("k_06", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_08, b_trees:delete("k_08", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_10, b_trees:delete("k_10", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_12, b_trees:delete("k_12", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_14, b_trees:delete("k_14", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_16, b_trees:delete("k_16", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_18, b_trees:delete("k_18", ?B_TREE_04_20)), - - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_18, b_trees:delete("k_18", ?B_TREE_04_33_MINUS_02_TILL_16)), - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_20, b_trees:delete("k_20", ?B_TREE_04_33_MINUS_02_TILL_18)), - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_22, b_trees:delete("k_22", ?B_TREE_04_33_MINUS_02_TILL_20)), - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_30, b_trees:delete("k_30", ?B_TREE_04_33_MINUS_02_TILL_28)), - - ?assertEqual(?B_TREE_04_64_MINUS_08, b_trees:delete("k_08", ?B_TREE_04_64)), - ?assertEqual(?B_TREE_04_64_MINUS_16, b_trees:delete("k_16", ?B_TREE_04_64)), - ?assertEqual(?B_TREE_04_64_MINUS_32, b_trees:delete("k_32", ?B_TREE_04_64)), + test_generator:check_equal(?B_TREE_04_10_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_04_10))), + + test_generator:check_equal(?B_TREE_04_17_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_04_17))), + test_generator:check_equal(?B_TREE_04_17_MINUS_02_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_04_17_MINUS_02))), + test_generator:check_equal(?B_TREE_04_17_MINUS_02_TILL_12, b_trees:delete("k_12", test_generator:prepare_template(?B_TREE_04_17_MINUS_02_TILL_10))), + + test_generator:check_equal(?B_TREE_04_20_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_10, b_trees:delete("k_10", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_12, b_trees:delete("k_12", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_14, b_trees:delete("k_14", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_16, b_trees:delete("k_16", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_18, b_trees:delete("k_18", test_generator:prepare_template(?B_TREE_04_20))), + + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_18, b_trees:delete("k_18", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_16))), + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_20, b_trees:delete("k_20", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_18))), + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_22, b_trees:delete("k_22", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_20))), + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_30, b_trees:delete("k_30", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_28))), + + test_generator:check_equal(?B_TREE_04_64_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_04_64))), + test_generator:check_equal(?B_TREE_04_64_MINUS_16, b_trees:delete("k_16", test_generator:prepare_template(?B_TREE_04_64))), + test_generator:check_equal(?B_TREE_04_64_MINUS_32, b_trees:delete("k_32", test_generator:prepare_template(?B_TREE_04_64))), ok. @@ -130,44 +130,44 @@ delete_b_tree_order_4_test(_Config) -> %%-------------------------------------------------------------------- delete_b_tree_order_6_test(_Config) -> - ?assertEqual(?B_TREE_06_00, b_trees:delete("k_01", ?B_TREE_06_01)), - - ?assertEqual(?B_TREE_06_06_MINUS_01, b_trees:delete("k_01", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_02, b_trees:delete("k_02", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_03, b_trees:delete("k_03", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_04, b_trees:delete("k_04", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_05, b_trees:delete("k_05", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_06, b_trees:delete("k_06", ?B_TREE_06_06)), - - ?assertEqual(?B_TREE_06_09_MINUS_01, b_trees:delete("k_01", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_02, b_trees:delete("k_02", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_03, b_trees:delete("k_03", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_04, b_trees:delete("k_04", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_05, b_trees:delete("k_05", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_06, b_trees:delete("k_06", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_07, b_trees:delete("k_07", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_08, b_trees:delete("k_08", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_09, b_trees:delete("k_09", ?B_TREE_06_09)), - - ?assertEqual(?B_TREE_06_10_MINUS_01, b_trees:delete("k_01", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_02, b_trees:delete("k_02", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_03, b_trees:delete("k_03", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_04, b_trees:delete("k_04", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_05, b_trees:delete("k_05", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_06, b_trees:delete("k_06", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_07, b_trees:delete("k_07", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_08, b_trees:delete("k_08", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_09, b_trees:delete("k_09", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_10, b_trees:delete("k_10", ?B_TREE_06_10)), - - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 1, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 5, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 8, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 11, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 14, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 17, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 20, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_till(6, 100, 4)), + test_generator:check_equal(?B_TREE_06_00, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_01))), + + test_generator:check_equal(?B_TREE_06_06_MINUS_01, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_03, b_trees:delete("k_03", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_05, b_trees:delete("k_05", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_06_06))), + + test_generator:check_equal(?B_TREE_06_09_MINUS_01, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_03, b_trees:delete("k_03", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_05, b_trees:delete("k_05", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_07, b_trees:delete("k_07", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_09, b_trees:delete("k_09", test_generator:prepare_template(?B_TREE_06_09))), + + test_generator:check_equal(?B_TREE_06_10_MINUS_01, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_03, b_trees:delete("k_03", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_05, b_trees:delete("k_05", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_07, b_trees:delete("k_07", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_09, b_trees:delete("k_09", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_10, b_trees:delete("k_10", test_generator:prepare_template(?B_TREE_06_10))), + + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 1, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 5, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 8, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 11, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 14, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 17, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 20, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_till(6, 100, 4)), ok. @@ -178,46 +178,46 @@ delete_b_tree_order_6_test(_Config) -> delete_clrs_test(_Config) -> % case 1 - _B_TREE_CLRS_500_MINUS_F = b_trees:delete("k_f", ?B_TREE_CLRS_500), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F, _B_TREE_CLRS_500_MINUS_F), + _B_TREE_CLRS_500_MINUS_F = b_trees:delete("k_f", test_generator:prepare_template(?B_TREE_CLRS_500)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F, _B_TREE_CLRS_500_MINUS_F), % case 2a - _B_TREE_CLRS_500_MINUS_F_M = b_trees:delete("k_m", ?B_TREE_CLRS_500_MINUS_F), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M, _B_TREE_CLRS_500_MINUS_F_M), + _B_TREE_CLRS_500_MINUS_F_M = b_trees:delete("k_m", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M, _B_TREE_CLRS_500_MINUS_F_M), % case 2b - _B_TREE_CLRS_500_MINUS_F_L = b_trees:delete("k_l", ?B_TREE_CLRS_500_MINUS_F_2), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_L, _B_TREE_CLRS_500_MINUS_F_L), + _B_TREE_CLRS_500_MINUS_F_L = b_trees:delete("k_l", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_2)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_L, _B_TREE_CLRS_500_MINUS_F_L), % case 2c - _B_TREE_CLRS_500_MINUS_F_M_G = b_trees:delete("k_g", ?B_TREE_CLRS_500_MINUS_F_M), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G, _B_TREE_CLRS_500_MINUS_F_M_G), + _B_TREE_CLRS_500_MINUS_F_M_G = b_trees:delete("k_g", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G, _B_TREE_CLRS_500_MINUS_F_M_G), % case 3a - delete left - _B_TREE_CLRS_500_MINUS_F_M_G_D_A = b_trees:delete("k_a", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_A, _B_TREE_CLRS_500_MINUS_F_M_G_D_A), - _B_TREE_CLRS_500_MINUS_F_M_G_D_B = b_trees:delete("k_b", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_B, _B_TREE_CLRS_500_MINUS_F_M_G_D_B), - _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E = b_trees:delete("k_e", ?B_TREE_CLRS_500_2_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_E, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E), - _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J = b_trees:delete("k_j", ?B_TREE_CLRS_500_2_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_J, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J), - _B_TREE_CLRS_500_MINUS_F_M_G_D_N = b_trees:delete("k_n", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_N, _B_TREE_CLRS_500_MINUS_F_M_G_D_N), - _B_TREE_CLRS_500_MINUS_F_M_G_D_O = b_trees:delete("k_o", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_O, _B_TREE_CLRS_500_MINUS_F_M_G_D_O), + _B_TREE_CLRS_500_MINUS_F_M_G_D_A = b_trees:delete("k_a", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_A, _B_TREE_CLRS_500_MINUS_F_M_G_D_A), + _B_TREE_CLRS_500_MINUS_F_M_G_D_B = b_trees:delete("k_b", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_B, _B_TREE_CLRS_500_MINUS_F_M_G_D_B), + _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E = b_trees:delete("k_e", test_generator:prepare_template(?B_TREE_CLRS_500_2_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_E, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E), + _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J = b_trees:delete("k_j", test_generator:prepare_template(?B_TREE_CLRS_500_2_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_J, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J), + _B_TREE_CLRS_500_MINUS_F_M_G_D_N = b_trees:delete("k_n", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_N, _B_TREE_CLRS_500_MINUS_F_M_G_D_N), + _B_TREE_CLRS_500_MINUS_F_M_G_D_O = b_trees:delete("k_o", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_O, _B_TREE_CLRS_500_MINUS_F_M_G_D_O), % case 3a delete right - _B_TREE_CLRS_500_MINUS_F_M_G_D_U = b_trees:delete("k_u", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_U, _B_TREE_CLRS_500_MINUS_F_M_G_D_U), - _B_TREE_CLRS_500_MINUS_F_M_G_D_V = b_trees:delete("k_v", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_V, _B_TREE_CLRS_500_MINUS_F_M_G_D_V), + _B_TREE_CLRS_500_MINUS_F_M_G_D_U = b_trees:delete("k_u", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_U, _B_TREE_CLRS_500_MINUS_F_M_G_D_U), + _B_TREE_CLRS_500_MINUS_F_M_G_D_V = b_trees:delete("k_v", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_V, _B_TREE_CLRS_500_MINUS_F_M_G_D_V), % case 3b - _B_TREE_CLRS_500_MINUS_F_M_G_D = b_trees:delete("k_d", ?B_TREE_CLRS_500_MINUS_F_M_G), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D, _B_TREE_CLRS_500_MINUS_F_M_G_D), - _B_TREE_CLRS_500_MINUS_F_M_G_U = b_trees:delete("k_u", ?B_TREE_CLRS_500_MINUS_F_M_G), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_U, _B_TREE_CLRS_500_MINUS_F_M_G_U), + _B_TREE_CLRS_500_MINUS_F_M_G_D = b_trees:delete("k_d", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D, _B_TREE_CLRS_500_MINUS_F_M_G_D), + _B_TREE_CLRS_500_MINUS_F_M_G_U = b_trees:delete("k_u", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_U, _B_TREE_CLRS_500_MINUS_F_M_G_U), ok. @@ -226,11 +226,11 @@ delete_clrs_test(_Config) -> %%-------------------------------------------------------------------- delete_error_test(_Config) -> - ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", ?B_TREE_06_00)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", test_generator:prepare_template(?B_TREE_06_00))), - ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", ?B_TREE_06_01)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", test_generator:prepare_template(?B_TREE_06_01))), - ?assertException(error, {key_not_found, "k_10"}, b_trees:delete("k_10", ?B_TREE_06_09)), + ?assertException(error, {key_not_found, "k_10"}, b_trees:delete("k_10", test_generator:prepare_template(?B_TREE_06_09))), ok. @@ -239,15 +239,15 @@ delete_error_test(_Config) -> %%-------------------------------------------------------------------- empty_b_tree_test(_Config) -> - ?assertEqual(?B_TREE_04_00, b_trees:empty(4)), + test_generator:check_equal(?B_TREE_04_00, b_trees:empty(4)), ?assert(b_trees:is_empty(b_trees:empty(4))), ?assertEqual(0, b_trees:size(b_trees:empty(4))), - ?assertEqual(?B_TREE_06_00, b_trees:empty(6)), + test_generator:check_equal(?B_TREE_06_00, b_trees:empty(6)), ?assert(b_trees:is_empty(b_trees:empty(6))), ?assertEqual(0, b_trees:size(b_trees:empty(6))), - ?assertEqual(?B_TREE_32_00, b_trees:empty(32)), + test_generator:check_equal(?B_TREE_32_00, b_trees:empty(32)), ?assert(b_trees:is_empty(b_trees:empty(32))), ?assertEqual(0, b_trees:size(b_trees:empty(32))), @@ -258,38 +258,38 @@ empty_b_tree_test(_Config) -> %%-------------------------------------------------------------------- enter_b_tree_order_4_test(_Config) -> - _BTree_04_15_01 = b_trees:enter("k_01", "v_01", ?B_TREE_04_00), - _BTree_04_15_02 = b_trees:enter("k_02", "v_02", _BTree_04_15_01), - _BTree_04_15_03 = b_trees:enter("k_03", "v_03", _BTree_04_15_02), - _BTree_04_15_04 = b_trees:enter("k_04", "v_04", _BTree_04_15_03), - _BTree_04_15_05 = b_trees:enter("k_05", "v_05", _BTree_04_15_04), - _BTree_04_15_06 = b_trees:enter("k_06", "v_06", _BTree_04_15_05), - _BTree_04_15_07 = b_trees:enter("k_07", "v_07", _BTree_04_15_06), - _BTree_04_15_08 = b_trees:enter("k_08", "v_08", _BTree_04_15_07), - _BTree_04_15_09 = b_trees:enter("k_09", "v_09", _BTree_04_15_08), - _BTree_04_15_10 = b_trees:enter("k_10", "v_10", _BTree_04_15_09), - _BTree_04_15_11 = b_trees:enter("k_11", "v_11", _BTree_04_15_10), - _BTree_04_15_12 = b_trees:enter("k_12", "v_12", _BTree_04_15_11), - _BTree_04_15_13 = b_trees:enter("k_13", "v_13", _BTree_04_15_12), - _BTree_04_15_14 = b_trees:enter("k_14", "v_14", _BTree_04_15_13), - _BTree_04_15_15 = b_trees:enter("k_15", "v_15", _BTree_04_15_14), - ?assertEqual(?B_TREE_04_15, _BTree_04_15_15), - - _BTree_04_15_01_NEW = b_trees:enter("k_01", "v_01_new", _BTree_04_15_15), - _BTree_04_15_02_NEW = b_trees:enter("k_02", "v_02_new", _BTree_04_15_01_NEW), - _BTree_04_15_03_NEW = b_trees:enter("k_03", "v_03_new", _BTree_04_15_02_NEW), - _BTree_04_15_04_NEW = b_trees:enter("k_04", "v_04_new", _BTree_04_15_03_NEW), - _BTree_04_15_05_NEW = b_trees:enter("k_05", "v_05_new", _BTree_04_15_04_NEW), - _BTree_04_15_06_NEW = b_trees:enter("k_06", "v_06_new", _BTree_04_15_05_NEW), - _BTree_04_15_07_NEW = b_trees:enter("k_07", "v_07_new", _BTree_04_15_06_NEW), - _BTree_04_15_08_NEW = b_trees:enter("k_08", "v_08_new", _BTree_04_15_07_NEW), - _BTree_04_15_09_NEW = b_trees:enter("k_09", "v_09_new", _BTree_04_15_08_NEW), - _BTree_04_15_10_NEW = b_trees:enter("k_10", "v_10_new", _BTree_04_15_09_NEW), - _BTree_04_15_11_NEW = b_trees:enter("k_11", "v_11_new", _BTree_04_15_10_NEW), - _BTree_04_15_12_NEW = b_trees:enter("k_12", "v_12_new", _BTree_04_15_11_NEW), - _BTree_04_15_13_NEW = b_trees:enter("k_13", "v_13_new", _BTree_04_15_12_NEW), - _BTree_04_15_14_NEW = b_trees:enter("k_14", "v_14_new", _BTree_04_15_13_NEW), - ?assertEqual(?B_TREE_04_15_UPDATE, b_trees:enter("k_15", "v_15_new", _BTree_04_15_14_NEW)), + BTree_04_15_01 = b_trees:enter("k_01", "v_01", test_generator:prepare_template(?B_TREE_04_00)), + BTree_04_15_02 = b_trees:enter("k_02", "v_02", BTree_04_15_01), + BTree_04_15_03 = b_trees:enter("k_03", "v_03", BTree_04_15_02), + BTree_04_15_04 = b_trees:enter("k_04", "v_04", BTree_04_15_03), + BTree_04_15_05 = b_trees:enter("k_05", "v_05", BTree_04_15_04), + BTree_04_15_06 = b_trees:enter("k_06", "v_06", BTree_04_15_05), + BTree_04_15_07 = b_trees:enter("k_07", "v_07", BTree_04_15_06), + BTree_04_15_08 = b_trees:enter("k_08", "v_08", BTree_04_15_07), + BTree_04_15_09 = b_trees:enter("k_09", "v_09", BTree_04_15_08), + BTree_04_15_10 = b_trees:enter("k_10", "v_10", BTree_04_15_09), + BTree_04_15_11 = b_trees:enter("k_11", "v_11", BTree_04_15_10), + BTree_04_15_12 = b_trees:enter("k_12", "v_12", BTree_04_15_11), + BTree_04_15_13 = b_trees:enter("k_13", "v_13", BTree_04_15_12), + BTree_04_15_14 = b_trees:enter("k_14", "v_14", BTree_04_15_13), + BTree_04_15_15 = b_trees:enter("k_15", "v_15", BTree_04_15_14), + test_generator:check_equal(?B_TREE_04_15, BTree_04_15_15), + + BTree_04_15_01_NEW = b_trees:enter("k_01", "v_01_new", BTree_04_15_15), + BTree_04_15_02_NEW = b_trees:enter("k_02", "v_02_new", BTree_04_15_01_NEW), + BTree_04_15_03_NEW = b_trees:enter("k_03", "v_03_new", BTree_04_15_02_NEW), + BTree_04_15_04_NEW = b_trees:enter("k_04", "v_04_new", BTree_04_15_03_NEW), + BTree_04_15_05_NEW = b_trees:enter("k_05", "v_05_new", BTree_04_15_04_NEW), + BTree_04_15_06_NEW = b_trees:enter("k_06", "v_06_new", BTree_04_15_05_NEW), + BTree_04_15_07_NEW = b_trees:enter("k_07", "v_07_new", BTree_04_15_06_NEW), + BTree_04_15_08_NEW = b_trees:enter("k_08", "v_08_new", BTree_04_15_07_NEW), + BTree_04_15_09_NEW = b_trees:enter("k_09", "v_09_new", BTree_04_15_08_NEW), + BTree_04_15_10_NEW = b_trees:enter("k_10", "v_10_new", BTree_04_15_09_NEW), + BTree_04_15_11_NEW = b_trees:enter("k_11", "v_11_new", BTree_04_15_10_NEW), + BTree_04_15_12_NEW = b_trees:enter("k_12", "v_12_new", BTree_04_15_11_NEW), + BTree_04_15_13_NEW = b_trees:enter("k_13", "v_13_new", BTree_04_15_12_NEW), + BTree_04_15_14_NEW = b_trees:enter("k_14", "v_14_new", BTree_04_15_13_NEW), + test_generator:check_equal(?B_TREE_04_15_UPDATE, b_trees:enter("k_15", "v_15_new", BTree_04_15_14_NEW)), ok. @@ -298,10 +298,10 @@ enter_b_tree_order_4_test(_Config) -> %%-------------------------------------------------------------------- from_dict_b_tree_test(_Config) -> - ?assertEqual(?B_TREE_04_04, b_trees:from_dict(4, test_generator:generate_key_values_from(4, 2))), - ?assertEqual(?B_TREE_06_01, b_trees:from_dict(6, test_generator:generate_key_values_from(1, 2))), - ?assertEqual(?B_TREE_06_29, b_trees:from_dict(6, test_generator:generate_key_values_from(29, 2))), - ?assertEqual(?B_TREE_18_19, b_trees:from_dict(18, test_generator:generate_key_values_from(19, 2))), + test_generator:check_equal(?B_TREE_04_04, b_trees:from_dict(4, test_generator:generate_key_values_from(4, 2))), + test_generator:check_equal(?B_TREE_06_01, b_trees:from_dict(6, test_generator:generate_key_values_from(1, 2))), + test_generator:check_equal(?B_TREE_06_29, b_trees:from_dict(6, test_generator:generate_key_values_from(29, 2))), + test_generator:check_equal(?B_TREE_18_19, b_trees:from_dict(18, test_generator:generate_key_values_from(19, 2))), ok. @@ -310,94 +310,94 @@ from_dict_b_tree_test(_Config) -> %%-------------------------------------------------------------------- get_test(_Config) -> - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_04_00)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_04_04)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_04_04)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_04_04)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_04_04)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_04_04)), - ?assertException(error, {key_not_found, "k_05"}, b_trees:get("k_05", ?B_TREE_04_04)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_06_07)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_06_07)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_06_07)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_06_07)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_06_07)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_06_07)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_06_07)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_06_07)), - ?assertException(error, {key_not_found, "k_08"}, b_trees:get("k_08", ?B_TREE_06_07)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_10_10)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_10_10)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_10_10)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_10_10)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_10_10)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_10_10)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_10_10)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_10_10)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_10_10)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_10_10)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_10_10)), - ?assertException(error, {key_not_found, "k_11"}, b_trees:get("k_11", ?B_TREE_10_10)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_12_13)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_12_13)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_12_13)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_12_13)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_12_13)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_12_13)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_12_13)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_12_13)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_12_13)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_12_13)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_12_13)), - ?assertEqual("v_11", b_trees:get("k_11", ?B_TREE_12_13)), - ?assertEqual("v_12", b_trees:get("k_12", ?B_TREE_12_13)), - ?assertEqual("v_13", b_trees:get("k_13", ?B_TREE_12_13)), - ?assertException(error, {key_not_found, "k_14"}, b_trees:get("k_14", ?B_TREE_12_13)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_16_16)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_16_16)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_16_16)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_16_16)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_16_16)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_16_16)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_16_16)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_16_16)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_16_16)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_16_16)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_16_16)), - ?assertEqual("v_11", b_trees:get("k_11", ?B_TREE_16_16)), - ?assertEqual("v_12", b_trees:get("k_12", ?B_TREE_16_16)), - ?assertEqual("v_13", b_trees:get("k_13", ?B_TREE_16_16)), - ?assertEqual("v_14", b_trees:get("k_14", ?B_TREE_16_16)), - ?assertEqual("v_15", b_trees:get("k_15", ?B_TREE_16_16)), - ?assertEqual("v_16", b_trees:get("k_16", ?B_TREE_16_16)), - ?assertException(error, {key_not_found, "k_17"}, b_trees:get("k_17", ?B_TREE_16_16)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_18_19)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_18_19)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_18_19)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_18_19)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_18_19)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_18_19)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_18_19)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_18_19)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_18_19)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_18_19)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_18_19)), - ?assertEqual("v_11", b_trees:get("k_11", ?B_TREE_18_19)), - ?assertEqual("v_12", b_trees:get("k_12", ?B_TREE_18_19)), - ?assertEqual("v_13", b_trees:get("k_13", ?B_TREE_18_19)), - ?assertEqual("v_14", b_trees:get("k_14", ?B_TREE_18_19)), - ?assertEqual("v_15", b_trees:get("k_15", ?B_TREE_18_19)), - ?assertEqual("v_16", b_trees:get("k_16", ?B_TREE_18_19)), - ?assertEqual("v_17", b_trees:get("k_17", ?B_TREE_18_19)), - ?assertEqual("v_18", b_trees:get("k_18", ?B_TREE_18_19)), - ?assertEqual("v_19", b_trees:get("k_19", ?B_TREE_18_19)), - ?assertException(error, {key_not_found, "k_20"}, b_trees:get("k_20", ?B_TREE_18_19)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_04_00))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_04_04))), + ?assertException(error, {key_not_found, "k_05"}, b_trees:get("k_05", test_generator:prepare_template(?B_TREE_04_04))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_06_07))), + ?assertException(error, {key_not_found, "k_08"}, b_trees:get("k_08", test_generator:prepare_template(?B_TREE_06_07))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_10_10))), + ?assertException(error, {key_not_found, "k_11"}, b_trees:get("k_11", test_generator:prepare_template(?B_TREE_10_10))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_11", b_trees:get("k_11", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_12", b_trees:get("k_12", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_13", b_trees:get("k_13", test_generator:prepare_template(?B_TREE_12_13))), + ?assertException(error, {key_not_found, "k_14"}, b_trees:get("k_14", test_generator:prepare_template(?B_TREE_12_13))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_11", b_trees:get("k_11", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_12", b_trees:get("k_12", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_13", b_trees:get("k_13", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_14", b_trees:get("k_14", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_15", b_trees:get("k_15", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_16", b_trees:get("k_16", test_generator:prepare_template(?B_TREE_16_16))), + ?assertException(error, {key_not_found, "k_17"}, b_trees:get("k_17", test_generator:prepare_template(?B_TREE_16_16))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_11", b_trees:get("k_11", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_12", b_trees:get("k_12", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_13", b_trees:get("k_13", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_14", b_trees:get("k_14", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_15", b_trees:get("k_15", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_16", b_trees:get("k_16", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_17", b_trees:get("k_17", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_18", b_trees:get("k_18", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_19", b_trees:get("k_19", test_generator:prepare_template(?B_TREE_18_19))), + ?assertException(error, {key_not_found, "k_20"}, b_trees:get("k_20", test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -406,11 +406,11 @@ get_test(_Config) -> %%-------------------------------------------------------------------- height_test(_Config) -> - ?assertException(error, {empty_tree, _}, b_trees:height(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:height(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual(0, b_trees:height(?B_TREE_06_02)), - ?assertEqual(1, b_trees:height(?B_TREE_06_06)), - ?assertEqual(2, b_trees:height(?B_TREE_06_21)), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_06))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_21))), ok. @@ -419,29 +419,29 @@ height_test(_Config) -> %%-------------------------------------------------------------------- insert_b_tree_order_4_test(_Config) -> - ?assertEqual(?B_TREE_04_00, b_trees:empty(4)), - - ?assertEqual(?B_TREE_04_01, test_generator:generate_b_tree_from_number(4, 1, 2)), - ?assertEqual(?B_TREE_04_02, test_generator:generate_b_tree_from_number(4, 2, 2)), - ?assertEqual(?B_TREE_04_03, test_generator:generate_b_tree_from_number(4, 3, 2)), - ?assertEqual(?B_TREE_04_04, test_generator:generate_b_tree_from_number(4, 4, 2)), - ?assertEqual(?B_TREE_04_05, test_generator:generate_b_tree_from_number(4, 5, 2)), - ?assertEqual(?B_TREE_04_06, test_generator:generate_b_tree_from_number(4, 6, 2)), - ?assertEqual(?B_TREE_04_07, test_generator:generate_b_tree_from_number(4, 7, 2)), - ?assertEqual(?B_TREE_04_08, test_generator:generate_b_tree_from_number(4, 8, 2)), - ?assertEqual(?B_TREE_04_09, test_generator:generate_b_tree_from_number(4, 9, 2)), - ?assertEqual(?B_TREE_04_10, test_generator:generate_b_tree_from_number(4, 10, 2)), - - ?assertEqual(?B_TREE_04_11, test_generator:generate_b_tree_from_number(4, 11, 2)), - ?assertEqual(?B_TREE_04_12, test_generator:generate_b_tree_from_number(4, 12, 2)), - ?assertEqual(?B_TREE_04_13, test_generator:generate_b_tree_from_number(4, 13, 2)), - ?assertEqual(?B_TREE_04_14, test_generator:generate_b_tree_from_number(4, 14, 2)), - ?assertEqual(?B_TREE_04_15, test_generator:generate_b_tree_from_number(4, 15, 2)), - ?assertEqual(?B_TREE_04_16, test_generator:generate_b_tree_from_number(4, 16, 2)), - ?assertEqual(?B_TREE_04_17, test_generator:generate_b_tree_from_number(4, 17, 2)), - ?assertEqual(?B_TREE_04_18, test_generator:generate_b_tree_from_number(4, 18, 2)), - ?assertEqual(?B_TREE_04_19, test_generator:generate_b_tree_from_number(4, 19, 2)), - ?assertEqual(?B_TREE_04_20, test_generator:generate_b_tree_from_number(4, 20, 2)), + test_generator:check_equal(?B_TREE_04_00, b_trees:empty(4)), + + test_generator:check_equal(?B_TREE_04_01, test_generator:generate_b_tree_from_number(4, 1, 2)), + test_generator:check_equal(?B_TREE_04_02, test_generator:generate_b_tree_from_number(4, 2, 2)), + test_generator:check_equal(?B_TREE_04_03, test_generator:generate_b_tree_from_number(4, 3, 2)), + test_generator:check_equal(?B_TREE_04_04, test_generator:generate_b_tree_from_number(4, 4, 2)), + test_generator:check_equal(?B_TREE_04_05, test_generator:generate_b_tree_from_number(4, 5, 2)), + test_generator:check_equal(?B_TREE_04_06, test_generator:generate_b_tree_from_number(4, 6, 2)), + test_generator:check_equal(?B_TREE_04_07, test_generator:generate_b_tree_from_number(4, 7, 2)), + test_generator:check_equal(?B_TREE_04_08, test_generator:generate_b_tree_from_number(4, 8, 2)), + test_generator:check_equal(?B_TREE_04_09, test_generator:generate_b_tree_from_number(4, 9, 2)), + test_generator:check_equal(?B_TREE_04_10, test_generator:generate_b_tree_from_number(4, 10, 2)), + + test_generator:check_equal(?B_TREE_04_11, test_generator:generate_b_tree_from_number(4, 11, 2)), + test_generator:check_equal(?B_TREE_04_12, test_generator:generate_b_tree_from_number(4, 12, 2)), + test_generator:check_equal(?B_TREE_04_13, test_generator:generate_b_tree_from_number(4, 13, 2)), + test_generator:check_equal(?B_TREE_04_14, test_generator:generate_b_tree_from_number(4, 14, 2)), + test_generator:check_equal(?B_TREE_04_15, test_generator:generate_b_tree_from_number(4, 15, 2)), + test_generator:check_equal(?B_TREE_04_16, test_generator:generate_b_tree_from_number(4, 16, 2)), + test_generator:check_equal(?B_TREE_04_17, test_generator:generate_b_tree_from_number(4, 17, 2)), + test_generator:check_equal(?B_TREE_04_18, test_generator:generate_b_tree_from_number(4, 18, 2)), + test_generator:check_equal(?B_TREE_04_19, test_generator:generate_b_tree_from_number(4, 19, 2)), + test_generator:check_equal(?B_TREE_04_20, test_generator:generate_b_tree_from_number(4, 20, 2)), ok. @@ -450,70 +450,70 @@ insert_b_tree_order_4_test(_Config) -> %%-------------------------------------------------------------------- insert_b_tree_order_6_test(_Config) -> - ?assertEqual(?B_TREE_06_00, b_trees:empty(6)), - ?assertEqual(0, b_trees:number_key_values(?B_TREE_06_00)), - ?assertException(error, {empty_tree, _}, b_trees:height(?B_TREE_06_00)), - ?assertEqual(0, b_trees:size(?B_TREE_06_00)), - - ?assertEqual(?B_TREE_06_01, b_trees:insert("k_01", "v_01", ?B_TREE_06_00)), - ?assertEqual(1, b_trees:number_key_values(?B_TREE_06_01)), - ?assertEqual(0, b_trees:height(?B_TREE_06_01)), - ?assertEqual(1, b_trees:size(?B_TREE_06_01)), - - ?assertEqual(?B_TREE_06_02, b_trees:insert("k_02", "v_02", test_generator:generate_b_tree_from_number(6, 1, 2))), - ?assertEqual(2, b_trees:number_key_values(?B_TREE_06_02)), - ?assertEqual(0, b_trees:height(?B_TREE_06_02)), - ?assertEqual(1, b_trees:size(?B_TREE_06_02)), - - ?assertEqual(?B_TREE_06_03, b_trees:insert("k_03", "v_03", test_generator:generate_b_tree_from_number(6, 2, 2))), - ?assertEqual(3, b_trees:number_key_values(?B_TREE_06_03)), - ?assertEqual(0, b_trees:height(?B_TREE_06_03)), - ?assertEqual(1, b_trees:size(?B_TREE_06_03)), - - ?assertEqual(?B_TREE_06_04, b_trees:insert("k_04", "v_04", test_generator:generate_b_tree_from_number(6, 3, 2))), - ?assertEqual(4, b_trees:number_key_values(?B_TREE_06_04)), - ?assertEqual(0, b_trees:height(?B_TREE_06_04)), - ?assertEqual(1, b_trees:size(?B_TREE_06_04)), - - ?assertEqual(?B_TREE_06_05, b_trees:insert("k_05", "v_05", test_generator:generate_b_tree_from_number(6, 4, 2))), - ?assertEqual(5, b_trees:number_key_values(?B_TREE_06_05)), - ?assertEqual(0, b_trees:height(?B_TREE_06_05)), - ?assertEqual(1, b_trees:size(?B_TREE_06_05)), - - ?assertEqual(?B_TREE_06_09, b_trees:insert("k_09", "v_09", test_generator:generate_b_tree_from_number(6, 8, 2))), - ?assertEqual(9, b_trees:number_key_values(?B_TREE_06_09)), - ?assertEqual(1, b_trees:height(?B_TREE_06_09)), - ?assertEqual(4, b_trees:size(?B_TREE_06_09)), - - ?assertEqual(?B_TREE_06_13, b_trees:insert("k_13", "v_13", test_generator:generate_b_tree_from_number(6, 12, 2))), - ?assertEqual(13, b_trees:number_key_values(?B_TREE_06_13)), - ?assertEqual(1, b_trees:height(?B_TREE_06_13)), - ?assertEqual(5, b_trees:size(?B_TREE_06_13)), - - ?assertEqual(?B_TREE_06_17, b_trees:insert("k_17", "v_17", test_generator:generate_b_tree_from_number(6, 16, 2))), - ?assertEqual(17, b_trees:number_key_values(?B_TREE_06_17)), - ?assertEqual(1, b_trees:height(?B_TREE_06_17)), - ?assertEqual(6, b_trees:size(?B_TREE_06_17)), - - ?assertEqual(?B_TREE_06_21, b_trees:insert("k_21", "v_21", test_generator:generate_b_tree_from_number(6, 20, 2))), - ?assertEqual(21, b_trees:number_key_values(?B_TREE_06_21)), - ?assertEqual(2, b_trees:height(?B_TREE_06_21)), - ?assertEqual(10, b_trees:size(?B_TREE_06_21)), - - ?assertEqual(?B_TREE_06_25, b_trees:insert("k_25", "v_25", test_generator:generate_b_tree_from_number(6, 24, 2))), - ?assertEqual(25, b_trees:number_key_values(?B_TREE_06_25)), - ?assertEqual(2, b_trees:height(?B_TREE_06_25)), - ?assertEqual(11, b_trees:size(?B_TREE_06_25)), - - ?assertEqual(?B_TREE_06_29, b_trees:insert("k_29", "v_29", test_generator:generate_b_tree_from_number(6, 28, 2))), - ?assertEqual(29, b_trees:number_key_values(?B_TREE_06_29)), - ?assertEqual(2, b_trees:height(?B_TREE_06_29)), - ?assertEqual(13, b_trees:size(?B_TREE_06_29)), - - ?assertEqual(?B_TREE_06_30, b_trees:insert("k_30", "v_30", test_generator:generate_b_tree_from_number(6, 29, 2))), - ?assertEqual(30, b_trees:number_key_values(?B_TREE_06_30)), - ?assertEqual(2, b_trees:height(?B_TREE_06_30)), - ?assertEqual(14, b_trees:size(?B_TREE_06_30)), + test_generator:check_equal(?B_TREE_06_00, b_trees:empty(6)), + ?assertEqual(0, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_00))), + ?assertException(error, {empty_tree, _}, b_trees:height(test_generator:prepare_template(?B_TREE_06_00))), + ?assertEqual(0, b_trees:size(test_generator:prepare_template(?B_TREE_06_00))), + + test_generator:check_equal(?B_TREE_06_01, b_trees:insert("k_01", "v_01", test_generator:prepare_template(?B_TREE_06_00))), + ?assertEqual(1, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_01))), + + test_generator:check_equal(?B_TREE_06_02, b_trees:insert("k_02", "v_02", test_generator:generate_b_tree_from_number(6, 1, 2))), + ?assertEqual(2, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_02))), + + test_generator:check_equal(?B_TREE_06_03, b_trees:insert("k_03", "v_03", test_generator:generate_b_tree_from_number(6, 2, 2))), + ?assertEqual(3, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_03))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_03))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_03))), + + test_generator:check_equal(?B_TREE_06_04, b_trees:insert("k_04", "v_04", test_generator:generate_b_tree_from_number(6, 3, 2))), + ?assertEqual(4, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_04))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_04))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_04))), + + test_generator:check_equal(?B_TREE_06_05, b_trees:insert("k_05", "v_05", test_generator:generate_b_tree_from_number(6, 4, 2))), + ?assertEqual(5, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_05))), + + test_generator:check_equal(?B_TREE_06_09, b_trees:insert("k_09", "v_09", test_generator:generate_b_tree_from_number(6, 8, 2))), + ?assertEqual(9, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual(4, b_trees:size(test_generator:prepare_template(?B_TREE_06_09))), + + test_generator:check_equal(?B_TREE_06_13, b_trees:insert("k_13", "v_13", test_generator:generate_b_tree_from_number(6, 12, 2))), + ?assertEqual(13, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_13))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_13))), + ?assertEqual(5, b_trees:size(test_generator:prepare_template(?B_TREE_06_13))), + + test_generator:check_equal(?B_TREE_06_17, b_trees:insert("k_17", "v_17", test_generator:generate_b_tree_from_number(6, 16, 2))), + ?assertEqual(17, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_17))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_17))), + ?assertEqual(6, b_trees:size(test_generator:prepare_template(?B_TREE_06_17))), + + test_generator:check_equal(?B_TREE_06_21, b_trees:insert("k_21", "v_21", test_generator:generate_b_tree_from_number(6, 20, 2))), + ?assertEqual(21, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_21))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_21))), + ?assertEqual(10, b_trees:size(test_generator:prepare_template(?B_TREE_06_21))), + + test_generator:check_equal(?B_TREE_06_25, b_trees:insert("k_25", "v_25", test_generator:generate_b_tree_from_number(6, 24, 2))), + ?assertEqual(25, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_25))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_25))), + ?assertEqual(11, b_trees:size(test_generator:prepare_template(?B_TREE_06_25))), + + test_generator:check_equal(?B_TREE_06_29, b_trees:insert("k_29", "v_29", test_generator:generate_b_tree_from_number(6, 28, 2))), + ?assertEqual(29, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_29))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_29))), + ?assertEqual(13, b_trees:size(test_generator:prepare_template(?B_TREE_06_29))), + + test_generator:check_equal(?B_TREE_06_30, b_trees:insert("k_30", "v_30", test_generator:generate_b_tree_from_number(6, 29, 2))), + ?assertEqual(30, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_30))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_30))), + ?assertEqual(14, b_trees:size(test_generator:prepare_template(?B_TREE_06_30))), ok. @@ -522,30 +522,30 @@ insert_b_tree_order_6_test(_Config) -> %%-------------------------------------------------------------------- insert_b_tree_order_8_test(_Config) -> - ?assertEqual(?B_TREE_08_00, b_trees:empty(8)), - ?assertEqual(0, b_trees:number_key_values(?B_TREE_08_00)), - ?assertException(error, {empty_tree, _}, b_trees:height(?B_TREE_08_00)), - ?assertEqual(0, b_trees:size(?B_TREE_08_00)), - - ?assertEqual(?B_TREE_06_07, b_trees:insert("k_07", "v_07", test_generator:generate_b_tree_from_number(6, 6, 2))), - ?assertEqual(7, b_trees:number_key_values(?B_TREE_06_07)), - ?assertEqual(1, b_trees:height(?B_TREE_06_07)), - ?assertEqual(3, b_trees:size(?B_TREE_06_07)), - - ?assertEqual(?B_TREE_08_16, b_trees:insert("k_16", "v_16", test_generator:generate_b_tree_from_number(8, 15, 2))), - ?assertEqual(16, b_trees:number_key_values(?B_TREE_08_16)), - ?assertEqual(1, b_trees:height(?B_TREE_08_16)), - ?assertEqual(5, b_trees:size(?B_TREE_08_16)), - - ?assertEqual(?B_TREE_08_32, b_trees:insert("k_32", "v_32", test_generator:generate_b_tree_from_number(8, 31, 2))), - ?assertEqual(32, b_trees:number_key_values(?B_TREE_08_32)), - ?assertEqual(1, b_trees:height(?B_TREE_08_32)), - ?assertEqual(9, b_trees:size(?B_TREE_08_32)), - - ?assertEqual(?B_TREE_08_64, b_trees:insert("k_64", "v_64", test_generator:generate_b_tree_from_number(8, 63, 2))), - ?assertEqual(64, b_trees:number_key_values(?B_TREE_08_64)), - ?assertEqual(2, b_trees:height(?B_TREE_08_64)), - ?assertEqual(20, b_trees:size(?B_TREE_08_64)), + test_generator:check_equal(?B_TREE_08_00, b_trees:empty(8)), + ?assertEqual(0, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_00))), + ?assertException(error, {empty_tree, _}, b_trees:height(test_generator:prepare_template(?B_TREE_08_00))), + ?assertEqual(0, b_trees:size(test_generator:prepare_template(?B_TREE_08_00))), + + test_generator:check_equal(?B_TREE_06_07, b_trees:insert("k_07", "v_07", test_generator:generate_b_tree_from_number(6, 6, 2))), + ?assertEqual(7, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual(3, b_trees:size(test_generator:prepare_template(?B_TREE_06_07))), + + test_generator:check_equal(?B_TREE_08_16, b_trees:insert("k_16", "v_16", test_generator:generate_b_tree_from_number(8, 15, 2))), + ?assertEqual(16, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_16))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_08_16))), + ?assertEqual(5, b_trees:size(test_generator:prepare_template(?B_TREE_08_16))), + + test_generator:check_equal(?B_TREE_08_32, b_trees:insert("k_32", "v_32", test_generator:generate_b_tree_from_number(8, 31, 2))), + ?assertEqual(32, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_32))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_08_32))), + ?assertEqual(9, b_trees:size(test_generator:prepare_template(?B_TREE_08_32))), + + test_generator:check_equal(?B_TREE_08_64, b_trees:insert("k_64", "v_64", test_generator:generate_b_tree_from_number(8, 63, 2))), + ?assertEqual(64, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_64))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_08_64))), + ?assertEqual(20, b_trees:size(test_generator:prepare_template(?B_TREE_08_64))), ok. @@ -555,17 +555,17 @@ insert_b_tree_order_8_test(_Config) -> %%-------------------------------------------------------------------- insert_clrs_test(_Config) -> - _B_TREE_CLRS_498_PLUS_B = b_trees:insert("k_b", "v_b", ?B_TREE_CLRS_498), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B, _B_TREE_CLRS_498_PLUS_B), + _B_TREE_CLRS_498_PLUS_B = b_trees:insert("k_b", "v_b", test_generator:prepare_template(?B_TREE_CLRS_498)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B, _B_TREE_CLRS_498_PLUS_B), - _B_TREE_CLRS_498_PLUS_B_Q = b_trees:insert("k_q", "v_q", ?B_TREE_CLRS_498_PLUS_B), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B_Q, _B_TREE_CLRS_498_PLUS_B_Q), + _B_TREE_CLRS_498_PLUS_B_Q = b_trees:insert("k_q", "v_q", test_generator:prepare_template(?B_TREE_CLRS_498_PLUS_B)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B_Q, _B_TREE_CLRS_498_PLUS_B_Q), - _B_TREE_CLRS_498_PLUS_B_Q_L = b_trees:insert("k_l", "v_l", ?B_TREE_CLRS_498_PLUS_B_Q), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B_Q_L, _B_TREE_CLRS_498_PLUS_B_Q_L), + _B_TREE_CLRS_498_PLUS_B_Q_L = b_trees:insert("k_l", "v_l", test_generator:prepare_template(?B_TREE_CLRS_498_PLUS_B_Q)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B_Q_L, _B_TREE_CLRS_498_PLUS_B_Q_L), - _B_TREE_CLRS_498_PLUS_B_Q_L_F = b_trees:insert("k_f", "v_f", ?B_TREE_CLRS_498_PLUS_B_Q_L), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B_Q_L_F, _B_TREE_CLRS_498_PLUS_B_Q_L_F), + _B_TREE_CLRS_498_PLUS_B_Q_L_F = b_trees:insert("k_f", "v_f", test_generator:prepare_template(?B_TREE_CLRS_498_PLUS_B_Q_L)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B_Q_L_F, _B_TREE_CLRS_498_PLUS_B_Q_L_F), ok. @@ -587,94 +587,94 @@ insert_error_test(_Config) -> %%-------------------------------------------------------------------- is_defined_test(_Config) -> - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_04_00)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_04_04)), - ?assertNot(b_trees:is_defined("k_05", ?B_TREE_04_04)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_06_07)), - ?assertNot(b_trees:is_defined("k_08", ?B_TREE_06_07)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_10_10)), - ?assertNot(b_trees:is_defined("k_11", ?B_TREE_10_10)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_11", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_12", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_13", ?B_TREE_12_13)), - ?assertNot(b_trees:is_defined("k_14", ?B_TREE_12_13)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_11", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_12", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_13", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_14", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_15", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_16", ?B_TREE_16_16)), - ?assertNot(b_trees:is_defined("k_17", ?B_TREE_16_16)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_11", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_12", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_13", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_14", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_15", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_16", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_17", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_18", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_19", ?B_TREE_18_19)), - ?assertNot(b_trees:is_defined("k_20", ?B_TREE_18_19)), + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_04_00))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_04_04))), + ?assertNot(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_04_04))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_06_07))), + ?assertNot(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_06_07))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_10_10))), + ?assertNot(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_10_10))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_12", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_13", test_generator:prepare_template(?B_TREE_12_13))), + ?assertNot(b_trees:is_defined("k_14", test_generator:prepare_template(?B_TREE_12_13))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_12", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_13", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_14", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_15", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_16", test_generator:prepare_template(?B_TREE_16_16))), + ?assertNot(b_trees:is_defined("k_17", test_generator:prepare_template(?B_TREE_16_16))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_12", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_13", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_14", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_15", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_16", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_17", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_18", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_19", test_generator:prepare_template(?B_TREE_18_19))), + ?assertNot(b_trees:is_defined("k_20", test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -683,8 +683,8 @@ is_defined_test(_Config) -> %%-------------------------------------------------------------------- is_empty_test(_Config) -> - ?assertEqual(false, b_trees:is_empty(?B_TREE_32_01)), - ?assertEqual(true, b_trees:is_empty(?B_TREE_32_00)), + ?assertEqual(false, b_trees:is_empty(test_generator:prepare_template(?B_TREE_32_01))), + ?assertEqual(true, b_trees:is_empty(test_generator:prepare_template(?B_TREE_32_00))), ok. @@ -778,22 +778,22 @@ iterator_from_next_04_16_test(_Config) -> BTree = test_generator:generate_b_tree_from_number(4, Number, 2), KeyValues = test_generator:generate_key_values_from(Number, 2), - ?assertEqual(lists:sublist(KeyValues, 1, Number), iterate_next_b_tree(b_trees:iterator_from("k_00", BTree), Number - 0, [])), - ?assertEqual(lists:sublist(KeyValues, 2, Number), iterate_next_b_tree(b_trees:iterator_from("k_02", BTree), Number - 1, [])), - ?assertEqual(lists:sublist(KeyValues, 3, Number), iterate_next_b_tree(b_trees:iterator_from("k_03", BTree), Number - 2, [])), - ?assertEqual(lists:sublist(KeyValues, 4, Number), iterate_next_b_tree(b_trees:iterator_from("k_04", BTree), Number - 3, [])), - ?assertEqual(lists:sublist(KeyValues, 5, Number), iterate_next_b_tree(b_trees:iterator_from("k_05", BTree), Number - 4, [])), - ?assertEqual(lists:sublist(KeyValues, 6, Number), iterate_next_b_tree(b_trees:iterator_from("k_06", BTree), Number - 5, [])), - ?assertEqual(lists:sublist(KeyValues, 7, Number), iterate_next_b_tree(b_trees:iterator_from("k_07", BTree), Number - 6, [])), - ?assertEqual(lists:sublist(KeyValues, 8, Number), iterate_next_b_tree(b_trees:iterator_from("k_08", BTree), Number - 7, [])), - ?assertEqual(lists:sublist(KeyValues, 9, Number), iterate_next_b_tree(b_trees:iterator_from("k_09", BTree), Number - 8, [])), - ?assertEqual(lists:sublist(KeyValues, 10, Number), iterate_next_b_tree(b_trees:iterator_from("k_10", BTree), Number - 9, [])), - ?assertEqual(lists:sublist(KeyValues, 11, Number), iterate_next_b_tree(b_trees:iterator_from("k_11", BTree), Number - 10, [])), - ?assertEqual(lists:sublist(KeyValues, 12, Number), iterate_next_b_tree(b_trees:iterator_from("k_12", BTree), Number - 11, [])), - ?assertEqual(lists:sublist(KeyValues, 13, Number), iterate_next_b_tree(b_trees:iterator_from("k_13", BTree), Number - 12, [])), - ?assertEqual(lists:sublist(KeyValues, 14, Number), iterate_next_b_tree(b_trees:iterator_from("k_14", BTree), Number - 13, [])), - ?assertEqual(lists:sublist(KeyValues, 15, Number), iterate_next_b_tree(b_trees:iterator_from("k_15", BTree), Number - 14, [])), - ?assertEqual(lists:sublist(KeyValues, 16, Number), iterate_next_b_tree(b_trees:iterator_from("k_16", BTree), Number - 15, [])), + ?assertEqual(lists:sublist(KeyValues, 1, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_00", BTree), Number - 0, [])), + ?assertEqual(lists:sublist(KeyValues, 2, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_02", BTree), Number - 1, [])), + ?assertEqual(lists:sublist(KeyValues, 3, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_03", BTree), Number - 2, [])), + ?assertEqual(lists:sublist(KeyValues, 4, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_04", BTree), Number - 3, [])), + ?assertEqual(lists:sublist(KeyValues, 5, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_05", BTree), Number - 4, [])), + ?assertEqual(lists:sublist(KeyValues, 6, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_06", BTree), Number - 5, [])), + ?assertEqual(lists:sublist(KeyValues, 7, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_07", BTree), Number - 6, [])), + ?assertEqual(lists:sublist(KeyValues, 8, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_08", BTree), Number - 7, [])), + ?assertEqual(lists:sublist(KeyValues, 9, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_09", BTree), Number - 8, [])), + ?assertEqual(lists:sublist(KeyValues, 10, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_10", BTree), Number - 9, [])), + ?assertEqual(lists:sublist(KeyValues, 11, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_11", BTree), Number - 10, [])), + ?assertEqual(lists:sublist(KeyValues, 12, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_12", BTree), Number - 11, [])), + ?assertEqual(lists:sublist(KeyValues, 13, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_13", BTree), Number - 12, [])), + ?assertEqual(lists:sublist(KeyValues, 14, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_14", BTree), Number - 13, [])), + ?assertEqual(lists:sublist(KeyValues, 15, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_15", BTree), Number - 14, [])), + ?assertEqual(lists:sublist(KeyValues, 16, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_16", BTree), Number - 15, [])), ok. @@ -821,30 +821,30 @@ iterator_from_next_08_256_test(_Config) -> BTree = test_generator:generate_b_tree_from_number(4, Number, 3), KeyValues = test_generator:generate_key_values_from(Number, 3), - ?assertEqual(lists:sublist(KeyValues, 1, Number), iterate_next_b_tree(b_trees:iterator_from("k_000", BTree), Number - 0, [])), - ?assertEqual(lists:sublist(KeyValues, 2, Number), iterate_next_b_tree(b_trees:iterator_from("k_002", BTree), Number - 1, [])), - ?assertEqual(lists:sublist(KeyValues, 3, Number), iterate_next_b_tree(b_trees:iterator_from("k_003", BTree), Number - 2, [])), - ?assertEqual(lists:sublist(KeyValues, 4, Number), iterate_next_b_tree(b_trees:iterator_from("k_004", BTree), Number - 3, [])), - ?assertEqual(lists:sublist(KeyValues, 5, Number), iterate_next_b_tree(b_trees:iterator_from("k_005", BTree), Number - 4, [])), - ?assertEqual(lists:sublist(KeyValues, 7, Number), iterate_next_b_tree(b_trees:iterator_from("k_007", BTree), Number - 6, [])), - ?assertEqual(lists:sublist(KeyValues, 8, Number), iterate_next_b_tree(b_trees:iterator_from("k_008", BTree), Number - 7, [])), - ?assertEqual(lists:sublist(KeyValues, 11, Number), iterate_next_b_tree(b_trees:iterator_from("k_011", BTree), Number - 10, [])), - ?assertEqual(lists:sublist(KeyValues, 13, Number), iterate_next_b_tree(b_trees:iterator_from("k_013", BTree), Number - 12, [])), - ?assertEqual(lists:sublist(KeyValues, 16, Number), iterate_next_b_tree(b_trees:iterator_from("k_016", BTree), Number - 15, [])), - ?assertEqual(lists:sublist(KeyValues, 17, Number), iterate_next_b_tree(b_trees:iterator_from("k_017", BTree), Number - 16, [])), - ?assertEqual(lists:sublist(KeyValues, 19, Number), iterate_next_b_tree(b_trees:iterator_from("k_019", BTree), Number - 18, [])), - ?assertEqual(lists:sublist(KeyValues, 23, Number), iterate_next_b_tree(b_trees:iterator_from("k_023", BTree), Number - 22, [])), - ?assertEqual(lists:sublist(KeyValues, 29, Number), iterate_next_b_tree(b_trees:iterator_from("k_029", BTree), Number - 28, [])), - ?assertEqual(lists:sublist(KeyValues, 31, Number), iterate_next_b_tree(b_trees:iterator_from("k_031", BTree), Number - 30, [])), - ?assertEqual(lists:sublist(KeyValues, 32, Number), iterate_next_b_tree(b_trees:iterator_from("k_032", BTree), Number - 31, [])), - ?assertEqual(lists:sublist(KeyValues, 37, Number), iterate_next_b_tree(b_trees:iterator_from("k_037", BTree), Number - 36, [])), - ?assertEqual(lists:sublist(KeyValues, 41, Number), iterate_next_b_tree(b_trees:iterator_from("k_041", BTree), Number - 40, [])), - ?assertEqual(lists:sublist(KeyValues, 43, Number), iterate_next_b_tree(b_trees:iterator_from("k_043", BTree), Number - 42, [])), - ?assertEqual(lists:sublist(KeyValues, 47, Number), iterate_next_b_tree(b_trees:iterator_from("k_047", BTree), Number - 46, [])), - ?assertEqual(lists:sublist(KeyValues, 49, Number), iterate_next_b_tree(b_trees:iterator_from("k_049", BTree), Number - 48, [])), - ?assertEqual(lists:sublist(KeyValues, 64, Number), iterate_next_b_tree(b_trees:iterator_from("k_064", BTree), Number - 63, [])), - ?assertEqual(lists:sublist(KeyValues, 128, Number), iterate_next_b_tree(b_trees:iterator_from("k_128", BTree), Number - 127, [])), - ?assertEqual(lists:sublist(KeyValues, 256, Number), iterate_next_b_tree(b_trees:iterator_from("k_256", BTree), Number - 255, [])), + ?assertEqual(lists:sublist(KeyValues, 1, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_000", BTree), Number - 0, [])), + ?assertEqual(lists:sublist(KeyValues, 2, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_002", BTree), Number - 1, [])), + ?assertEqual(lists:sublist(KeyValues, 3, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_003", BTree), Number - 2, [])), + ?assertEqual(lists:sublist(KeyValues, 4, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_004", BTree), Number - 3, [])), + ?assertEqual(lists:sublist(KeyValues, 5, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_005", BTree), Number - 4, [])), + ?assertEqual(lists:sublist(KeyValues, 7, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_007", BTree), Number - 6, [])), + ?assertEqual(lists:sublist(KeyValues, 8, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_008", BTree), Number - 7, [])), + ?assertEqual(lists:sublist(KeyValues, 11, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_011", BTree), Number - 10, [])), + ?assertEqual(lists:sublist(KeyValues, 13, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_013", BTree), Number - 12, [])), + ?assertEqual(lists:sublist(KeyValues, 16, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_016", BTree), Number - 15, [])), + ?assertEqual(lists:sublist(KeyValues, 17, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_017", BTree), Number - 16, [])), + ?assertEqual(lists:sublist(KeyValues, 19, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_019", BTree), Number - 18, [])), + ?assertEqual(lists:sublist(KeyValues, 23, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_023", BTree), Number - 22, [])), + ?assertEqual(lists:sublist(KeyValues, 29, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_029", BTree), Number - 28, [])), + ?assertEqual(lists:sublist(KeyValues, 31, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_031", BTree), Number - 30, [])), + ?assertEqual(lists:sublist(KeyValues, 32, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_032", BTree), Number - 31, [])), + ?assertEqual(lists:sublist(KeyValues, 37, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_037", BTree), Number - 36, [])), + ?assertEqual(lists:sublist(KeyValues, 41, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_041", BTree), Number - 40, [])), + ?assertEqual(lists:sublist(KeyValues, 43, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_043", BTree), Number - 42, [])), + ?assertEqual(lists:sublist(KeyValues, 47, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_047", BTree), Number - 46, [])), + ?assertEqual(lists:sublist(KeyValues, 49, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_049", BTree), Number - 48, [])), + ?assertEqual(lists:sublist(KeyValues, 64, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_064", BTree), Number - 63, [])), + ?assertEqual(lists:sublist(KeyValues, 128, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_128", BTree), Number - 127, [])), + ?assertEqual(lists:sublist(KeyValues, 256, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_256", BTree), Number - 255, [])), ok. @@ -958,23 +958,23 @@ iterator_next_test(_Config) -> %%-------------------------------------------------------------------- keys_test(_Config) -> - ?assertEqual([], b_trees:keys(?B_TREE_06_00)), + ?assertEqual([], b_trees:keys(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual(["k_01"], b_trees:keys(?B_TREE_06_01)), + ?assertEqual(["k_01"], b_trees:keys(test_generator:prepare_template(?B_TREE_06_01))), - _Keys_06_02 = b_trees:keys(?B_TREE_06_02), + _Keys_06_02 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_02)), ?assertEqual(test_generator:generate_keys_from(2, 2), _Keys_06_02), ?assertEqual(2, length(_Keys_06_02)), - _Keys_06_05 = b_trees:keys(?B_TREE_06_05), + _Keys_06_05 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_05)), ?assertEqual(test_generator:generate_keys_from(5, 2), _Keys_06_05), ?assertEqual(5, length(_Keys_06_05)), - _Keys_06_09 = b_trees:keys(?B_TREE_06_09), + _Keys_06_09 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_09)), ?assertEqual(test_generator:generate_keys_from(9, 2), _Keys_06_09), ?assertEqual(9, length(_Keys_06_09)), - _Keys_06_16 = b_trees:keys(?B_TREE_06_16), + _Keys_06_16 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_16)), ?assertEqual(test_generator:generate_keys_from(16, 2), _Keys_06_16), ?assertEqual(16, length(_Keys_06_16)), @@ -985,15 +985,15 @@ keys_test(_Config) -> %%-------------------------------------------------------------------- largest_test(_Config) -> - ?assertException(error, {empty_tree, _}, b_trees:largest(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual({"k_01", "v_01"}, b_trees:largest(?B_TREE_06_01)), - ?assertEqual({"k_02", "v_02"}, b_trees:largest(?B_TREE_06_02)), - ?assertEqual({"k_05", "v_05"}, b_trees:largest(?B_TREE_06_05)), - ?assertEqual({"k_09", "v_09"}, b_trees:largest(?B_TREE_06_09)), - ?assertEqual({"k_16", "v_16"}, b_trees:largest(?B_TREE_06_16)), + ?assertEqual({"k_01", "v_01"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual({"k_02", "v_02"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual({"k_05", "v_05"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual({"k_09", "v_09"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual({"k_16", "v_16"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_16))), - ?assertEqual({"k_19", "v_19"}, b_trees:largest(?B_TREE_18_19)), + ?assertEqual({"k_19", "v_19"}, b_trees:largest(test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1002,94 +1002,94 @@ largest_test(_Config) -> %%-------------------------------------------------------------------- lookup_test(_Config) -> - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_04_00)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_04_04)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_04_04)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_04_04)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_04_04)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_04_04)), - ?assertEqual(none, b_trees:lookup("k_05", ?B_TREE_04_04)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_06_07)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_06_07)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_06_07)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_06_07)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_06_07)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_06_07)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_06_07)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_06_07)), - ?assertEqual(none, b_trees:lookup("k_08", ?B_TREE_06_07)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_10_10)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_10_10)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_10_10)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_10_10)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_10_10)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_10_10)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_10_10)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_10_10)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_10_10)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_10_10)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_10_10)), - ?assertEqual(none, b_trees:lookup("k_11", ?B_TREE_10_10)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_12_13)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_12_13)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_12_13)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_12_13)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_12_13)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_12_13)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_12_13)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_12_13)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_12_13)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_12_13)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_12_13)), - ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", ?B_TREE_12_13)), - ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", ?B_TREE_12_13)), - ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", ?B_TREE_12_13)), - ?assertEqual(none, b_trees:lookup("k_14", ?B_TREE_12_13)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_16_16)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_16_16)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_16_16)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_16_16)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_16_16)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_16_16)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_16_16)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_16_16)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_16_16)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_16_16)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_16_16)), - ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", ?B_TREE_16_16)), - ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", ?B_TREE_16_16)), - ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", ?B_TREE_16_16)), - ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", ?B_TREE_16_16)), - ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", ?B_TREE_16_16)), - ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", ?B_TREE_16_16)), - ?assertEqual(none, b_trees:lookup("k_17", ?B_TREE_16_16)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_18_19)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_18_19)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_18_19)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_18_19)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_18_19)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_18_19)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_18_19)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_18_19)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_18_19)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_18_19)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_18_19)), - ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", ?B_TREE_18_19)), - ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", ?B_TREE_18_19)), - ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", ?B_TREE_18_19)), - ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", ?B_TREE_18_19)), - ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", ?B_TREE_18_19)), - ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", ?B_TREE_18_19)), - ?assertEqual({value, "v_17"}, b_trees:lookup("k_17", ?B_TREE_18_19)), - ?assertEqual({value, "v_18"}, b_trees:lookup("k_18", ?B_TREE_18_19)), - ?assertEqual({value, "v_19"}, b_trees:lookup("k_19", ?B_TREE_18_19)), - ?assertEqual(none, b_trees:lookup("k_20", ?B_TREE_18_19)), + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_04_00))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual(none, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_04_04))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual(none, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_06_07))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual(none, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_10_10))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual(none, b_trees:lookup("k_14", test_generator:prepare_template(?B_TREE_12_13))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual(none, b_trees:lookup("k_17", test_generator:prepare_template(?B_TREE_16_16))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_17"}, b_trees:lookup("k_17", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_18"}, b_trees:lookup("k_18", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_19"}, b_trees:lookup("k_19", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual(none, b_trees:lookup("k_20", test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1098,19 +1098,16 @@ lookup_test(_Config) -> %%-------------------------------------------------------------------- map_b_tree_order_4_test(_Config) -> - ?assertEqual(?B_TREE_04_15_UPDATE, b_trees:map(fun map_value_to_new/2, ?B_TREE_04_15)), + test_generator:check_equal(?B_TREE_04_15_UPDATE, b_trees:map(fun test_generator:map_value_to_new/2, test_generator:prepare_template(?B_TREE_04_15))), ok. -map_value_to_new(_, Value) -> - Value ++ "_new". - %%-------------------------------------------------------------------- %% TEST CASES: map - error %%-------------------------------------------------------------------- map_error_test(_Config) -> - ?assertException(error, {empty_tree, ?B_TREE_06_00}, b_trees:map(fun map_value_to_new/2, ?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:map(fun test_generator:map_value_to_new/2, test_generator:prepare_template(?B_TREE_06_00))), ok. @@ -1119,13 +1116,13 @@ map_error_test(_Config) -> %%-------------------------------------------------------------------- number_key_values_test(_Config) -> - ?assertEqual(0, b_trees:number_key_values(?B_TREE_06_00)), - ?assertEqual(2, b_trees:number_key_values(?B_TREE_06_02)), - ?assertEqual(5, b_trees:number_key_values(?B_TREE_06_05)), - ?assertEqual(16, b_trees:number_key_values(?B_TREE_06_16)), - ?assertEqual(29, b_trees:number_key_values(?B_TREE_06_29)), + ?assertEqual(0, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_00))), + ?assertEqual(2, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(5, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual(16, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_16))), + ?assertEqual(29, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_29))), - ?assertEqual(19, b_trees:number_key_values(?B_TREE_18_19)), + ?assertEqual(19, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1136,11 +1133,11 @@ number_key_values_test(_Config) -> size_test(_Config) -> ?assertEqual(0, b_trees:size(b_trees:empty(6))), - ?assertEqual(1, b_trees:size(?B_TREE_06_03)), - ?assertEqual(3, b_trees:size(?B_TREE_06_08)), - ?assertEqual(5, b_trees:size(?B_TREE_06_13)), - ?assertEqual(7, b_trees:size(?B_TREE_06_20)), - ?assertEqual(10, b_trees:size(?B_TREE_06_21)), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_03))), + ?assertEqual(3, b_trees:size(test_generator:prepare_template(?B_TREE_06_08))), + ?assertEqual(5, b_trees:size(test_generator:prepare_template(?B_TREE_06_13))), + ?assertEqual(7, b_trees:size(test_generator:prepare_template(?B_TREE_06_20))), + ?assertEqual(10, b_trees:size(test_generator:prepare_template(?B_TREE_06_21))), ok. @@ -1149,14 +1146,14 @@ size_test(_Config) -> %%-------------------------------------------------------------------- smallest_test(_Config) -> - ?assertException(error, {empty_tree, _}, b_trees:smallest(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_01)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_02)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_05)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_09)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_16)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_18_19)), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_16))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1167,27 +1164,27 @@ smallest_test(_Config) -> take_largest_test(_Config) -> ?assertException(error, {empty_tree, _}, b_trees:take_largest(?B_TREE_06_00)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 3, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 6, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 9, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 12, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 15, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 18, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 21, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 24, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 27, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 30, 2)), - - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 4, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 8, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 12, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 16, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 20, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 24, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 28, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 32, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 36, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 40, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 3, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 6, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 9, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 12, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 15, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 18, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 21, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 24, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 27, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 30, 2)), + + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 4, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 8, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 12, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 16, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 20, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 24, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 28, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 32, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 36, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 40, 2)), ok. @@ -1198,27 +1195,27 @@ take_largest_test(_Config) -> take_smallest_test(_Config) -> ?assertException(error, {empty_tree, _}, b_trees:take_smallest(?B_TREE_06_00)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 3, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 6, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 9, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 12, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 15, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 18, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 21, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 24, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 27, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 30, 2)), - - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 4, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 8, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 12, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 16, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 20, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 24, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 28, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 32, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 36, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 40, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 3, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 6, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 9, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 12, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 15, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 18, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 21, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 24, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 27, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 30, 2)), + + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 4, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 8, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 12, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 16, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 20, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 24, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 28, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 32, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 36, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 40, 2)), ok. @@ -1227,23 +1224,23 @@ take_smallest_test(_Config) -> %%-------------------------------------------------------------------- to_list_test(_Config) -> - ?assertException(error, {empty_tree, _}, b_trees:to_list(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:to_list(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual([{"k_01", "v_01"}], b_trees:to_list(?B_TREE_06_01)), + ?assertEqual([{"k_01", "v_01"}], b_trees:to_list(test_generator:prepare_template(?B_TREE_06_01))), - _KeyValues_06_02 = b_trees:to_list(?B_TREE_06_02), + _KeyValues_06_02 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_02)), ?assertEqual(test_generator:generate_key_values_from(2, 2), _KeyValues_06_02), ?assertEqual(2, length(_KeyValues_06_02)), - _KeyValues_06_05 = b_trees:to_list(?B_TREE_06_05), + _KeyValues_06_05 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_05)), ?assertEqual(test_generator:generate_key_values_from(5, 2), _KeyValues_06_05), ?assertEqual(5, length(_KeyValues_06_05)), - _KeyValues_06_09 = b_trees:to_list(?B_TREE_06_09), + _KeyValues_06_09 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_09)), ?assertEqual(test_generator:generate_key_values_from(9, 2), _KeyValues_06_09), ?assertEqual(9, length(_KeyValues_06_09)), - _KeyValues_06_16 = b_trees:to_list(?B_TREE_06_16), + _KeyValues_06_16 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_16)), ?assertEqual(test_generator:generate_key_values_from(16, 2), _KeyValues_06_16), ?assertEqual(16, length(_KeyValues_06_16)), @@ -1254,7 +1251,7 @@ to_list_test(_Config) -> %%-------------------------------------------------------------------- update_b_tree_order_4_test(_Config) -> - BTree_04_15_K_01 = b_trees:update("k_01", "v_01_new", ?B_TREE_04_15), + BTree_04_15_K_01 = b_trees:update("k_01", "v_01_new", test_generator:prepare_template(?B_TREE_04_15)), BTree_04_15_K_02 = b_trees:update("k_02", "v_02_new", BTree_04_15_K_01), BTree_04_15_K_03 = b_trees:update("k_03", "v_03_new", BTree_04_15_K_02), BTree_04_15_K_04 = b_trees:update("k_04", "v_04_new", BTree_04_15_K_03), @@ -1268,7 +1265,7 @@ update_b_tree_order_4_test(_Config) -> BTree_04_15_K_12 = b_trees:update("k_12", "v_12_new", BTree_04_15_K_11), BTree_04_15_K_13 = b_trees:update("k_13", "v_13_new", BTree_04_15_K_12), _BTree_04_15_K_14 = b_trees:update("k_14", "v_14_new", BTree_04_15_K_13), - ?assertEqual(?B_TREE_04_15_UPDATE, b_trees:update("k_15", "v_15_new", _BTree_04_15_K_14)), + test_generator:check_equal(?B_TREE_04_15_UPDATE, b_trees:update("k_15", "v_15_new", _BTree_04_15_K_14)), ok. @@ -1277,12 +1274,12 @@ update_b_tree_order_4_test(_Config) -> %%-------------------------------------------------------------------- update_error_test(_Config) -> - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_06_00)), - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_06_02)), - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_06_29)), - ?assertException(error, {key_not_found, "k_30"}, b_trees:update("k_30", "v_30_new", ?B_TREE_06_29)), - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_08_64)), - ?assertException(error, {key_not_found, "k_65"}, b_trees:update("k_65", "v_65_new", ?B_TREE_08_64)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_06_00))), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_06_02))), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_06_29))), + ?assertException(error, {key_not_found, "k_30"}, b_trees:update("k_30", "v_30_new", test_generator:prepare_template(?B_TREE_06_29))), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_08_64))), + ?assertException(error, {key_not_found, "k_65"}, b_trees:update("k_65", "v_65_new", test_generator:prepare_template(?B_TREE_08_64))), ok. @@ -1291,23 +1288,13 @@ update_error_test(_Config) -> %%-------------------------------------------------------------------- values_test(_Config) -> - ?assertEqual([], b_trees:values(?B_TREE_06_00)), + ?assertEqual([], b_trees:values(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual(["v_01"], b_trees:values(?B_TREE_06_01)), + ?assertEqual(["v_01"], b_trees:values(test_generator:prepare_template(?B_TREE_06_01))), - ?assertEqual(2, length(b_trees:values(?B_TREE_06_02))), - ?assertEqual(5, length(b_trees:values(?B_TREE_06_05))), - ?assertEqual(9, length(b_trees:values(?B_TREE_06_09))), - ?assertEqual(16, length(b_trees:values(?B_TREE_06_16))), + ?assertEqual(2, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_02)))), + ?assertEqual(5, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_05)))), + ?assertEqual(9, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_09)))), + ?assertEqual(16, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_16)))), ok. - -%%-------------------------------------------------------------------- -%% Helper functions. -%%-------------------------------------------------------------------- - -iterate_next_b_tree(_, 0, KeyValues) -> - KeyValues; -iterate_next_b_tree(Iterator, Count, KeyValues) -> - {Key, Value, IteratorNew} = b_trees:next(Iterator), - iterate_next_b_tree(IteratorNew, Count - 1, KeyValues ++ [{Key, Value}]). diff --git a/test/b_trees_test.erl b/test/b_trees_test.erl index 81ce5c4..2e6da95 100644 --- a/test/b_trees_test.erl +++ b/test/b_trees_test.erl @@ -20,11 +20,11 @@ %%-------------------------------------------------------------------- delete_any_test() -> - ?assertEqual(?B_TREE_06_00, b_trees:delete_any("k_00", ?B_TREE_06_00)), - ?assertEqual(?B_TREE_06_00, b_trees:delete_any("k_01", ?B_TREE_06_01)), - ?assertEqual(?B_TREE_06_01, b_trees:delete_any("k_00", ?B_TREE_06_01)), - ?assertEqual(?B_TREE_06_03, b_trees:delete_any("k_04", ?B_TREE_06_04)), - ?assertEqual(?B_TREE_06_06, b_trees:delete_any("k_07", ?B_TREE_06_07)), + test_generator:check_equal(?B_TREE_06_00, b_trees:delete_any("k_00", test_generator:prepare_template(?B_TREE_06_00))), + test_generator:check_equal(?B_TREE_06_00, b_trees:delete_any("k_01", test_generator:prepare_template(?B_TREE_06_01))), + test_generator:check_equal(?B_TREE_06_01, b_trees:delete_any("k_00", test_generator:prepare_template(?B_TREE_06_01))), + test_generator:check_equal(?B_TREE_06_03, b_trees:delete_any("k_04", test_generator:prepare_template(?B_TREE_06_04))), + test_generator:check_equal(?B_TREE_06_06, b_trees:delete_any("k_07", test_generator:prepare_template(?B_TREE_06_07))), ok. @@ -33,30 +33,30 @@ delete_any_test() -> %%-------------------------------------------------------------------- delete_b_tree_order_4_test() -> - ?assertEqual(?B_TREE_04_10_MINUS_02, b_trees:delete("k_02", ?B_TREE_04_10)), - - ?assertEqual(?B_TREE_04_17_MINUS_02, b_trees:delete("k_02", ?B_TREE_04_17)), - ?assertEqual(?B_TREE_04_17_MINUS_02_04, b_trees:delete("k_04", ?B_TREE_04_17_MINUS_02)), - ?assertEqual(?B_TREE_04_17_MINUS_02_TILL_12, b_trees:delete("k_12", ?B_TREE_04_17_MINUS_02_TILL_10)), - - ?assertEqual(?B_TREE_04_20_MINUS_02, b_trees:delete("k_02", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_04, b_trees:delete("k_04", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_06, b_trees:delete("k_06", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_08, b_trees:delete("k_08", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_10, b_trees:delete("k_10", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_12, b_trees:delete("k_12", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_14, b_trees:delete("k_14", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_16, b_trees:delete("k_16", ?B_TREE_04_20)), - ?assertEqual(?B_TREE_04_20_MINUS_18, b_trees:delete("k_18", ?B_TREE_04_20)), - - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_18, b_trees:delete("k_18", ?B_TREE_04_33_MINUS_02_TILL_16)), - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_20, b_trees:delete("k_20", ?B_TREE_04_33_MINUS_02_TILL_18)), - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_22, b_trees:delete("k_22", ?B_TREE_04_33_MINUS_02_TILL_20)), - ?assertEqual(?B_TREE_04_33_MINUS_02_TILL_30, b_trees:delete("k_30", ?B_TREE_04_33_MINUS_02_TILL_28)), - - ?assertEqual(?B_TREE_04_64_MINUS_08, b_trees:delete("k_08", ?B_TREE_04_64)), - ?assertEqual(?B_TREE_04_64_MINUS_16, b_trees:delete("k_16", ?B_TREE_04_64)), - ?assertEqual(?B_TREE_04_64_MINUS_32, b_trees:delete("k_32", ?B_TREE_04_64)), + test_generator:check_equal(?B_TREE_04_10_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_04_10))), + + test_generator:check_equal(?B_TREE_04_17_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_04_17))), + test_generator:check_equal(?B_TREE_04_17_MINUS_02_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_04_17_MINUS_02))), + test_generator:check_equal(?B_TREE_04_17_MINUS_02_TILL_12, b_trees:delete("k_12", test_generator:prepare_template(?B_TREE_04_17_MINUS_02_TILL_10))), + + test_generator:check_equal(?B_TREE_04_20_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_10, b_trees:delete("k_10", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_12, b_trees:delete("k_12", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_14, b_trees:delete("k_14", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_16, b_trees:delete("k_16", test_generator:prepare_template(?B_TREE_04_20))), + test_generator:check_equal(?B_TREE_04_20_MINUS_18, b_trees:delete("k_18", test_generator:prepare_template(?B_TREE_04_20))), + + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_18, b_trees:delete("k_18", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_16))), + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_20, b_trees:delete("k_20", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_18))), + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_22, b_trees:delete("k_22", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_20))), + test_generator:check_equal(?B_TREE_04_33_MINUS_02_TILL_30, b_trees:delete("k_30", test_generator:prepare_template(?B_TREE_04_33_MINUS_02_TILL_28))), + + test_generator:check_equal(?B_TREE_04_64_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_04_64))), + test_generator:check_equal(?B_TREE_04_64_MINUS_16, b_trees:delete("k_16", test_generator:prepare_template(?B_TREE_04_64))), + test_generator:check_equal(?B_TREE_04_64_MINUS_32, b_trees:delete("k_32", test_generator:prepare_template(?B_TREE_04_64))), ok. @@ -65,44 +65,44 @@ delete_b_tree_order_4_test() -> %%-------------------------------------------------------------------- delete_b_tree_order_6_test() -> - ?assertEqual(?B_TREE_06_00, b_trees:delete("k_01", ?B_TREE_06_01)), - - ?assertEqual(?B_TREE_06_06_MINUS_01, b_trees:delete("k_01", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_02, b_trees:delete("k_02", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_03, b_trees:delete("k_03", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_04, b_trees:delete("k_04", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_05, b_trees:delete("k_05", ?B_TREE_06_06)), - ?assertEqual(?B_TREE_06_06_MINUS_06, b_trees:delete("k_06", ?B_TREE_06_06)), - - ?assertEqual(?B_TREE_06_09_MINUS_01, b_trees:delete("k_01", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_02, b_trees:delete("k_02", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_03, b_trees:delete("k_03", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_04, b_trees:delete("k_04", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_05, b_trees:delete("k_05", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_06, b_trees:delete("k_06", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_07, b_trees:delete("k_07", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_08, b_trees:delete("k_08", ?B_TREE_06_09)), - ?assertEqual(?B_TREE_06_09_MINUS_09, b_trees:delete("k_09", ?B_TREE_06_09)), - - ?assertEqual(?B_TREE_06_10_MINUS_01, b_trees:delete("k_01", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_02, b_trees:delete("k_02", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_03, b_trees:delete("k_03", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_04, b_trees:delete("k_04", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_05, b_trees:delete("k_05", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_06, b_trees:delete("k_06", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_07, b_trees:delete("k_07", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_08, b_trees:delete("k_08", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_09, b_trees:delete("k_09", ?B_TREE_06_10)), - ?assertEqual(?B_TREE_06_10_MINUS_10, b_trees:delete("k_10", ?B_TREE_06_10)), - - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 1, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 5, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 8, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 11, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 14, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 17, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 20, 4)), - ?assertEqual(?B_TREE_06_00, test_generator:delete_b_tree_till(6, 100, 4)), + test_generator:check_equal(?B_TREE_06_00, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_01))), + + test_generator:check_equal(?B_TREE_06_06_MINUS_01, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_03, b_trees:delete("k_03", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_05, b_trees:delete("k_05", test_generator:prepare_template(?B_TREE_06_06))), + test_generator:check_equal(?B_TREE_06_06_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_06_06))), + + test_generator:check_equal(?B_TREE_06_09_MINUS_01, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_03, b_trees:delete("k_03", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_05, b_trees:delete("k_05", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_07, b_trees:delete("k_07", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_06_09))), + test_generator:check_equal(?B_TREE_06_09_MINUS_09, b_trees:delete("k_09", test_generator:prepare_template(?B_TREE_06_09))), + + test_generator:check_equal(?B_TREE_06_10_MINUS_01, b_trees:delete("k_01", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_02, b_trees:delete("k_02", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_03, b_trees:delete("k_03", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_04, b_trees:delete("k_04", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_05, b_trees:delete("k_05", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_06, b_trees:delete("k_06", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_07, b_trees:delete("k_07", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_08, b_trees:delete("k_08", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_09, b_trees:delete("k_09", test_generator:prepare_template(?B_TREE_06_10))), + test_generator:check_equal(?B_TREE_06_10_MINUS_10, b_trees:delete("k_10", test_generator:prepare_template(?B_TREE_06_10))), + + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 1, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 5, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 8, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 11, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 14, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 17, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_from(6, 20, 4)), + test_generator:check_equal(?B_TREE_06_00, test_generator:delete_b_tree_till(6, 100, 4)), ok. @@ -113,46 +113,46 @@ delete_b_tree_order_6_test() -> delete_clrs_test() -> % case 1 - _B_TREE_CLRS_500_MINUS_F = b_trees:delete("k_f", ?B_TREE_CLRS_500), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F, _B_TREE_CLRS_500_MINUS_F), + _B_TREE_CLRS_500_MINUS_F = b_trees:delete("k_f", test_generator:prepare_template(?B_TREE_CLRS_500)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F, _B_TREE_CLRS_500_MINUS_F), % case 2a - _B_TREE_CLRS_500_MINUS_F_M = b_trees:delete("k_m", ?B_TREE_CLRS_500_MINUS_F), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M, _B_TREE_CLRS_500_MINUS_F_M), + _B_TREE_CLRS_500_MINUS_F_M = b_trees:delete("k_m", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M, _B_TREE_CLRS_500_MINUS_F_M), % case 2b - _B_TREE_CLRS_500_MINUS_F_L = b_trees:delete("k_l", ?B_TREE_CLRS_500_MINUS_F_2), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_L, _B_TREE_CLRS_500_MINUS_F_L), + _B_TREE_CLRS_500_MINUS_F_L = b_trees:delete("k_l", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_2)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_L, _B_TREE_CLRS_500_MINUS_F_L), % case 2c - _B_TREE_CLRS_500_MINUS_F_M_G = b_trees:delete("k_g", ?B_TREE_CLRS_500_MINUS_F_M), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G, _B_TREE_CLRS_500_MINUS_F_M_G), + _B_TREE_CLRS_500_MINUS_F_M_G = b_trees:delete("k_g", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G, _B_TREE_CLRS_500_MINUS_F_M_G), % case 3a - delete left - _B_TREE_CLRS_500_MINUS_F_M_G_D_A = b_trees:delete("k_a", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_A, _B_TREE_CLRS_500_MINUS_F_M_G_D_A), - _B_TREE_CLRS_500_MINUS_F_M_G_D_B = b_trees:delete("k_b", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_B, _B_TREE_CLRS_500_MINUS_F_M_G_D_B), - _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E = b_trees:delete("k_e", ?B_TREE_CLRS_500_2_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_E, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E), - _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J = b_trees:delete("k_j", ?B_TREE_CLRS_500_2_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_J, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J), - _B_TREE_CLRS_500_MINUS_F_M_G_D_N = b_trees:delete("k_n", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_N, _B_TREE_CLRS_500_MINUS_F_M_G_D_N), - _B_TREE_CLRS_500_MINUS_F_M_G_D_O = b_trees:delete("k_o", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_O, _B_TREE_CLRS_500_MINUS_F_M_G_D_O), + _B_TREE_CLRS_500_MINUS_F_M_G_D_A = b_trees:delete("k_a", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_A, _B_TREE_CLRS_500_MINUS_F_M_G_D_A), + _B_TREE_CLRS_500_MINUS_F_M_G_D_B = b_trees:delete("k_b", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_B, _B_TREE_CLRS_500_MINUS_F_M_G_D_B), + _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E = b_trees:delete("k_e", test_generator:prepare_template(?B_TREE_CLRS_500_2_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_E, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_E), + _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J = b_trees:delete("k_j", test_generator:prepare_template(?B_TREE_CLRS_500_2_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_2_MINUS_F_M_G_D_J, _B_TREE_CLRS_500_2_MINUS_F_M_G_D_J), + _B_TREE_CLRS_500_MINUS_F_M_G_D_N = b_trees:delete("k_n", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_N, _B_TREE_CLRS_500_MINUS_F_M_G_D_N), + _B_TREE_CLRS_500_MINUS_F_M_G_D_O = b_trees:delete("k_o", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_O, _B_TREE_CLRS_500_MINUS_F_M_G_D_O), % case 3a delete right - _B_TREE_CLRS_500_MINUS_F_M_G_D_U = b_trees:delete("k_u", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_U, _B_TREE_CLRS_500_MINUS_F_M_G_D_U), - _B_TREE_CLRS_500_MINUS_F_M_G_D_V = b_trees:delete("k_v", ?B_TREE_CLRS_500_MINUS_F_M_G_D), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D_V, _B_TREE_CLRS_500_MINUS_F_M_G_D_V), + _B_TREE_CLRS_500_MINUS_F_M_G_D_U = b_trees:delete("k_u", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_U, _B_TREE_CLRS_500_MINUS_F_M_G_D_U), + _B_TREE_CLRS_500_MINUS_F_M_G_D_V = b_trees:delete("k_v", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G_D)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D_V, _B_TREE_CLRS_500_MINUS_F_M_G_D_V), % case 3b - _B_TREE_CLRS_500_MINUS_F_M_G_D = b_trees:delete("k_d", ?B_TREE_CLRS_500_MINUS_F_M_G), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_D, _B_TREE_CLRS_500_MINUS_F_M_G_D), - _B_TREE_CLRS_500_MINUS_F_M_G_U = b_trees:delete("k_u", ?B_TREE_CLRS_500_MINUS_F_M_G), - ?assertEqual(?B_TREE_CLRS_500_MINUS_F_M_G_U, _B_TREE_CLRS_500_MINUS_F_M_G_U), + _B_TREE_CLRS_500_MINUS_F_M_G_D = b_trees:delete("k_d", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_D, _B_TREE_CLRS_500_MINUS_F_M_G_D), + _B_TREE_CLRS_500_MINUS_F_M_G_U = b_trees:delete("k_u", test_generator:prepare_template(?B_TREE_CLRS_500_MINUS_F_M_G)), + test_generator:check_equal(?B_TREE_CLRS_500_MINUS_F_M_G_U, _B_TREE_CLRS_500_MINUS_F_M_G_U), ok. @@ -161,11 +161,11 @@ delete_clrs_test() -> %%-------------------------------------------------------------------- delete_error_test() -> - ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", ?B_TREE_06_00)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", test_generator:prepare_template(?B_TREE_06_00))), - ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", ?B_TREE_06_01)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:delete("k_00", test_generator:prepare_template(?B_TREE_06_01))), - ?assertException(error, {key_not_found, "k_10"}, b_trees:delete("k_10", ?B_TREE_06_09)), + ?assertException(error, {key_not_found, "k_10"}, b_trees:delete("k_10", test_generator:prepare_template(?B_TREE_06_09))), ok. @@ -174,15 +174,15 @@ delete_error_test() -> %%-------------------------------------------------------------------- empty_b_tree_test() -> - ?assertEqual(?B_TREE_04_00, b_trees:empty(4)), + test_generator:check_equal(?B_TREE_04_00, b_trees:empty(4)), ?assert(b_trees:is_empty(b_trees:empty(4))), ?assertEqual(0, b_trees:size(b_trees:empty(4))), - ?assertEqual(?B_TREE_06_00, b_trees:empty(6)), + test_generator:check_equal(?B_TREE_06_00, b_trees:empty(6)), ?assert(b_trees:is_empty(b_trees:empty(6))), ?assertEqual(0, b_trees:size(b_trees:empty(6))), - ?assertEqual(?B_TREE_32_00, b_trees:empty(32)), + test_generator:check_equal(?B_TREE_32_00, b_trees:empty(32)), ?assert(b_trees:is_empty(b_trees:empty(32))), ?assertEqual(0, b_trees:size(b_trees:empty(32))), @@ -193,7 +193,7 @@ empty_b_tree_test() -> %%-------------------------------------------------------------------- enter_b_tree_order_4_test() -> - BTree_04_15_01 = b_trees:enter("k_01", "v_01", ?B_TREE_04_00), + BTree_04_15_01 = b_trees:enter("k_01", "v_01", test_generator:prepare_template(?B_TREE_04_00)), BTree_04_15_02 = b_trees:enter("k_02", "v_02", BTree_04_15_01), BTree_04_15_03 = b_trees:enter("k_03", "v_03", BTree_04_15_02), BTree_04_15_04 = b_trees:enter("k_04", "v_04", BTree_04_15_03), @@ -208,7 +208,7 @@ enter_b_tree_order_4_test() -> BTree_04_15_13 = b_trees:enter("k_13", "v_13", BTree_04_15_12), BTree_04_15_14 = b_trees:enter("k_14", "v_14", BTree_04_15_13), BTree_04_15_15 = b_trees:enter("k_15", "v_15", BTree_04_15_14), - ?assertEqual(?B_TREE_04_15, BTree_04_15_15), + test_generator:check_equal(?B_TREE_04_15, BTree_04_15_15), BTree_04_15_01_NEW = b_trees:enter("k_01", "v_01_new", BTree_04_15_15), BTree_04_15_02_NEW = b_trees:enter("k_02", "v_02_new", BTree_04_15_01_NEW), @@ -224,7 +224,7 @@ enter_b_tree_order_4_test() -> BTree_04_15_12_NEW = b_trees:enter("k_12", "v_12_new", BTree_04_15_11_NEW), BTree_04_15_13_NEW = b_trees:enter("k_13", "v_13_new", BTree_04_15_12_NEW), BTree_04_15_14_NEW = b_trees:enter("k_14", "v_14_new", BTree_04_15_13_NEW), - ?assertEqual(?B_TREE_04_15_UPDATE, b_trees:enter("k_15", "v_15_new", BTree_04_15_14_NEW)), + test_generator:check_equal(?B_TREE_04_15_UPDATE, b_trees:enter("k_15", "v_15_new", BTree_04_15_14_NEW)), ok. @@ -233,10 +233,10 @@ enter_b_tree_order_4_test() -> %%-------------------------------------------------------------------- from_dict_b_tree_test() -> - ?assertEqual(?B_TREE_04_04, b_trees:from_dict(4, test_generator:generate_key_values_from(4, 2))), - ?assertEqual(?B_TREE_06_01, b_trees:from_dict(6, test_generator:generate_key_values_from(1, 2))), - ?assertEqual(?B_TREE_06_29, b_trees:from_dict(6, test_generator:generate_key_values_from(29, 2))), - ?assertEqual(?B_TREE_18_19, b_trees:from_dict(18, test_generator:generate_key_values_from(19, 2))), + test_generator:check_equal(?B_TREE_04_04, b_trees:from_dict(4, test_generator:generate_key_values_from(4, 2))), + test_generator:check_equal(?B_TREE_06_01, b_trees:from_dict(6, test_generator:generate_key_values_from(1, 2))), + test_generator:check_equal(?B_TREE_06_29, b_trees:from_dict(6, test_generator:generate_key_values_from(29, 2))), + test_generator:check_equal(?B_TREE_18_19, b_trees:from_dict(18, test_generator:generate_key_values_from(19, 2))), ok. @@ -245,94 +245,94 @@ from_dict_b_tree_test() -> %%-------------------------------------------------------------------- get_test() -> - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_04_00)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_04_04)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_04_04)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_04_04)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_04_04)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_04_04)), - ?assertException(error, {key_not_found, "k_05"}, b_trees:get("k_05", ?B_TREE_04_04)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_06_07)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_06_07)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_06_07)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_06_07)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_06_07)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_06_07)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_06_07)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_06_07)), - ?assertException(error, {key_not_found, "k_08"}, b_trees:get("k_08", ?B_TREE_06_07)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_10_10)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_10_10)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_10_10)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_10_10)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_10_10)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_10_10)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_10_10)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_10_10)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_10_10)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_10_10)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_10_10)), - ?assertException(error, {key_not_found, "k_11"}, b_trees:get("k_11", ?B_TREE_10_10)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_12_13)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_12_13)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_12_13)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_12_13)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_12_13)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_12_13)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_12_13)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_12_13)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_12_13)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_12_13)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_12_13)), - ?assertEqual("v_11", b_trees:get("k_11", ?B_TREE_12_13)), - ?assertEqual("v_12", b_trees:get("k_12", ?B_TREE_12_13)), - ?assertEqual("v_13", b_trees:get("k_13", ?B_TREE_12_13)), - ?assertException(error, {key_not_found, "k_14"}, b_trees:get("k_14", ?B_TREE_12_13)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_16_16)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_16_16)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_16_16)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_16_16)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_16_16)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_16_16)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_16_16)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_16_16)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_16_16)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_16_16)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_16_16)), - ?assertEqual("v_11", b_trees:get("k_11", ?B_TREE_16_16)), - ?assertEqual("v_12", b_trees:get("k_12", ?B_TREE_16_16)), - ?assertEqual("v_13", b_trees:get("k_13", ?B_TREE_16_16)), - ?assertEqual("v_14", b_trees:get("k_14", ?B_TREE_16_16)), - ?assertEqual("v_15", b_trees:get("k_15", ?B_TREE_16_16)), - ?assertEqual("v_16", b_trees:get("k_16", ?B_TREE_16_16)), - ?assertException(error, {key_not_found, "k_17"}, b_trees:get("k_17", ?B_TREE_16_16)), - - ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", ?B_TREE_18_19)), - ?assertEqual("v_01", b_trees:get("k_01", ?B_TREE_18_19)), - ?assertEqual("v_02", b_trees:get("k_02", ?B_TREE_18_19)), - ?assertEqual("v_03", b_trees:get("k_03", ?B_TREE_18_19)), - ?assertEqual("v_04", b_trees:get("k_04", ?B_TREE_18_19)), - ?assertEqual("v_05", b_trees:get("k_05", ?B_TREE_18_19)), - ?assertEqual("v_06", b_trees:get("k_06", ?B_TREE_18_19)), - ?assertEqual("v_07", b_trees:get("k_07", ?B_TREE_18_19)), - ?assertEqual("v_08", b_trees:get("k_08", ?B_TREE_18_19)), - ?assertEqual("v_09", b_trees:get("k_09", ?B_TREE_18_19)), - ?assertEqual("v_10", b_trees:get("k_10", ?B_TREE_18_19)), - ?assertEqual("v_11", b_trees:get("k_11", ?B_TREE_18_19)), - ?assertEqual("v_12", b_trees:get("k_12", ?B_TREE_18_19)), - ?assertEqual("v_13", b_trees:get("k_13", ?B_TREE_18_19)), - ?assertEqual("v_14", b_trees:get("k_14", ?B_TREE_18_19)), - ?assertEqual("v_15", b_trees:get("k_15", ?B_TREE_18_19)), - ?assertEqual("v_16", b_trees:get("k_16", ?B_TREE_18_19)), - ?assertEqual("v_17", b_trees:get("k_17", ?B_TREE_18_19)), - ?assertEqual("v_18", b_trees:get("k_18", ?B_TREE_18_19)), - ?assertEqual("v_19", b_trees:get("k_19", ?B_TREE_18_19)), - ?assertException(error, {key_not_found, "k_20"}, b_trees:get("k_20", ?B_TREE_18_19)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_04_00))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_04_04))), + ?assertException(error, {key_not_found, "k_05"}, b_trees:get("k_05", test_generator:prepare_template(?B_TREE_04_04))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_06_07))), + ?assertException(error, {key_not_found, "k_08"}, b_trees:get("k_08", test_generator:prepare_template(?B_TREE_06_07))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_10_10))), + ?assertException(error, {key_not_found, "k_11"}, b_trees:get("k_11", test_generator:prepare_template(?B_TREE_10_10))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_11", b_trees:get("k_11", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_12", b_trees:get("k_12", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual("v_13", b_trees:get("k_13", test_generator:prepare_template(?B_TREE_12_13))), + ?assertException(error, {key_not_found, "k_14"}, b_trees:get("k_14", test_generator:prepare_template(?B_TREE_12_13))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_11", b_trees:get("k_11", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_12", b_trees:get("k_12", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_13", b_trees:get("k_13", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_14", b_trees:get("k_14", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_15", b_trees:get("k_15", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual("v_16", b_trees:get("k_16", test_generator:prepare_template(?B_TREE_16_16))), + ?assertException(error, {key_not_found, "k_17"}, b_trees:get("k_17", test_generator:prepare_template(?B_TREE_16_16))), + + ?assertException(error, {key_not_found, "k_00"}, b_trees:get("k_00", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_01", b_trees:get("k_01", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_02", b_trees:get("k_02", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_03", b_trees:get("k_03", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_04", b_trees:get("k_04", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_05", b_trees:get("k_05", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_06", b_trees:get("k_06", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_07", b_trees:get("k_07", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_08", b_trees:get("k_08", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_09", b_trees:get("k_09", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_10", b_trees:get("k_10", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_11", b_trees:get("k_11", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_12", b_trees:get("k_12", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_13", b_trees:get("k_13", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_14", b_trees:get("k_14", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_15", b_trees:get("k_15", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_16", b_trees:get("k_16", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_17", b_trees:get("k_17", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_18", b_trees:get("k_18", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual("v_19", b_trees:get("k_19", test_generator:prepare_template(?B_TREE_18_19))), + ?assertException(error, {key_not_found, "k_20"}, b_trees:get("k_20", test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -341,11 +341,11 @@ get_test() -> %%-------------------------------------------------------------------- height_test() -> - ?assertException(error, {empty_tree, _}, b_trees:height(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:height(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual(0, b_trees:height(?B_TREE_06_02)), - ?assertEqual(1, b_trees:height(?B_TREE_06_06)), - ?assertEqual(2, b_trees:height(?B_TREE_06_21)), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_06))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_21))), ok. @@ -354,29 +354,29 @@ height_test() -> %%-------------------------------------------------------------------- insert_b_tree_order_4_test() -> - ?assertEqual(?B_TREE_04_00, b_trees:empty(4)), - - ?assertEqual(?B_TREE_04_01, test_generator:generate_b_tree_from_number(4, 1, 2)), - ?assertEqual(?B_TREE_04_02, test_generator:generate_b_tree_from_number(4, 2, 2)), - ?assertEqual(?B_TREE_04_03, test_generator:generate_b_tree_from_number(4, 3, 2)), - ?assertEqual(?B_TREE_04_04, test_generator:generate_b_tree_from_number(4, 4, 2)), - ?assertEqual(?B_TREE_04_05, test_generator:generate_b_tree_from_number(4, 5, 2)), - ?assertEqual(?B_TREE_04_06, test_generator:generate_b_tree_from_number(4, 6, 2)), - ?assertEqual(?B_TREE_04_07, test_generator:generate_b_tree_from_number(4, 7, 2)), - ?assertEqual(?B_TREE_04_08, test_generator:generate_b_tree_from_number(4, 8, 2)), - ?assertEqual(?B_TREE_04_09, test_generator:generate_b_tree_from_number(4, 9, 2)), - ?assertEqual(?B_TREE_04_10, test_generator:generate_b_tree_from_number(4, 10, 2)), - - ?assertEqual(?B_TREE_04_11, test_generator:generate_b_tree_from_number(4, 11, 2)), - ?assertEqual(?B_TREE_04_12, test_generator:generate_b_tree_from_number(4, 12, 2)), - ?assertEqual(?B_TREE_04_13, test_generator:generate_b_tree_from_number(4, 13, 2)), - ?assertEqual(?B_TREE_04_14, test_generator:generate_b_tree_from_number(4, 14, 2)), - ?assertEqual(?B_TREE_04_15, test_generator:generate_b_tree_from_number(4, 15, 2)), - ?assertEqual(?B_TREE_04_16, test_generator:generate_b_tree_from_number(4, 16, 2)), - ?assertEqual(?B_TREE_04_17, test_generator:generate_b_tree_from_number(4, 17, 2)), - ?assertEqual(?B_TREE_04_18, test_generator:generate_b_tree_from_number(4, 18, 2)), - ?assertEqual(?B_TREE_04_19, test_generator:generate_b_tree_from_number(4, 19, 2)), - ?assertEqual(?B_TREE_04_20, test_generator:generate_b_tree_from_number(4, 20, 2)), + test_generator:check_equal(?B_TREE_04_00, b_trees:empty(4)), + + test_generator:check_equal(?B_TREE_04_01, test_generator:generate_b_tree_from_number(4, 1, 2)), + test_generator:check_equal(?B_TREE_04_02, test_generator:generate_b_tree_from_number(4, 2, 2)), + test_generator:check_equal(?B_TREE_04_03, test_generator:generate_b_tree_from_number(4, 3, 2)), + test_generator:check_equal(?B_TREE_04_04, test_generator:generate_b_tree_from_number(4, 4, 2)), + test_generator:check_equal(?B_TREE_04_05, test_generator:generate_b_tree_from_number(4, 5, 2)), + test_generator:check_equal(?B_TREE_04_06, test_generator:generate_b_tree_from_number(4, 6, 2)), + test_generator:check_equal(?B_TREE_04_07, test_generator:generate_b_tree_from_number(4, 7, 2)), + test_generator:check_equal(?B_TREE_04_08, test_generator:generate_b_tree_from_number(4, 8, 2)), + test_generator:check_equal(?B_TREE_04_09, test_generator:generate_b_tree_from_number(4, 9, 2)), + test_generator:check_equal(?B_TREE_04_10, test_generator:generate_b_tree_from_number(4, 10, 2)), + + test_generator:check_equal(?B_TREE_04_11, test_generator:generate_b_tree_from_number(4, 11, 2)), + test_generator:check_equal(?B_TREE_04_12, test_generator:generate_b_tree_from_number(4, 12, 2)), + test_generator:check_equal(?B_TREE_04_13, test_generator:generate_b_tree_from_number(4, 13, 2)), + test_generator:check_equal(?B_TREE_04_14, test_generator:generate_b_tree_from_number(4, 14, 2)), + test_generator:check_equal(?B_TREE_04_15, test_generator:generate_b_tree_from_number(4, 15, 2)), + test_generator:check_equal(?B_TREE_04_16, test_generator:generate_b_tree_from_number(4, 16, 2)), + test_generator:check_equal(?B_TREE_04_17, test_generator:generate_b_tree_from_number(4, 17, 2)), + test_generator:check_equal(?B_TREE_04_18, test_generator:generate_b_tree_from_number(4, 18, 2)), + test_generator:check_equal(?B_TREE_04_19, test_generator:generate_b_tree_from_number(4, 19, 2)), + test_generator:check_equal(?B_TREE_04_20, test_generator:generate_b_tree_from_number(4, 20, 2)), ok. @@ -385,70 +385,70 @@ insert_b_tree_order_4_test() -> %%-------------------------------------------------------------------- insert_b_tree_order_6_test() -> - ?assertEqual(?B_TREE_06_00, b_trees:empty(6)), - ?assertEqual(0, b_trees:number_key_values(?B_TREE_06_00)), - ?assertException(error, {empty_tree, _}, b_trees:height(?B_TREE_06_00)), - ?assertEqual(0, b_trees:size(?B_TREE_06_00)), - - ?assertEqual(?B_TREE_06_01, b_trees:insert("k_01", "v_01", ?B_TREE_06_00)), - ?assertEqual(1, b_trees:number_key_values(?B_TREE_06_01)), - ?assertEqual(0, b_trees:height(?B_TREE_06_01)), - ?assertEqual(1, b_trees:size(?B_TREE_06_01)), - - ?assertEqual(?B_TREE_06_02, b_trees:insert("k_02", "v_02", test_generator:generate_b_tree_from_number(6, 1, 2))), - ?assertEqual(2, b_trees:number_key_values(?B_TREE_06_02)), - ?assertEqual(0, b_trees:height(?B_TREE_06_02)), - ?assertEqual(1, b_trees:size(?B_TREE_06_02)), - - ?assertEqual(?B_TREE_06_03, b_trees:insert("k_03", "v_03", test_generator:generate_b_tree_from_number(6, 2, 2))), - ?assertEqual(3, b_trees:number_key_values(?B_TREE_06_03)), - ?assertEqual(0, b_trees:height(?B_TREE_06_03)), - ?assertEqual(1, b_trees:size(?B_TREE_06_03)), - - ?assertEqual(?B_TREE_06_04, b_trees:insert("k_04", "v_04", test_generator:generate_b_tree_from_number(6, 3, 2))), - ?assertEqual(4, b_trees:number_key_values(?B_TREE_06_04)), - ?assertEqual(0, b_trees:height(?B_TREE_06_04)), - ?assertEqual(1, b_trees:size(?B_TREE_06_04)), - - ?assertEqual(?B_TREE_06_05, b_trees:insert("k_05", "v_05", test_generator:generate_b_tree_from_number(6, 4, 2))), - ?assertEqual(5, b_trees:number_key_values(?B_TREE_06_05)), - ?assertEqual(0, b_trees:height(?B_TREE_06_05)), - ?assertEqual(1, b_trees:size(?B_TREE_06_05)), - - ?assertEqual(?B_TREE_06_09, b_trees:insert("k_09", "v_09", test_generator:generate_b_tree_from_number(6, 8, 2))), - ?assertEqual(9, b_trees:number_key_values(?B_TREE_06_09)), - ?assertEqual(1, b_trees:height(?B_TREE_06_09)), - ?assertEqual(4, b_trees:size(?B_TREE_06_09)), - - ?assertEqual(?B_TREE_06_13, b_trees:insert("k_13", "v_13", test_generator:generate_b_tree_from_number(6, 12, 2))), - ?assertEqual(13, b_trees:number_key_values(?B_TREE_06_13)), - ?assertEqual(1, b_trees:height(?B_TREE_06_13)), - ?assertEqual(5, b_trees:size(?B_TREE_06_13)), - - ?assertEqual(?B_TREE_06_17, b_trees:insert("k_17", "v_17", test_generator:generate_b_tree_from_number(6, 16, 2))), - ?assertEqual(17, b_trees:number_key_values(?B_TREE_06_17)), - ?assertEqual(1, b_trees:height(?B_TREE_06_17)), - ?assertEqual(6, b_trees:size(?B_TREE_06_17)), - - ?assertEqual(?B_TREE_06_21, b_trees:insert("k_21", "v_21", test_generator:generate_b_tree_from_number(6, 20, 2))), - ?assertEqual(21, b_trees:number_key_values(?B_TREE_06_21)), - ?assertEqual(2, b_trees:height(?B_TREE_06_21)), - ?assertEqual(10, b_trees:size(?B_TREE_06_21)), - - ?assertEqual(?B_TREE_06_25, b_trees:insert("k_25", "v_25", test_generator:generate_b_tree_from_number(6, 24, 2))), - ?assertEqual(25, b_trees:number_key_values(?B_TREE_06_25)), - ?assertEqual(2, b_trees:height(?B_TREE_06_25)), - ?assertEqual(11, b_trees:size(?B_TREE_06_25)), - - ?assertEqual(?B_TREE_06_29, b_trees:insert("k_29", "v_29", test_generator:generate_b_tree_from_number(6, 28, 2))), - ?assertEqual(29, b_trees:number_key_values(?B_TREE_06_29)), - ?assertEqual(2, b_trees:height(?B_TREE_06_29)), - ?assertEqual(13, b_trees:size(?B_TREE_06_29)), - - ?assertEqual(?B_TREE_06_30, b_trees:insert("k_30", "v_30", test_generator:generate_b_tree_from_number(6, 29, 2))), - ?assertEqual(30, b_trees:number_key_values(?B_TREE_06_30)), - ?assertEqual(2, b_trees:height(?B_TREE_06_30)), - ?assertEqual(14, b_trees:size(?B_TREE_06_30)), + test_generator:check_equal(?B_TREE_06_00, b_trees:empty(6)), + ?assertEqual(0, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_00))), + ?assertException(error, {empty_tree, _}, b_trees:height(test_generator:prepare_template(?B_TREE_06_00))), + ?assertEqual(0, b_trees:size(test_generator:prepare_template(?B_TREE_06_00))), + + test_generator:check_equal(?B_TREE_06_01, b_trees:insert("k_01", "v_01", test_generator:prepare_template(?B_TREE_06_00))), + ?assertEqual(1, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_01))), + + test_generator:check_equal(?B_TREE_06_02, b_trees:insert("k_02", "v_02", test_generator:generate_b_tree_from_number(6, 1, 2))), + ?assertEqual(2, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_02))), + + test_generator:check_equal(?B_TREE_06_03, b_trees:insert("k_03", "v_03", test_generator:generate_b_tree_from_number(6, 2, 2))), + ?assertEqual(3, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_03))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_03))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_03))), + + test_generator:check_equal(?B_TREE_06_04, b_trees:insert("k_04", "v_04", test_generator:generate_b_tree_from_number(6, 3, 2))), + ?assertEqual(4, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_04))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_04))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_04))), + + test_generator:check_equal(?B_TREE_06_05, b_trees:insert("k_05", "v_05", test_generator:generate_b_tree_from_number(6, 4, 2))), + ?assertEqual(5, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual(0, b_trees:height(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_05))), + + test_generator:check_equal(?B_TREE_06_09, b_trees:insert("k_09", "v_09", test_generator:generate_b_tree_from_number(6, 8, 2))), + ?assertEqual(9, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual(4, b_trees:size(test_generator:prepare_template(?B_TREE_06_09))), + + test_generator:check_equal(?B_TREE_06_13, b_trees:insert("k_13", "v_13", test_generator:generate_b_tree_from_number(6, 12, 2))), + ?assertEqual(13, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_13))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_13))), + ?assertEqual(5, b_trees:size(test_generator:prepare_template(?B_TREE_06_13))), + + test_generator:check_equal(?B_TREE_06_17, b_trees:insert("k_17", "v_17", test_generator:generate_b_tree_from_number(6, 16, 2))), + ?assertEqual(17, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_17))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_17))), + ?assertEqual(6, b_trees:size(test_generator:prepare_template(?B_TREE_06_17))), + + test_generator:check_equal(?B_TREE_06_21, b_trees:insert("k_21", "v_21", test_generator:generate_b_tree_from_number(6, 20, 2))), + ?assertEqual(21, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_21))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_21))), + ?assertEqual(10, b_trees:size(test_generator:prepare_template(?B_TREE_06_21))), + + test_generator:check_equal(?B_TREE_06_25, b_trees:insert("k_25", "v_25", test_generator:generate_b_tree_from_number(6, 24, 2))), + ?assertEqual(25, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_25))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_25))), + ?assertEqual(11, b_trees:size(test_generator:prepare_template(?B_TREE_06_25))), + + test_generator:check_equal(?B_TREE_06_29, b_trees:insert("k_29", "v_29", test_generator:generate_b_tree_from_number(6, 28, 2))), + ?assertEqual(29, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_29))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_29))), + ?assertEqual(13, b_trees:size(test_generator:prepare_template(?B_TREE_06_29))), + + test_generator:check_equal(?B_TREE_06_30, b_trees:insert("k_30", "v_30", test_generator:generate_b_tree_from_number(6, 29, 2))), + ?assertEqual(30, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_30))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_06_30))), + ?assertEqual(14, b_trees:size(test_generator:prepare_template(?B_TREE_06_30))), ok. @@ -457,30 +457,30 @@ insert_b_tree_order_6_test() -> %%-------------------------------------------------------------------- insert_b_tree_order_8_test() -> - ?assertEqual(?B_TREE_08_00, b_trees:empty(8)), - ?assertEqual(0, b_trees:number_key_values(?B_TREE_08_00)), - ?assertException(error, {empty_tree, _}, b_trees:height(?B_TREE_08_00)), - ?assertEqual(0, b_trees:size(?B_TREE_08_00)), - - ?assertEqual(?B_TREE_06_07, b_trees:insert("k_07", "v_07", test_generator:generate_b_tree_from_number(6, 6, 2))), - ?assertEqual(7, b_trees:number_key_values(?B_TREE_06_07)), - ?assertEqual(1, b_trees:height(?B_TREE_06_07)), - ?assertEqual(3, b_trees:size(?B_TREE_06_07)), - - ?assertEqual(?B_TREE_08_16, b_trees:insert("k_16", "v_16", test_generator:generate_b_tree_from_number(8, 15, 2))), - ?assertEqual(16, b_trees:number_key_values(?B_TREE_08_16)), - ?assertEqual(1, b_trees:height(?B_TREE_08_16)), - ?assertEqual(5, b_trees:size(?B_TREE_08_16)), - - ?assertEqual(?B_TREE_08_32, b_trees:insert("k_32", "v_32", test_generator:generate_b_tree_from_number(8, 31, 2))), - ?assertEqual(32, b_trees:number_key_values(?B_TREE_08_32)), - ?assertEqual(1, b_trees:height(?B_TREE_08_32)), - ?assertEqual(9, b_trees:size(?B_TREE_08_32)), - - ?assertEqual(?B_TREE_08_64, b_trees:insert("k_64", "v_64", test_generator:generate_b_tree_from_number(8, 63, 2))), - ?assertEqual(64, b_trees:number_key_values(?B_TREE_08_64)), - ?assertEqual(2, b_trees:height(?B_TREE_08_64)), - ?assertEqual(20, b_trees:size(?B_TREE_08_64)), + test_generator:check_equal(?B_TREE_08_00, b_trees:empty(8)), + ?assertEqual(0, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_00))), + ?assertException(error, {empty_tree, _}, b_trees:height(test_generator:prepare_template(?B_TREE_08_00))), + ?assertEqual(0, b_trees:size(test_generator:prepare_template(?B_TREE_08_00))), + + test_generator:check_equal(?B_TREE_06_07, b_trees:insert("k_07", "v_07", test_generator:generate_b_tree_from_number(6, 6, 2))), + ?assertEqual(7, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual(3, b_trees:size(test_generator:prepare_template(?B_TREE_06_07))), + + test_generator:check_equal(?B_TREE_08_16, b_trees:insert("k_16", "v_16", test_generator:generate_b_tree_from_number(8, 15, 2))), + ?assertEqual(16, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_16))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_08_16))), + ?assertEqual(5, b_trees:size(test_generator:prepare_template(?B_TREE_08_16))), + + test_generator:check_equal(?B_TREE_08_32, b_trees:insert("k_32", "v_32", test_generator:generate_b_tree_from_number(8, 31, 2))), + ?assertEqual(32, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_32))), + ?assertEqual(1, b_trees:height(test_generator:prepare_template(?B_TREE_08_32))), + ?assertEqual(9, b_trees:size(test_generator:prepare_template(?B_TREE_08_32))), + + test_generator:check_equal(?B_TREE_08_64, b_trees:insert("k_64", "v_64", test_generator:generate_b_tree_from_number(8, 63, 2))), + ?assertEqual(64, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_08_64))), + ?assertEqual(2, b_trees:height(test_generator:prepare_template(?B_TREE_08_64))), + ?assertEqual(20, b_trees:size(test_generator:prepare_template(?B_TREE_08_64))), ok. @@ -490,17 +490,17 @@ insert_b_tree_order_8_test() -> %%-------------------------------------------------------------------- insert_clrs_test() -> - _B_TREE_CLRS_498_PLUS_B = b_trees:insert("k_b", "v_b", ?B_TREE_CLRS_498), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B, _B_TREE_CLRS_498_PLUS_B), + _B_TREE_CLRS_498_PLUS_B = b_trees:insert("k_b", "v_b", test_generator:prepare_template(?B_TREE_CLRS_498)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B, _B_TREE_CLRS_498_PLUS_B), - _B_TREE_CLRS_498_PLUS_B_Q = b_trees:insert("k_q", "v_q", ?B_TREE_CLRS_498_PLUS_B), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B_Q, _B_TREE_CLRS_498_PLUS_B_Q), + _B_TREE_CLRS_498_PLUS_B_Q = b_trees:insert("k_q", "v_q", test_generator:prepare_template(?B_TREE_CLRS_498_PLUS_B)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B_Q, _B_TREE_CLRS_498_PLUS_B_Q), - _B_TREE_CLRS_498_PLUS_B_Q_L = b_trees:insert("k_l", "v_l", ?B_TREE_CLRS_498_PLUS_B_Q), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B_Q_L, _B_TREE_CLRS_498_PLUS_B_Q_L), + _B_TREE_CLRS_498_PLUS_B_Q_L = b_trees:insert("k_l", "v_l", test_generator:prepare_template(?B_TREE_CLRS_498_PLUS_B_Q)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B_Q_L, _B_TREE_CLRS_498_PLUS_B_Q_L), - _B_TREE_CLRS_498_PLUS_B_Q_L_F = b_trees:insert("k_f", "v_f", ?B_TREE_CLRS_498_PLUS_B_Q_L), - ?assertEqual(?B_TREE_CLRS_498_PLUS_B_Q_L_F, _B_TREE_CLRS_498_PLUS_B_Q_L_F), + _B_TREE_CLRS_498_PLUS_B_Q_L_F = b_trees:insert("k_f", "v_f", test_generator:prepare_template(?B_TREE_CLRS_498_PLUS_B_Q_L)), + test_generator:check_equal(?B_TREE_CLRS_498_PLUS_B_Q_L_F, _B_TREE_CLRS_498_PLUS_B_Q_L_F), ok. @@ -522,94 +522,94 @@ insert_error_test() -> %%-------------------------------------------------------------------- is_defined_test() -> - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_04_00)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_04_04)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_04_04)), - ?assertNot(b_trees:is_defined("k_05", ?B_TREE_04_04)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_06_07)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_06_07)), - ?assertNot(b_trees:is_defined("k_08", ?B_TREE_06_07)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_10_10)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_10_10)), - ?assertNot(b_trees:is_defined("k_11", ?B_TREE_10_10)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_11", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_12", ?B_TREE_12_13)), - ?assert(b_trees:is_defined("k_13", ?B_TREE_12_13)), - ?assertNot(b_trees:is_defined("k_14", ?B_TREE_12_13)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_11", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_12", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_13", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_14", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_15", ?B_TREE_16_16)), - ?assert(b_trees:is_defined("k_16", ?B_TREE_16_16)), - ?assertNot(b_trees:is_defined("k_17", ?B_TREE_16_16)), - - ?assertNot(b_trees:is_defined("k_00", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_01", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_02", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_03", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_04", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_05", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_06", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_07", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_08", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_09", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_10", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_11", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_12", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_13", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_14", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_15", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_16", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_17", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_18", ?B_TREE_18_19)), - ?assert(b_trees:is_defined("k_19", ?B_TREE_18_19)), - ?assertNot(b_trees:is_defined("k_20", ?B_TREE_18_19)), + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_04_00))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_04_04))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_04_04))), + ?assertNot(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_04_04))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_06_07))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_06_07))), + ?assertNot(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_06_07))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_10_10))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_10_10))), + ?assertNot(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_10_10))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_12", test_generator:prepare_template(?B_TREE_12_13))), + ?assert(b_trees:is_defined("k_13", test_generator:prepare_template(?B_TREE_12_13))), + ?assertNot(b_trees:is_defined("k_14", test_generator:prepare_template(?B_TREE_12_13))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_12", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_13", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_14", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_15", test_generator:prepare_template(?B_TREE_16_16))), + ?assert(b_trees:is_defined("k_16", test_generator:prepare_template(?B_TREE_16_16))), + ?assertNot(b_trees:is_defined("k_17", test_generator:prepare_template(?B_TREE_16_16))), + + ?assertNot(b_trees:is_defined("k_00", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_01", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_02", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_03", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_04", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_05", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_06", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_07", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_08", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_09", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_10", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_11", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_12", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_13", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_14", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_15", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_16", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_17", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_18", test_generator:prepare_template(?B_TREE_18_19))), + ?assert(b_trees:is_defined("k_19", test_generator:prepare_template(?B_TREE_18_19))), + ?assertNot(b_trees:is_defined("k_20", test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -618,8 +618,8 @@ is_defined_test() -> %%-------------------------------------------------------------------- is_empty_test() -> - ?assertEqual(false, b_trees:is_empty(?B_TREE_32_01)), - ?assertEqual(true, b_trees:is_empty(?B_TREE_32_00)), + ?assertEqual(false, b_trees:is_empty(test_generator:prepare_template(?B_TREE_32_01))), + ?assertEqual(true, b_trees:is_empty(test_generator:prepare_template(?B_TREE_32_00))), ok. @@ -713,22 +713,22 @@ iterator_from_next_04_16_test() -> BTree = test_generator:generate_b_tree_from_number(4, Number, 2), KeyValues = test_generator:generate_key_values_from(Number, 2), - ?assertEqual(lists:sublist(KeyValues, 1, Number), iterate_next_b_tree(b_trees:iterator_from("k_00", BTree), Number - 0, [])), - ?assertEqual(lists:sublist(KeyValues, 2, Number), iterate_next_b_tree(b_trees:iterator_from("k_02", BTree), Number - 1, [])), - ?assertEqual(lists:sublist(KeyValues, 3, Number), iterate_next_b_tree(b_trees:iterator_from("k_03", BTree), Number - 2, [])), - ?assertEqual(lists:sublist(KeyValues, 4, Number), iterate_next_b_tree(b_trees:iterator_from("k_04", BTree), Number - 3, [])), - ?assertEqual(lists:sublist(KeyValues, 5, Number), iterate_next_b_tree(b_trees:iterator_from("k_05", BTree), Number - 4, [])), - ?assertEqual(lists:sublist(KeyValues, 6, Number), iterate_next_b_tree(b_trees:iterator_from("k_06", BTree), Number - 5, [])), - ?assertEqual(lists:sublist(KeyValues, 7, Number), iterate_next_b_tree(b_trees:iterator_from("k_07", BTree), Number - 6, [])), - ?assertEqual(lists:sublist(KeyValues, 8, Number), iterate_next_b_tree(b_trees:iterator_from("k_08", BTree), Number - 7, [])), - ?assertEqual(lists:sublist(KeyValues, 9, Number), iterate_next_b_tree(b_trees:iterator_from("k_09", BTree), Number - 8, [])), - ?assertEqual(lists:sublist(KeyValues, 10, Number), iterate_next_b_tree(b_trees:iterator_from("k_10", BTree), Number - 9, [])), - ?assertEqual(lists:sublist(KeyValues, 11, Number), iterate_next_b_tree(b_trees:iterator_from("k_11", BTree), Number - 10, [])), - ?assertEqual(lists:sublist(KeyValues, 12, Number), iterate_next_b_tree(b_trees:iterator_from("k_12", BTree), Number - 11, [])), - ?assertEqual(lists:sublist(KeyValues, 13, Number), iterate_next_b_tree(b_trees:iterator_from("k_13", BTree), Number - 12, [])), - ?assertEqual(lists:sublist(KeyValues, 14, Number), iterate_next_b_tree(b_trees:iterator_from("k_14", BTree), Number - 13, [])), - ?assertEqual(lists:sublist(KeyValues, 15, Number), iterate_next_b_tree(b_trees:iterator_from("k_15", BTree), Number - 14, [])), - ?assertEqual(lists:sublist(KeyValues, 16, Number), iterate_next_b_tree(b_trees:iterator_from("k_16", BTree), Number - 15, [])), + ?assertEqual(lists:sublist(KeyValues, 1, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_00", BTree), Number - 0, [])), + ?assertEqual(lists:sublist(KeyValues, 2, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_02", BTree), Number - 1, [])), + ?assertEqual(lists:sublist(KeyValues, 3, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_03", BTree), Number - 2, [])), + ?assertEqual(lists:sublist(KeyValues, 4, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_04", BTree), Number - 3, [])), + ?assertEqual(lists:sublist(KeyValues, 5, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_05", BTree), Number - 4, [])), + ?assertEqual(lists:sublist(KeyValues, 6, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_06", BTree), Number - 5, [])), + ?assertEqual(lists:sublist(KeyValues, 7, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_07", BTree), Number - 6, [])), + ?assertEqual(lists:sublist(KeyValues, 8, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_08", BTree), Number - 7, [])), + ?assertEqual(lists:sublist(KeyValues, 9, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_09", BTree), Number - 8, [])), + ?assertEqual(lists:sublist(KeyValues, 10, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_10", BTree), Number - 9, [])), + ?assertEqual(lists:sublist(KeyValues, 11, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_11", BTree), Number - 10, [])), + ?assertEqual(lists:sublist(KeyValues, 12, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_12", BTree), Number - 11, [])), + ?assertEqual(lists:sublist(KeyValues, 13, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_13", BTree), Number - 12, [])), + ?assertEqual(lists:sublist(KeyValues, 14, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_14", BTree), Number - 13, [])), + ?assertEqual(lists:sublist(KeyValues, 15, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_15", BTree), Number - 14, [])), + ?assertEqual(lists:sublist(KeyValues, 16, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_16", BTree), Number - 15, [])), ok. @@ -756,30 +756,30 @@ iterator_from_next_08_256_test() -> BTree = test_generator:generate_b_tree_from_number(4, Number, 3), KeyValues = test_generator:generate_key_values_from(Number, 3), - ?assertEqual(lists:sublist(KeyValues, 1, Number), iterate_next_b_tree(b_trees:iterator_from("k_000", BTree), Number - 0, [])), - ?assertEqual(lists:sublist(KeyValues, 2, Number), iterate_next_b_tree(b_trees:iterator_from("k_002", BTree), Number - 1, [])), - ?assertEqual(lists:sublist(KeyValues, 3, Number), iterate_next_b_tree(b_trees:iterator_from("k_003", BTree), Number - 2, [])), - ?assertEqual(lists:sublist(KeyValues, 4, Number), iterate_next_b_tree(b_trees:iterator_from("k_004", BTree), Number - 3, [])), - ?assertEqual(lists:sublist(KeyValues, 5, Number), iterate_next_b_tree(b_trees:iterator_from("k_005", BTree), Number - 4, [])), - ?assertEqual(lists:sublist(KeyValues, 7, Number), iterate_next_b_tree(b_trees:iterator_from("k_007", BTree), Number - 6, [])), - ?assertEqual(lists:sublist(KeyValues, 8, Number), iterate_next_b_tree(b_trees:iterator_from("k_008", BTree), Number - 7, [])), - ?assertEqual(lists:sublist(KeyValues, 11, Number), iterate_next_b_tree(b_trees:iterator_from("k_011", BTree), Number - 10, [])), - ?assertEqual(lists:sublist(KeyValues, 13, Number), iterate_next_b_tree(b_trees:iterator_from("k_013", BTree), Number - 12, [])), - ?assertEqual(lists:sublist(KeyValues, 16, Number), iterate_next_b_tree(b_trees:iterator_from("k_016", BTree), Number - 15, [])), - ?assertEqual(lists:sublist(KeyValues, 17, Number), iterate_next_b_tree(b_trees:iterator_from("k_017", BTree), Number - 16, [])), - ?assertEqual(lists:sublist(KeyValues, 19, Number), iterate_next_b_tree(b_trees:iterator_from("k_019", BTree), Number - 18, [])), - ?assertEqual(lists:sublist(KeyValues, 23, Number), iterate_next_b_tree(b_trees:iterator_from("k_023", BTree), Number - 22, [])), - ?assertEqual(lists:sublist(KeyValues, 29, Number), iterate_next_b_tree(b_trees:iterator_from("k_029", BTree), Number - 28, [])), - ?assertEqual(lists:sublist(KeyValues, 31, Number), iterate_next_b_tree(b_trees:iterator_from("k_031", BTree), Number - 30, [])), - ?assertEqual(lists:sublist(KeyValues, 32, Number), iterate_next_b_tree(b_trees:iterator_from("k_032", BTree), Number - 31, [])), - ?assertEqual(lists:sublist(KeyValues, 37, Number), iterate_next_b_tree(b_trees:iterator_from("k_037", BTree), Number - 36, [])), - ?assertEqual(lists:sublist(KeyValues, 41, Number), iterate_next_b_tree(b_trees:iterator_from("k_041", BTree), Number - 40, [])), - ?assertEqual(lists:sublist(KeyValues, 43, Number), iterate_next_b_tree(b_trees:iterator_from("k_043", BTree), Number - 42, [])), - ?assertEqual(lists:sublist(KeyValues, 47, Number), iterate_next_b_tree(b_trees:iterator_from("k_047", BTree), Number - 46, [])), - ?assertEqual(lists:sublist(KeyValues, 49, Number), iterate_next_b_tree(b_trees:iterator_from("k_049", BTree), Number - 48, [])), - ?assertEqual(lists:sublist(KeyValues, 64, Number), iterate_next_b_tree(b_trees:iterator_from("k_064", BTree), Number - 63, [])), - ?assertEqual(lists:sublist(KeyValues, 128, Number), iterate_next_b_tree(b_trees:iterator_from("k_128", BTree), Number - 127, [])), - ?assertEqual(lists:sublist(KeyValues, 256, Number), iterate_next_b_tree(b_trees:iterator_from("k_256", BTree), Number - 255, [])), + ?assertEqual(lists:sublist(KeyValues, 1, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_000", BTree), Number - 0, [])), + ?assertEqual(lists:sublist(KeyValues, 2, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_002", BTree), Number - 1, [])), + ?assertEqual(lists:sublist(KeyValues, 3, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_003", BTree), Number - 2, [])), + ?assertEqual(lists:sublist(KeyValues, 4, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_004", BTree), Number - 3, [])), + ?assertEqual(lists:sublist(KeyValues, 5, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_005", BTree), Number - 4, [])), + ?assertEqual(lists:sublist(KeyValues, 7, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_007", BTree), Number - 6, [])), + ?assertEqual(lists:sublist(KeyValues, 8, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_008", BTree), Number - 7, [])), + ?assertEqual(lists:sublist(KeyValues, 11, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_011", BTree), Number - 10, [])), + ?assertEqual(lists:sublist(KeyValues, 13, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_013", BTree), Number - 12, [])), + ?assertEqual(lists:sublist(KeyValues, 16, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_016", BTree), Number - 15, [])), + ?assertEqual(lists:sublist(KeyValues, 17, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_017", BTree), Number - 16, [])), + ?assertEqual(lists:sublist(KeyValues, 19, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_019", BTree), Number - 18, [])), + ?assertEqual(lists:sublist(KeyValues, 23, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_023", BTree), Number - 22, [])), + ?assertEqual(lists:sublist(KeyValues, 29, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_029", BTree), Number - 28, [])), + ?assertEqual(lists:sublist(KeyValues, 31, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_031", BTree), Number - 30, [])), + ?assertEqual(lists:sublist(KeyValues, 32, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_032", BTree), Number - 31, [])), + ?assertEqual(lists:sublist(KeyValues, 37, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_037", BTree), Number - 36, [])), + ?assertEqual(lists:sublist(KeyValues, 41, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_041", BTree), Number - 40, [])), + ?assertEqual(lists:sublist(KeyValues, 43, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_043", BTree), Number - 42, [])), + ?assertEqual(lists:sublist(KeyValues, 47, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_047", BTree), Number - 46, [])), + ?assertEqual(lists:sublist(KeyValues, 49, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_049", BTree), Number - 48, [])), + ?assertEqual(lists:sublist(KeyValues, 64, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_064", BTree), Number - 63, [])), + ?assertEqual(lists:sublist(KeyValues, 128, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_128", BTree), Number - 127, [])), + ?assertEqual(lists:sublist(KeyValues, 256, Number), test_generator:iterate_next_b_tree(b_trees:iterator_from("k_256", BTree), Number - 255, [])), ok. @@ -893,23 +893,23 @@ iterator_next_test() -> %%-------------------------------------------------------------------- keys_test() -> - ?assertEqual([], b_trees:keys(?B_TREE_06_00)), + ?assertEqual([], b_trees:keys(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual(["k_01"], b_trees:keys(?B_TREE_06_01)), + ?assertEqual(["k_01"], b_trees:keys(test_generator:prepare_template(?B_TREE_06_01))), - _Keys_06_02 = b_trees:keys(?B_TREE_06_02), + _Keys_06_02 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_02)), ?assertEqual(test_generator:generate_keys_from(2, 2), _Keys_06_02), ?assertEqual(2, length(_Keys_06_02)), - _Keys_06_05 = b_trees:keys(?B_TREE_06_05), + _Keys_06_05 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_05)), ?assertEqual(test_generator:generate_keys_from(5, 2), _Keys_06_05), ?assertEqual(5, length(_Keys_06_05)), - _Keys_06_09 = b_trees:keys(?B_TREE_06_09), + _Keys_06_09 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_09)), ?assertEqual(test_generator:generate_keys_from(9, 2), _Keys_06_09), ?assertEqual(9, length(_Keys_06_09)), - _Keys_06_16 = b_trees:keys(?B_TREE_06_16), + _Keys_06_16 = b_trees:keys(test_generator:prepare_template(?B_TREE_06_16)), ?assertEqual(test_generator:generate_keys_from(16, 2), _Keys_06_16), ?assertEqual(16, length(_Keys_06_16)), @@ -920,15 +920,15 @@ keys_test() -> %%-------------------------------------------------------------------- largest_test() -> - ?assertException(error, {empty_tree, _}, b_trees:largest(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual({"k_01", "v_01"}, b_trees:largest(?B_TREE_06_01)), - ?assertEqual({"k_02", "v_02"}, b_trees:largest(?B_TREE_06_02)), - ?assertEqual({"k_05", "v_05"}, b_trees:largest(?B_TREE_06_05)), - ?assertEqual({"k_09", "v_09"}, b_trees:largest(?B_TREE_06_09)), - ?assertEqual({"k_16", "v_16"}, b_trees:largest(?B_TREE_06_16)), + ?assertEqual({"k_01", "v_01"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual({"k_02", "v_02"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual({"k_05", "v_05"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual({"k_09", "v_09"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual({"k_16", "v_16"}, b_trees:largest(test_generator:prepare_template(?B_TREE_06_16))), - ?assertEqual({"k_19", "v_19"}, b_trees:largest(?B_TREE_18_19)), + ?assertEqual({"k_19", "v_19"}, b_trees:largest(test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -937,94 +937,94 @@ largest_test() -> %%-------------------------------------------------------------------- lookup_test() -> - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_04_00)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_04_04)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_04_04)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_04_04)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_04_04)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_04_04)), - ?assertEqual(none, b_trees:lookup("k_05", ?B_TREE_04_04)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_06_07)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_06_07)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_06_07)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_06_07)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_06_07)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_06_07)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_06_07)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_06_07)), - ?assertEqual(none, b_trees:lookup("k_08", ?B_TREE_06_07)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_10_10)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_10_10)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_10_10)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_10_10)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_10_10)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_10_10)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_10_10)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_10_10)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_10_10)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_10_10)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_10_10)), - ?assertEqual(none, b_trees:lookup("k_11", ?B_TREE_10_10)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_12_13)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_12_13)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_12_13)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_12_13)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_12_13)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_12_13)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_12_13)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_12_13)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_12_13)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_12_13)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_12_13)), - ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", ?B_TREE_12_13)), - ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", ?B_TREE_12_13)), - ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", ?B_TREE_12_13)), - ?assertEqual(none, b_trees:lookup("k_14", ?B_TREE_12_13)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_16_16)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_16_16)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_16_16)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_16_16)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_16_16)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_16_16)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_16_16)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_16_16)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_16_16)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_16_16)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_16_16)), - ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", ?B_TREE_16_16)), - ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", ?B_TREE_16_16)), - ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", ?B_TREE_16_16)), - ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", ?B_TREE_16_16)), - ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", ?B_TREE_16_16)), - ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", ?B_TREE_16_16)), - ?assertEqual(none, b_trees:lookup("k_17", ?B_TREE_16_16)), - - ?assertEqual(none, b_trees:lookup("k_00", ?B_TREE_18_19)), - ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", ?B_TREE_18_19)), - ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", ?B_TREE_18_19)), - ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", ?B_TREE_18_19)), - ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", ?B_TREE_18_19)), - ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", ?B_TREE_18_19)), - ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", ?B_TREE_18_19)), - ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", ?B_TREE_18_19)), - ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", ?B_TREE_18_19)), - ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", ?B_TREE_18_19)), - ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", ?B_TREE_18_19)), - ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", ?B_TREE_18_19)), - ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", ?B_TREE_18_19)), - ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", ?B_TREE_18_19)), - ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", ?B_TREE_18_19)), - ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", ?B_TREE_18_19)), - ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", ?B_TREE_18_19)), - ?assertEqual({value, "v_17"}, b_trees:lookup("k_17", ?B_TREE_18_19)), - ?assertEqual({value, "v_18"}, b_trees:lookup("k_18", ?B_TREE_18_19)), - ?assertEqual({value, "v_19"}, b_trees:lookup("k_19", ?B_TREE_18_19)), - ?assertEqual(none, b_trees:lookup("k_20", ?B_TREE_18_19)), + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_04_00))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_04_04))), + ?assertEqual(none, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_04_04))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_06_07))), + ?assertEqual(none, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_06_07))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_10_10))), + ?assertEqual(none, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_10_10))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", test_generator:prepare_template(?B_TREE_12_13))), + ?assertEqual(none, b_trees:lookup("k_14", test_generator:prepare_template(?B_TREE_12_13))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", test_generator:prepare_template(?B_TREE_16_16))), + ?assertEqual(none, b_trees:lookup("k_17", test_generator:prepare_template(?B_TREE_16_16))), + + ?assertEqual(none, b_trees:lookup("k_00", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_01"}, b_trees:lookup("k_01", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_02"}, b_trees:lookup("k_02", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_03"}, b_trees:lookup("k_03", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_04"}, b_trees:lookup("k_04", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_05"}, b_trees:lookup("k_05", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_06"}, b_trees:lookup("k_06", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_07"}, b_trees:lookup("k_07", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_08"}, b_trees:lookup("k_08", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_09"}, b_trees:lookup("k_09", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_10"}, b_trees:lookup("k_10", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_11"}, b_trees:lookup("k_11", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_12"}, b_trees:lookup("k_12", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_13"}, b_trees:lookup("k_13", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_14"}, b_trees:lookup("k_14", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_15"}, b_trees:lookup("k_15", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_16"}, b_trees:lookup("k_16", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_17"}, b_trees:lookup("k_17", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_18"}, b_trees:lookup("k_18", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual({value, "v_19"}, b_trees:lookup("k_19", test_generator:prepare_template(?B_TREE_18_19))), + ?assertEqual(none, b_trees:lookup("k_20", test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1033,19 +1033,16 @@ lookup_test() -> %%-------------------------------------------------------------------- map_b_tree_order_4_test() -> - ?assertEqual(?B_TREE_04_15_UPDATE, b_trees:map(fun map_value_to_new/2, ?B_TREE_04_15)), + test_generator:check_equal(?B_TREE_04_15_UPDATE, b_trees:map(fun test_generator:map_value_to_new/2, test_generator:prepare_template(?B_TREE_04_15))), ok. -map_value_to_new(_, Value) -> - Value ++ "_new". - %%-------------------------------------------------------------------- %% TEST CASES: map - error %%-------------------------------------------------------------------- map_error_test() -> - ?assertException(error, {empty_tree, ?B_TREE_06_00}, b_trees:map(fun map_value_to_new/2, ?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:map(fun test_generator:map_value_to_new/2, test_generator:prepare_template(?B_TREE_06_00))), ok. @@ -1054,12 +1051,13 @@ map_error_test() -> %%-------------------------------------------------------------------- number_key_values_test() -> - ?assertEqual(0, b_trees:number_key_values(?B_TREE_06_00)), - ?assertEqual(2, b_trees:number_key_values(?B_TREE_06_02)), - ?assertEqual(5, b_trees:number_key_values(?B_TREE_06_05)), - ?assertEqual(16, b_trees:number_key_values(?B_TREE_06_16)), - ?assertEqual(29, b_trees:number_key_values(?B_TREE_06_29)), - ?assertEqual(19, b_trees:number_key_values(?B_TREE_18_19)), + ?assertEqual(0, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_00))), + ?assertEqual(2, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual(5, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual(16, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_16))), + ?assertEqual(29, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_06_29))), + + ?assertEqual(19, b_trees:number_key_values(test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1070,11 +1068,11 @@ number_key_values_test() -> size_test() -> ?assertEqual(0, b_trees:size(b_trees:empty(6))), - ?assertEqual(1, b_trees:size(?B_TREE_06_03)), - ?assertEqual(3, b_trees:size(?B_TREE_06_08)), - ?assertEqual(5, b_trees:size(?B_TREE_06_13)), - ?assertEqual(7, b_trees:size(?B_TREE_06_20)), - ?assertEqual(10, b_trees:size(?B_TREE_06_21)), + ?assertEqual(1, b_trees:size(test_generator:prepare_template(?B_TREE_06_03))), + ?assertEqual(3, b_trees:size(test_generator:prepare_template(?B_TREE_06_08))), + ?assertEqual(5, b_trees:size(test_generator:prepare_template(?B_TREE_06_13))), + ?assertEqual(7, b_trees:size(test_generator:prepare_template(?B_TREE_06_20))), + ?assertEqual(10, b_trees:size(test_generator:prepare_template(?B_TREE_06_21))), ok. @@ -1083,14 +1081,14 @@ size_test() -> %%-------------------------------------------------------------------- smallest_test() -> - ?assertException(error, {empty_tree, _}, b_trees:smallest(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_01)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_02)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_05)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_09)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_06_16)), - ?assertEqual({"k_01", "v_01"}, b_trees:smallest(?B_TREE_18_19)), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_01))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_02))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_05))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_09))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_06_16))), + ?assertEqual({"k_01", "v_01"}, b_trees:smallest(test_generator:prepare_template(?B_TREE_18_19))), ok. @@ -1101,27 +1099,27 @@ smallest_test() -> take_largest_test() -> ?assertException(error, {empty_tree, _}, b_trees:take_largest(?B_TREE_06_00)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 3, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 6, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 9, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 12, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 15, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 18, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 21, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 24, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 27, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 30, 2)), - - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 4, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 8, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 12, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 16, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 20, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 24, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 28, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 32, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 36, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 40, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 3, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 6, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 9, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 12, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 15, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 18, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 21, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 24, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 27, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_largest_b_tree(4, 30, 2)), + + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 4, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 8, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 12, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 16, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 20, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 24, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 28, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 32, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 36, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_largest_b_tree(6, 40, 2)), ok. @@ -1132,27 +1130,27 @@ take_largest_test() -> take_smallest_test() -> ?assertException(error, {empty_tree, _}, b_trees:take_smallest(?B_TREE_06_00)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 3, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 6, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 9, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 12, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 15, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 18, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 21, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 24, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 27, 2)), - ?assertEqual(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 30, 2)), - - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 4, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 8, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 12, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 16, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 20, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 24, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 28, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 32, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 36, 2)), - ?assertEqual(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 40, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 3, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 6, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 9, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 12, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 15, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 18, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 21, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 24, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 27, 2)), + test_generator:check_equal(?B_TREE_04_00, test_generator:take_smallest_b_tree(4, 30, 2)), + + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 4, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 8, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 12, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 16, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 20, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 24, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 28, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 32, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 36, 2)), + test_generator:check_equal(?B_TREE_06_00, test_generator:take_smallest_b_tree(6, 40, 2)), ok. @@ -1161,23 +1159,23 @@ take_smallest_test() -> %%-------------------------------------------------------------------- to_list_test() -> - ?assertException(error, {empty_tree, _}, b_trees:to_list(?B_TREE_06_00)), + ?assertException(error, {empty_tree, _}, b_trees:to_list(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual([{"k_01", "v_01"}], b_trees:to_list(?B_TREE_06_01)), + ?assertEqual([{"k_01", "v_01"}], b_trees:to_list(test_generator:prepare_template(?B_TREE_06_01))), - _KeyValues_06_02 = b_trees:to_list(?B_TREE_06_02), + _KeyValues_06_02 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_02)), ?assertEqual(test_generator:generate_key_values_from(2, 2), _KeyValues_06_02), ?assertEqual(2, length(_KeyValues_06_02)), - _KeyValues_06_05 = b_trees:to_list(?B_TREE_06_05), + _KeyValues_06_05 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_05)), ?assertEqual(test_generator:generate_key_values_from(5, 2), _KeyValues_06_05), ?assertEqual(5, length(_KeyValues_06_05)), - _KeyValues_06_09 = b_trees:to_list(?B_TREE_06_09), + _KeyValues_06_09 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_09)), ?assertEqual(test_generator:generate_key_values_from(9, 2), _KeyValues_06_09), ?assertEqual(9, length(_KeyValues_06_09)), - _KeyValues_06_16 = b_trees:to_list(?B_TREE_06_16), + _KeyValues_06_16 = b_trees:to_list(test_generator:prepare_template(?B_TREE_06_16)), ?assertEqual(test_generator:generate_key_values_from(16, 2), _KeyValues_06_16), ?assertEqual(16, length(_KeyValues_06_16)), @@ -1188,7 +1186,7 @@ to_list_test() -> %%-------------------------------------------------------------------- update_b_tree_order_4_test() -> - BTree_04_15_K_01 = b_trees:update("k_01", "v_01_new", ?B_TREE_04_15), + BTree_04_15_K_01 = b_trees:update("k_01", "v_01_new", test_generator:prepare_template(?B_TREE_04_15)), BTree_04_15_K_02 = b_trees:update("k_02", "v_02_new", BTree_04_15_K_01), BTree_04_15_K_03 = b_trees:update("k_03", "v_03_new", BTree_04_15_K_02), BTree_04_15_K_04 = b_trees:update("k_04", "v_04_new", BTree_04_15_K_03), @@ -1202,7 +1200,7 @@ update_b_tree_order_4_test() -> BTree_04_15_K_12 = b_trees:update("k_12", "v_12_new", BTree_04_15_K_11), BTree_04_15_K_13 = b_trees:update("k_13", "v_13_new", BTree_04_15_K_12), _BTree_04_15_K_14 = b_trees:update("k_14", "v_14_new", BTree_04_15_K_13), - ?assertEqual(?B_TREE_04_15_UPDATE, b_trees:update("k_15", "v_15_new", _BTree_04_15_K_14)), + test_generator:check_equal(?B_TREE_04_15_UPDATE, b_trees:update("k_15", "v_15_new", _BTree_04_15_K_14)), ok. @@ -1211,12 +1209,12 @@ update_b_tree_order_4_test() -> %%-------------------------------------------------------------------- update_error_test() -> - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_06_00)), - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_06_02)), - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_06_29)), - ?assertException(error, {key_not_found, "k_30"}, b_trees:update("k_30", "v_30_new", ?B_TREE_06_29)), - ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", ?B_TREE_08_64)), - ?assertException(error, {key_not_found, "k_65"}, b_trees:update("k_65", "v_65_new", ?B_TREE_08_64)), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_06_00))), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_06_02))), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_06_29))), + ?assertException(error, {key_not_found, "k_30"}, b_trees:update("k_30", "v_30_new", test_generator:prepare_template(?B_TREE_06_29))), + ?assertException(error, {key_not_found, "k_00"}, b_trees:update("k_00", "v_00_new", test_generator:prepare_template(?B_TREE_08_64))), + ?assertException(error, {key_not_found, "k_65"}, b_trees:update("k_65", "v_65_new", test_generator:prepare_template(?B_TREE_08_64))), ok. @@ -1225,14 +1223,14 @@ update_error_test() -> %%-------------------------------------------------------------------- values_test() -> - ?assertEqual([], b_trees:values(?B_TREE_06_00)), + ?assertEqual([], b_trees:values(test_generator:prepare_template(?B_TREE_06_00))), - ?assertEqual(["v_01"], b_trees:values(?B_TREE_06_01)), + ?assertEqual(["v_01"], b_trees:values(test_generator:prepare_template(?B_TREE_06_01))), - ?assertEqual(2, length(b_trees:values(?B_TREE_06_02))), - ?assertEqual(5, length(b_trees:values(?B_TREE_06_05))), - ?assertEqual(9, length(b_trees:values(?B_TREE_06_09))), - ?assertEqual(16, length(b_trees:values(?B_TREE_06_16))), + ?assertEqual(2, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_02)))), + ?assertEqual(5, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_05)))), + ?assertEqual(9, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_09)))), + ?assertEqual(16, length(b_trees:values(test_generator:prepare_template(?B_TREE_06_16)))), ok. @@ -1240,8 +1238,3 @@ values_test() -> %% Helper functions. %%-------------------------------------------------------------------- -iterate_next_b_tree(_, 0, KeyValues) -> - KeyValues; -iterate_next_b_tree(Iterator, Count, KeyValues) -> - {Key, Value, IteratorNew} = b_trees:next(Iterator), - iterate_next_b_tree(IteratorNew, Count - 1, KeyValues ++ [{Key, Value}]).