41 printf(
"sum tree... started\n");
44 const uint32 n_leaves = 128;
51 for (
uint32 i = 0; i < n_leaves; ++i)
60 if (c0 != 1 || c1 != 90 || c2 != 127)
62 log_error( stderr,
"error in test(1):\n c(0.0) = %u (!= 1)\n c(0.5) = %u (!= 90) c(1.0) = %u (!= 127)\n", c0, c1, c2 );
68 for (
uint32 i = 0; i < n_leaves; ++i)
69 vec[i] = i < n_leaves/2 ? 0 : 1;
77 if (c0 != 64 || c1 != 96 || c2 != 127)
79 log_error( stderr,
"error in test(2):\n c(0.0) = %u (!= 64)\n c(0.5) = %u (!= 90) c(1.0) = %u (!= 127)\n", c0, c1, c2 );
85 for (
uint32 i = 0; i < n_leaves; ++i)
86 vec[i] = i < n_leaves/2 ? 1 : 0;
94 if (c0 != 0 || c1 != 32 || c2 != 63)
96 log_error( stderr,
"error in test(3):\n c(0.0) = %u (!= 0)\n c(0.5) = %u (!= 32) c(1.0) = %u (!= 63)\n", c0, c1, c2 );
103 const uint32 n_leaves = 80;
116 for (
uint32 i = 0; i < n_leaves; ++i)
117 vec[i] = i < n_leaves/2 ? 0 : 1;
125 if (c0 != 40 || c1 != 60 || c2 != 79)
127 log_error( stderr,
"error in test(3):\n c(0.0) = %u (!= 40)\n c(0.5) = %u (!= 60) c(1.0) = %u (!= 79)\n", c0, c1, c2 );
133 for (
uint32 i = 0; i < n_leaves; ++i)
134 vec[i] = i < n_leaves/2 ? 1 : 0;
142 if (c0 != 0 || c1 != 20 || c2 != 39)
144 log_error( stderr,
"error in test(5):\n c(0.0) = %u (!= 0)\n c(0.5) = %u (!= 20) c(1.0) = %u (!= 39)\n", c0, c1, c2 );
150 sum_tree.
add( 39, -1 );
156 log_error( stderr,
"error in test(6):\n c(1.0) = %u (!= 38)\n", c );
161 sum_tree.
add( 38, -1 );
163 c =
sample( sum_tree, 1.0f );
166 log_error( stderr,
"error in test(7):\n c(1.0) = %u (!= 37)\n", c );
171 sum_tree.
add( 38, 1 );
174 sum_tree.
set( 38, 0 );
176 c =
sample( sum_tree, 1.0f );
179 log_error( stderr,
"error in test(8):\n c(1.0) = %u (!= 37)\n", c );
184 for (
uint32 i = 0; i < 10; ++i)
186 sum_tree.
set( i, 0 );
188 c =
sample( sum_tree, 0.0f );
191 log_error( stderr,
"error in test(9):\n c(0.0) = %u (!= %u)\n", c, i );
196 printf(
"sum tree... done\n");