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


GNU libavl 2.0.1

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

16.5 Testing

No comment is necessary.

 
&#60;@xref{\NODE\, , License.&#62;,1}
#include &#60;assert.h&#62;
#include &#60;limits.h&#62;
#include &#60;stdio.h&#62;
#include "prb.h"
#include "test.h"
&#60;@xref{\NODE\, , BST print function; bst =>.&#62; prb,119}
&#60;@xref{\NODE\, , BST traverser check function; bst =>.&#62; prb,104}
&#60;@xref{\NODE\, , Compare two PRB trees for structure and content.&#62;,584}
&#60;@xref{\NODE\, , Recursively verify PRB tree structure.&#62;,585}
&#60;@xref{\NODE\, , RB tree verify function; rb =>.&#62; prb,244}
&#60;@xref{\NODE\, , BST test function; bst =>.&#62; prb,100}
&#60;@xref{\NODE\, , BST overflow test function; bst =>.&#62; prb,122}

 
static int 
compare_trees (struct prb_node *a, struct prb_node *b)
{ int okay; if (a == NULL || b == NULL)
{ assert (a == NULL && b == NULL); return 1; } if (*(int *) a-&#62;prb_data != *(int *) b-&#62;prb_data || ((a-&#62;prb_link[0] != NULL) != (b-&#62;prb_link[0] != NULL)) || ((a-&#62;prb_link[1] != NULL) != (b-&#62;prb_link[1] != NULL)) || a-&#62;prb_color != b-&#62;prb_color)
{ printf ("Copiednodesdiffer:a=%d%cb=%d%ca:", *(int *) a-&#62;prb_data, a-&#62;prb_color == PRB_RED ? 'r' : 'b', *(int *) b-&#62;prb_data, b-&#62;prb_color == PRB_RED ? 'r' : 'b'); if (a-&#62;prb_link[0] != NULL)
printf ("l"); if (a-&#62;prb_link[1] != NULL)
printf ("r"); printf ("b:"); if (b-&#62;prb_link[0] != NULL)
printf ("l"); if (b-&#62;prb_link[1] != NULL)
printf ("r"); printf ("\n"); return 0; } okay = 1; if (a-&#62;prb_link[0] != NULL) okay &= compare_trees (a-&#62;prb_link[0], b-&#62;prb_link[0]); if (a-&#62;prb_link[1] != NULL) okay &= compare_trees (a-&#62;prb_link[1], b-&#62;prb_link[1]); return okay; }
This code is included in @refalso{583

 
/* Examines the binary tree rooted at node.  
   Zeroes *okay if an error occurs.  
Otherwise, does not modify *okay. Sets *count to the number of nodes in that tree,
including node itself if node != NULL. Sets *bh to the tree's black-height. All the nodes in the tree are verified to be at least min
but no greater than max. */ static void
recurse_verify_tree (struct prb_node *node, int *okay, size_t *count, int min, int max, int *bh)
{ int d; /* Value of this node's data. */ size_t subcount[2]; /* Number of nodes in subtrees. */ int subbh[2]; /* Black-heights of subtrees. */ int i; if (node == NULL)
{ *count = 0; *bh = 0; return; } d = *(int *) node-&#62;prb_data; &#60;@xref{\NODE\, , Verify binary search tree ordering.&#62;,114} recurse_verify_tree (node-&#62;prb_link[0], okay, &subcount[0], min, d - 1, &subbh[0]); recurse_verify_tree (node-&#62;prb_link[1], okay, &subcount[1], d + 1, max, &subbh[1]); *count = 1 + subcount[0] + subcount[1]; *bh = (node-&#62;prb_color == PRB_BLACK) + subbh[0]; &#60;@xref{\NODE\, , Verify RB node color; rb =>.&#62; prb,241} &#60;@xref{\NODE\, , Verify RB node rule 1 compliance; rb =>.&#62; prb,242} &#60;@xref{\NODE\, , Verify RB node rule 2 compliance; rb =>.&#62; prb,243} &#60;@xref{\NODE\, , Verify PBST node parent pointers; pbst =>.&#62; prb,518} }
This code is included in @refalso{583


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

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