title: Unit test proper data structure creation
body: <p>How would one test whether data structure built properly? I'm implementing kind of modified radix tree, and been wondering how do you check if your data structure builds up correctly.</p>
  
  <p>Consider a tree of <code>TreeNode {String, Int}</code> nodes.
  You always want to append new child to deepest node of value equal to 0, as in following example:</p>
  
  <pre>
  Root, 0
  - Child_1, 5
  - Child_2, 0
     - Child_3, 1
  </pre>
  
  <p>Question is, how to unit test if <strong>tree structure</strong> builds up as you wished? TreeNode only has one method, which would be <code>insert</code>.</p>
  
  <p>My idea so far was to write <code>TreeVisitor</code> that would walk through tree and convert each node to string. 
  Tree from example above, could look like this:</p>
  
  <pre>
  [Root, 0 [Child_1, 5][Child_2, 0 [Child_3, 1]]]
  </pre>
  
  <p>Knowing algorithm that builds tree, I can create such string manually if I have idea what elements I'm inserting. My unit test would look like this (using same example).</p>
  
  <pre><code>TreeNode root = new TreeNode("Root", 0);
  root.insert(new TreeNode("Child_1", 5));
  root.insert(new TreeNode("Child_2", 0));
  root.insert(new TreeNode("Child_3", 1));
  TreeVisitor visitor = new TreeVisitor();
  String expected = "[Root, 0 [Child_1, 5][Child_2, 0 [Child_3, 1]]]";
  asssertEquals(expected, visitor.visit(root));</code></pre>
  
  <p>I got the feeling it's not best approach. To start of, as soon as visitor changes, all tests will fail (simply put change <code>[ ]</code> to <code>( )</code>). Also, this approach allows me to test pretty small trees (as big as I can compute manually). How would you test bigger ones?</p>
  
  <p>General question is, <strong>how to write tests checking whether data structure builds up correctly</strong>? </p>
  
  <p>I assume I might be getting whole testing idea wrong, as I'm fresh from dozen tutorials where people test whether .Sum(a, b) works as expected :-) </p>