projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge commit 'origin/stable'
[pspp-builds.git]
/
tests
/
libpspp
/
tower-test.c
diff --git
a/tests/libpspp/tower-test.c
b/tests/libpspp/tower-test.c
index f78fb8920700b50d2e77cca2dd86e0d4b69adaa3..c603c3a876a61ee2ce5e21815d93e6a8e829e1c6 100644
(file)
--- a/
tests/libpspp/tower-test.c
+++ b/
tests/libpspp/tower-test.c
@@
-1,20
+1,18
@@
-/* PSPP -
computes sample statistic
s.
+/* PSPP -
a program for statistical analysi
s.
Copyright (C) 2007 Free Software Foundation, Inc.
Copyright (C) 2007 Free Software Foundation, Inc.
- This program is free software
; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of the
-
License, or
(at your option) any later version.
+ This program is free software
: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful,
but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU
- General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+
but
WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ G
NU G
eneral Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This is a test program for the routines defined in tower.c.
This test program aims to be as comprehensive as possible.
/* This is a test program for the routines defined in tower.c.
This test program aims to be as comprehensive as possible.
@@
-32,6
+30,7
@@
#include <assert.h>
#include <limits.h>
#include <assert.h>
#include <limits.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-46,17
+45,17
@@
static const char *test_name;
/* Exit with a failure code.
(Place a breakpoint on this function while debugging.) */
static void
/* Exit with a failure code.
(Place a breakpoint on this function while debugging.) */
static void
-check_die (void)
+check_die (void)
{
{
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
}
/* If OK is not true, prints a message about failure on the
current source file and the given LINE and terminates. */
static void
}
/* If OK is not true, prints a message about failure on the
current source file and the given LINE and terminates. */
static void
-check_func (bool ok, int line)
+check_func (bool ok, int line)
{
{
- if (!ok)
+ if (!ok)
{
printf ("Check failed in %s test at %s, line %d\n",
test_name, __FILE__, line);
{
printf ("Check failed in %s test at %s, line %d\n",
test_name, __FILE__, line);
@@
-87,7
+86,7
@@
tower_node_to_block (const struct tower_node *node)
/* Swaps *A and *B. */
static void
/* Swaps *A and *B. */
static void
-swap (int *a, int *b)
+swap (int *a, int *b)
{
int t = *a;
*a = *b;
{
int t = *a;
*a = *b;
@@
-118,7
+117,7
@@
next_permutation (int *values, size_t cnt)
if (cnt > 0)
{
size_t i = cnt - 1;
if (cnt > 0)
{
size_t i = cnt - 1;
- while (i != 0)
+ while (i != 0)
{
i--;
if (values[i] < values[i + 1])
{
i--;
if (values[i] < values[i + 1])
@@
-129,18
+128,18
@@
next_permutation (int *values, size_t cnt)
swap (values + i, values + j);
reverse (values + (i + 1), cnt - (i + 1));
return true;
swap (values + i, values + j);
reverse (values + (i + 1), cnt - (i + 1));
return true;
- }
+ }
}
}
-
+
reverse (values, cnt);
}
reverse (values, cnt);
}
-
+
return false;
}
/* Returns N!. */
static unsigned int
return false;
}
/* Returns N!. */
static unsigned int
-factorial (unsigned int n)
+factorial (unsigned int n)
{
unsigned int value = 1;
/* Disallow N values that overflow on 32-bit machines. */
{
unsigned int value = 1;
/* Disallow N values that overflow on 32-bit machines. */
@@
-153,7
+152,7
@@
factorial (unsigned int n)
/* Returns C(n, k), the number of ways that K choices can be made
from N items when order is unimportant. */
static unsigned int
/* Returns C(n, k), the number of ways that K choices can be made
from N items when order is unimportant. */
static unsigned int
-binomial_cofficient (unsigned int n, unsigned int k)
+binomial_cofficient (unsigned int n, unsigned int k)
{
assert (n >= k);
return factorial (n) / factorial (k) / factorial (n - k);
{
assert (n >= k);
return factorial (n) / factorial (k) / factorial (n - k);
@@
-162,7
+161,7
@@
binomial_cofficient (unsigned int n, unsigned int k)
/* Tests whether PARTS is a K-part integer composition of N.
Returns true if so, false otherwise. */
static bool UNUSED
/* Tests whether PARTS is a K-part integer composition of N.
Returns true if so, false otherwise. */
static bool UNUSED
-is_k_composition (int n, int k, const int parts[])
+is_k_composition (int n, int k, const int parts[])
{
int sum;
int i;
{
int sum;
int i;
@@
-183,7
+182,7
@@
is_k_composition (int n, int k, const int parts[])
already the greatest K-part composition of N (in which case
PARTS is unaltered). */
static bool
already the greatest K-part composition of N (in which case
PARTS is unaltered). */
static bool
-next_k_composition (int n UNUSED, int k, int parts[])
+next_k_composition (int n UNUSED, int k, int parts[])
{
int x, i;
{
int x, i;
@@
-209,7
+208,7
@@
next_k_composition (int n UNUSED, int k, int parts[])
/* Sets the K integers in PARTS to the lexicographically first
K-part composition of N. */
static void
/* Sets the K integers in PARTS to the lexicographically first
K-part composition of N. */
static void
-first_k_composition (int n, int k, int parts[])
+first_k_composition (int n, int k, int parts[])
{
int i;
{
int i;
@@
-230,7
+229,7
@@
first_k_composition (int n, int k, int parts[])
Returns true if successful, false if the set of compositions
has been exhausted. */
static bool
Returns true if successful, false if the set of compositions
has been exhausted. */
static bool
-next_composition (int n, int *k, int parts[])
+next_composition (int n, int *k, int parts[])
{
if (*k >= 1 && next_k_composition (n, *k, parts))
return true;
{
if (*k >= 1 && next_k_composition (n, *k, parts))
return true;
@@
-244,9
+243,9
@@
next_composition (int n, int *k, int parts[])
}
/* A block expected to be found in a tower. */
}
/* A block expected to be found in a tower. */
-struct expected_block
+struct expected_block
{
{
- int
height; /* Expected height of bottom
of block. */
+ int
size; /* Expected thickness
of block. */
int x; /* Expected value for `x' member. */
};
int x; /* Expected value for `x' member. */
};
@@
-254,21
+253,22
@@
struct expected_block
BLOCKS[]. */
static void
check_tower (struct tower *t,
BLOCKS[]. */
static void
check_tower (struct tower *t,
- struct expected_block blocks[], size_t block_cnt)
+ struct expected_block blocks[], size_t block_cnt)
{
int total_height;
struct tower_node *node;
size_t i;
{
int total_height;
struct tower_node *node;
size_t i;
-
+
+ check (tower_count (t) == block_cnt);
check (tower_is_empty (t) == (block_cnt == 0));
total_height = 0;
check (tower_is_empty (t) == (block_cnt == 0));
total_height = 0;
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
{
unsigned long int level;
for (level = total_height;
{
unsigned long int level;
for (level = total_height;
- level < total_height + blocks[i].
height
;
- level++)
+ level < total_height + blocks[i].
size
;
+ level++)
{
struct tower_node *found;
unsigned long int block_start;
{
struct tower_node *found;
unsigned long int block_start;
@@
-276,63
+276,75
@@
check_tower (struct tower *t,
check (found != NULL);
check (tower_node_to_block (found)->x == blocks[i].x);
check (block_start == total_height);
check (found != NULL);
check (tower_node_to_block (found)->x == blocks[i].x);
check (block_start == total_height);
+ check (tower_node_get_level (found) == total_height);
+ check (tower_node_get_index (found) == i);
+ check (tower_get (t, i) == found);
}
}
- total_height += blocks[i].
height;
+ total_height += blocks[i].
size;
}
check (tower_height (t) == total_height);
for (node = tower_first (t), i = 0;
node != NULL;
}
check (tower_height (t) == total_height);
for (node = tower_first (t), i = 0;
node != NULL;
- node = tower_next (t, node), i++)
+ node = tower_next (t, node), i++)
{
{
- check (tower_node_get_
height (node) == blocks[i].height
);
+ check (tower_node_get_
size (node) == blocks[i].size
);
check (tower_node_to_block (node)->x == blocks[i].x);
}
check (i == block_cnt);
check (tower_node_to_block (node)->x == blocks[i].x);
}
check (i == block_cnt);
+
+ for (node = tower_last (t), i = block_cnt - 1;
+ node != NULL;
+ node = tower_prev (t, node), i--)
+ {
+ check (tower_node_get_size (node) == blocks[i].size);
+ check (tower_node_to_block (node)->x == blocks[i].x);
+ }
+ check (i == SIZE_MAX);
}
\f
/* Tests inserting all possible sets of block heights into a
tower in all possible orders, up to a specified maximum tower
height. */
static void
}
\f
/* Tests inserting all possible sets of block heights into a
tower in all possible orders, up to a specified maximum tower
height. */
static void
-test_insert (void)
+test_insert (void)
{
const int max_height = 7;
int cnt;
{
const int max_height = 7;
int cnt;
- for (cnt = 1; cnt <= max_height; cnt++)
+ for (cnt = 1; cnt <= max_height; cnt++)
{
unsigned int composition_cnt;
struct expected_block *expected;
{
unsigned int composition_cnt;
struct expected_block *expected;
- int *
height
s;
+ int *
size
s;
int block_cnt;
int *order;
struct block *blocks;
int block_cnt;
int *order;
struct block *blocks;
-
+
expected = xnmalloc (cnt, sizeof *expected);
expected = xnmalloc (cnt, sizeof *expected);
-
heights = xnmalloc (cnt, sizeof *height
s);
+
sizes = xnmalloc (cnt, sizeof *size
s);
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
- while (next_composition (cnt, &block_cnt,
heights))
+ while (next_composition (cnt, &block_cnt,
sizes))
{
int i, j;
unsigned int permutation_cnt;
{
int i, j;
unsigned int permutation_cnt;
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
order[i] = i;
permutation_cnt = 0;
order[i] = i;
permutation_cnt = 0;
- while (permutation_cnt == 0 || next_permutation (order, block_cnt))
+ while (permutation_cnt == 0 || next_permutation (order, block_cnt))
{
struct tower t;
/* Inserts the block_cnt blocks with the given
{
struct tower t;
/* Inserts the block_cnt blocks with the given
-
height
s[] into T in the order given by order[]. */
+
size
s[] into T in the order given by order[]. */
tower_init (&t);
tower_init (&t);
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
{
struct block *under;
int idx;
{
struct block *under;
int idx;
@@
-346,14
+358,14
@@
test_insert (void)
&& (under == NULL || under->x > order[j]))
under = &blocks[order[j]];
&& (under == NULL || under->x > order[j]))
under = &blocks[order[j]];
- tower_insert (&t,
height
s[idx], &blocks[idx].node,
+ tower_insert (&t,
size
s[idx], &blocks[idx].node,
under != NULL ? &under->node : NULL);
}
/* Check that the result is what we expect. */
for (i = 0; i < block_cnt; i++)
{
under != NULL ? &under->node : NULL);
}
/* Check that the result is what we expect. */
for (i = 0; i < block_cnt; i++)
{
- expected[i].
height = height
s[i];
+ expected[i].
size = size
s[i];
expected[i].x = i;
}
check_tower (&t, expected, block_cnt);
expected[i].x = i;
}
check_tower (&t, expected, block_cnt);
@@
-361,67
+373,67
@@
test_insert (void)
permutation_cnt++;
}
check (permutation_cnt == factorial (block_cnt));
permutation_cnt++;
}
check (permutation_cnt == factorial (block_cnt));
-
+
composition_cnt++;
}
check (composition_cnt == 1 << (cnt - 1));
free (expected);
composition_cnt++;
}
check (composition_cnt == 1 << (cnt - 1));
free (expected);
- free (
height
s);
+ free (
size
s);
free (order);
free (blocks);
}
}
/* Tests deleting blocks from towers that initially contain all
free (order);
free (blocks);
}
}
/* Tests deleting blocks from towers that initially contain all
- possible sets of block
height
s into a tower in all possible
+ possible sets of block
size
s into a tower in all possible
orders, up to a specified maximum tower height. */
static void
orders, up to a specified maximum tower height. */
static void
-test_delete (void)
+test_delete (void)
{
const int max_height = 7;
int cnt;
{
const int max_height = 7;
int cnt;
- for (cnt = 1; cnt <= max_height; cnt++)
+ for (cnt = 1; cnt <= max_height; cnt++)
{
unsigned int composition_cnt;
struct expected_block *expected;
{
unsigned int composition_cnt;
struct expected_block *expected;
- int *
height
s;
+ int *
size
s;
int block_cnt;
int *order;
struct block *blocks;
int block_cnt;
int *order;
struct block *blocks;
-
+
expected = xnmalloc (cnt, sizeof *expected);
expected = xnmalloc (cnt, sizeof *expected);
-
heights = xnmalloc (cnt, sizeof *height
s);
+
sizes = xnmalloc (cnt, sizeof *size
s);
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
- while (next_composition (cnt, &block_cnt,
heights))
+ while (next_composition (cnt, &block_cnt,
sizes))
{
int i;
unsigned int permutation_cnt;
{
int i;
unsigned int permutation_cnt;
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
order[i] = i;
permutation_cnt = 0;
order[i] = i;
permutation_cnt = 0;
- while (permutation_cnt == 0 || next_permutation (order, block_cnt))
+ while (permutation_cnt == 0 || next_permutation (order, block_cnt))
{
struct tower t;
/* Insert blocks into tower in ascending order. */
tower_init (&t);
{
struct tower t;
/* Insert blocks into tower in ascending order. */
tower_init (&t);
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
{
blocks[i].x = i;
{
blocks[i].x = i;
- tower_insert (&t,
height
s[i], &blocks[i].node, NULL);
+ tower_insert (&t,
size
s[i], &blocks[i].node, NULL);
expected[i].x = i;
expected[i].x = i;
- expected[i].
height = height
s[i];
+ expected[i].
size = size
s[i];
}
check_tower (&t, expected, block_cnt);
}
check_tower (&t, expected, block_cnt);
-
+
/* Delete blocks from tower in the order of
order[]. */
for (i = 0; i < block_cnt; i++)
/* Delete blocks from tower in the order of
order[]. */
for (i = 0; i < block_cnt; i++)
@@
-429,7
+441,7
@@
test_delete (void)
int idx = order[i];
int j;
tower_delete (&t, &blocks[idx].node);
int idx = order[i];
int j;
tower_delete (&t, &blocks[idx].node);
- for (j = 0; ; j++)
+ for (j = 0; ; j++)
{
assert (j < block_cnt - i);
if (expected[j].x == idx)
{
assert (j < block_cnt - i);
if (expected[j].x == idx)
@@
-445,85
+457,85
@@
test_delete (void)
permutation_cnt++;
}
check (permutation_cnt == factorial (block_cnt));
permutation_cnt++;
}
check (permutation_cnt == factorial (block_cnt));
-
+
composition_cnt++;
}
check (composition_cnt == 1 << (cnt - 1));
free (expected);
composition_cnt++;
}
check (composition_cnt == 1 << (cnt - 1));
free (expected);
- free (
height
s);
+ free (
size
s);
free (order);
free (blocks);
}
}
free (order);
free (blocks);
}
}
-/* Tests towers containing all possible block
height
s, resizing
- the blocks to all possible
height
s that conserve the total
+/* Tests towers containing all possible block
size
s, resizing
+ the blocks to all possible
size
s that conserve the total
tower height, up to a maximum total tower height. */
static void
tower height, up to a maximum total tower height. */
static void
-test_resize (void)
+test_resize (void)
{
const int max_height = 9;
int cnt;
{
const int max_height = 9;
int cnt;
- for (cnt = 1; cnt <= max_height; cnt++)
+ for (cnt = 1; cnt <= max_height; cnt++)
{
unsigned int composition_cnt;
struct expected_block *expected;
{
unsigned int composition_cnt;
struct expected_block *expected;
- int *
heights, *new_height
s;
+ int *
sizes, *new_size
s;
int block_cnt;
int *order;
struct block *blocks;
int block_cnt;
int *order;
struct block *blocks;
-
+
expected = xnmalloc (cnt, sizeof *expected);
expected = xnmalloc (cnt, sizeof *expected);
-
heights = xnmalloc (cnt, sizeof *height
s);
- new_
heights = xnmalloc (cnt, sizeof *new_height
s);
+
sizes = xnmalloc (cnt, sizeof *size
s);
+ new_
sizes = xnmalloc (cnt, sizeof *new_size
s);
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
- while (next_composition (cnt, &block_cnt,
heights))
+ while (next_composition (cnt, &block_cnt,
sizes))
{
int i;
unsigned int resizes = 0;
{
int i;
unsigned int resizes = 0;
- for (resizes = 0, first_k_composition (cnt, block_cnt, new_
height
s);
+ for (resizes = 0, first_k_composition (cnt, block_cnt, new_
size
s);
(resizes == 0
(resizes == 0
- || next_k_composition (cnt, block_cnt, new_
height
s));
+ || next_k_composition (cnt, block_cnt, new_
size
s));
resizes++)
{
struct tower t;
/* Insert blocks into tower in ascending order. */
tower_init (&t);
resizes++)
{
struct tower t;
/* Insert blocks into tower in ascending order. */
tower_init (&t);
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
{
blocks[i].x = i;
{
blocks[i].x = i;
- tower_insert (&t,
height
s[i], &blocks[i].node, NULL);
+ tower_insert (&t,
size
s[i], &blocks[i].node, NULL);
expected[i].x = i;
expected[i].x = i;
- expected[i].
height = height
s[i];
+ expected[i].
size = size
s[i];
}
check_tower (&t, expected, block_cnt);
/* Resize all the blocks. */
}
check_tower (&t, expected, block_cnt);
/* Resize all the blocks. */
- for (i = 0; i < block_cnt; i++)
+ for (i = 0; i < block_cnt; i++)
{
{
- if (expected[i].
height != new_height
s[i] || rand () % 2)
- tower_resize (&t, &blocks[i].node, new_
height
s[i]);
- expected[i].
height = new_height
s[i];
+ if (expected[i].
size != new_size
s[i] || rand () % 2)
+ tower_resize (&t, &blocks[i].node, new_
size
s[i]);
+ expected[i].
size = new_size
s[i];
}
check_tower (&t, expected, block_cnt);
}
check (resizes == binomial_cofficient (cnt - 1, block_cnt - 1));
}
check_tower (&t, expected, block_cnt);
}
check (resizes == binomial_cofficient (cnt - 1, block_cnt - 1));
-
+
composition_cnt++;
}
check (composition_cnt == 1 << (cnt - 1));
free (expected);
composition_cnt++;
}
check (composition_cnt == 1 << (cnt - 1));
free (expected);
- free (new_
height
s);
- free (
height
s);
+ free (new_
size
s);
+ free (
size
s);
free (order);
free (blocks);
}
free (order);
free (blocks);
}
@@
-532,29
+544,29
@@
test_resize (void)
/* Tests splicing all possible contiguous sets of blocks out of one
tower into a second, initially empty tower. */
static void
/* Tests splicing all possible contiguous sets of blocks out of one
tower into a second, initially empty tower. */
static void
-test_splice_out (void)
+test_splice_out (void)
{
const int max_height = 9;
int cnt;
{
const int max_height = 9;
int cnt;
- for (cnt = 1; cnt <= max_height; cnt++)
+ for (cnt = 1; cnt <= max_height; cnt++)
{
unsigned int composition_cnt;
struct expected_block *expected;
{
unsigned int composition_cnt;
struct expected_block *expected;
- int *
heights, *new_height
s;
+ int *
sizes, *new_size
s;
int block_cnt;
int *order;
struct block *blocks;
int block_cnt;
int *order;
struct block *blocks;
-
+
expected = xnmalloc (cnt, sizeof *expected);
expected = xnmalloc (cnt, sizeof *expected);
-
heights = xnmalloc (cnt, sizeof *height
s);
- new_
heights = xnmalloc (cnt, sizeof *new_height
s);
+
sizes = xnmalloc (cnt, sizeof *size
s);
+ new_
sizes = xnmalloc (cnt, sizeof *new_size
s);
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
- while (next_composition (cnt, &block_cnt,
heights))
+ while (next_composition (cnt, &block_cnt,
sizes))
{
int i, j;
{
int i, j;
@@
-568,12
+580,12
@@
test_splice_out (void)
tower_init (&dst);
/* Insert blocks into SRC and DST in ascending order. */
tower_init (&dst);
/* Insert blocks into SRC and DST in ascending order. */
- for (k = 0; k < block_cnt; k++)
+ for (k = 0; k < block_cnt; k++)
{
blocks[k].x = k;
{
blocks[k].x = k;
- tower_insert (&src,
height
s[k], &blocks[k].node, NULL);
+ tower_insert (&src,
size
s[k], &blocks[k].node, NULL);
expected[k].x = k;
expected[k].x = k;
- expected[k].
height = height
s[k];
+ expected[k].
size = size
s[k];
}
check_tower (&src, expected, block_cnt);
}
check_tower (&src, expected, block_cnt);
@@
-590,8
+602,8
@@
test_splice_out (void)
check (composition_cnt == 1 << (cnt - 1));
free (expected);
check (composition_cnt == 1 << (cnt - 1));
free (expected);
- free (new_
height
s);
- free (
height
s);
+ free (new_
size
s);
+ free (
size
s);
free (order);
free (blocks);
}
free (order);
free (blocks);
}
@@
-600,29
+612,29
@@
test_splice_out (void)
/* Tests splicing all of the contents of a tower into all
possible positions in a second tower. */
static void
/* Tests splicing all of the contents of a tower into all
possible positions in a second tower. */
static void
-test_splice_in (void)
+test_splice_in (void)
{
const int max_height = 9;
int cnt;
{
const int max_height = 9;
int cnt;
- for (cnt = 1; cnt <= max_height; cnt++)
+ for (cnt = 1; cnt <= max_height; cnt++)
{
unsigned int composition_cnt;
struct expected_block *expected;
{
unsigned int composition_cnt;
struct expected_block *expected;
- int *
heights, *new_height
s;
+ int *
sizes, *new_size
s;
int block_cnt;
int *order;
struct block *blocks;
int block_cnt;
int *order;
struct block *blocks;
-
+
expected = xnmalloc (cnt, sizeof *expected);
expected = xnmalloc (cnt, sizeof *expected);
-
heights = xnmalloc (cnt, sizeof *height
s);
- new_
heights = xnmalloc (cnt, sizeof *new_height
s);
+
sizes = xnmalloc (cnt, sizeof *size
s);
+ new_
sizes = xnmalloc (cnt, sizeof *new_size
s);
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
order = xnmalloc (cnt, sizeof *order);
blocks = xnmalloc (cnt, sizeof *blocks);
block_cnt = 0;
composition_cnt = 0;
- while (next_composition (cnt, &block_cnt,
heights))
+ while (next_composition (cnt, &block_cnt,
sizes))
{
int i, j;
{
int i, j;
@@
-636,13
+648,13
@@
test_splice_in (void)
tower_init (&dst);
/* Insert blocks into SRC and DST in ascending order. */
tower_init (&dst);
/* Insert blocks into SRC and DST in ascending order. */
- for (k = 0; k < block_cnt; k++)
+ for (k = 0; k < block_cnt; k++)
{
blocks[k].x = k;
{
blocks[k].x = k;
- tower_insert (k >= i && k < j ? &src : &dst,
-
height
s[k], &blocks[k].node, NULL);
+ tower_insert (k >= i && k < j ? &src : &dst,
+
size
s[k], &blocks[k].node, NULL);
expected[k].x = k;
expected[k].x = k;
- expected[k].
height = height
s[k];
+ expected[k].
size = size
s[k];
}
/* Splice SRC into DST. */
}
/* Splice SRC into DST. */
@@
-655,8
+667,8
@@
test_splice_in (void)
check (composition_cnt == 1 << (cnt - 1));
free (expected);
check (composition_cnt == 1 << (cnt - 1));
free (expected);
- free (new_
height
s);
- free (
height
s);
+ free (new_
size
s);
+ free (
size
s);
free (order);
free (blocks);
}
free (order);
free (blocks);
}
@@
-667,7
+679,7
@@
test_splice_in (void)
/* Runs TEST_FUNCTION and prints a message about NAME. */
static void
/* Runs TEST_FUNCTION and prints a message about NAME. */
static void
-run_test (void (*test_function) (void), const char *name)
+run_test (void (*test_function) (void), const char *name)
{
test_name = name;
putchar ('.');
{
test_name = name;
putchar ('.');
@@
-676,7
+688,7
@@
run_test (void (*test_function) (void), const char *name)
}
int
}
int
-main (void)
+main (void)
{
run_test (test_insert, "insert");
run_test (test_delete, "delete");
{
run_test (test_insert, "insert");
run_test (test_delete, "delete");