www.delorie.com/gnu/docs/avl/libavl_215.html   search  
 
Buy GNU books!


GNU libavl 2.0.1

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

12.7 Testing

 
&#60;@xref{\NODE\, , License.&#62;,1}
#include &#60;assert.h&#62;
#include &#60;limits.h&#62;
#include &#60;stdio.h&#62;
#include "rtavl.h"
#include "test.h"
&#60;@xref{\NODE\, , RTBST print function; rtbst =>.&#62; rtavl,412}
&#60;@xref{\NODE\, , BST traverser check function; bst =>.&#62; rtavl,104}
&#60;@xref{\NODE\, , Compare two RTAVL trees for structure and content.&#62;,450}
&#60;@xref{\NODE\, , Recursively verify RTAVL tree structure.&#62;,451}
&#60;@xref{\NODE\, , AVL tree verify function; avl =>.&#62; rtavl,190}
&#60;@xref{\NODE\, , BST test function; bst =>.&#62; rtavl,100}
&#60;@xref{\NODE\, , BST overflow test function; bst =>.&#62; rtavl,122}

 
static int 
compare_trees (struct rtavl_node *a, struct rtavl_node *b)
{ int okay; if (a == NULL || b == NULL)
{ if (a != NULL || b != NULL)
{ printf ("a=%db=%d\n", a ? *(int *) a-&#62;rtavl_data : -1,
b ? *(int *) b-&#62;rtavl_data : -1); assert (0); } return 1; } assert (a != b); if (*(int *) a-&#62;rtavl_data != *(int *) b-&#62;rtavl_data || a-&#62;rtavl_rtag != b-&#62;rtavl_rtag || a-&#62;rtavl_balance != b-&#62;rtavl_balance)
{ printf ("Copiednodesdiffer:a=%d(bal=%d)b=%d(bal=%d)a:", *(int *) a-&#62;rtavl_data, a-&#62;rtavl_balance, *(int *) b-&#62;rtavl_data, b-&#62;rtavl_balance); if (a-&#62;rtavl_rtag == RTAVL_CHILD)
printf ("r"); printf ("b:"); if (b-&#62;rtavl_rtag == RTAVL_CHILD)
printf ("r"); printf ("\n"); return 0; } if (a-&#62;rtavl_rtag == RTAVL_THREAD) assert ((a-&#62;rtavl_link[1] == NULL) != (a-&#62;rtavl_link[1] != b-&#62;rtavl_link[1])); okay = compare_trees (a-&#62;rtavl_link[0], b-&#62;rtavl_link[0]); if (a-&#62;rtavl_rtag == RTAVL_CHILD) okay &= compare_trees (a-&#62;rtavl_link[1], b-&#62;rtavl_link[1]); return okay; }
This code is included in @refalso{449

 
static void 
recurse_verify_tree (struct rtavl_node *node, int *okay, size_t *count, int min, int max, int *height)
{ int d; /* Value of this node's data. */ size_t subcount[2]; /* Number of nodes in subtrees. */ int subheight[2]; /* Heights of subtrees. */ if (node == NULL)
{ *count = 0; *height = 0; return; } d = *(int *) node-&#62;rtavl_data; &#60;@xref{\NODE\, , Verify binary search tree ordering.&#62;,114} subcount[0] = subcount[1] = 0; subheight[0] = subheight[1] = 0; recurse_verify_tree (node-&#62;rtavl_link[0], okay, &subcount[0], min, d - 1, &subheight[0]); if (node-&#62;rtavl_rtag == RTAVL_CHILD) recurse_verify_tree (node-&#62;rtavl_link[1], okay, &subcount[1], d + 1, max, &subheight[1]); *count = 1 + subcount[0] + subcount[1]; *height = 1 + (subheight[0] > subheight[1] ? subheight[0] : subheight[1]); &#60;@xref{\NODE\, , Verify AVL node balance factor; avl =>.&#62; rtavl,189} }
This code is included in @refalso{449


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003