File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 11package binarytree_test
22
33import (
4+ "bytes"
45 "reflect"
6+ "strings"
57 "testing"
68
79 "gopkg.in/dnaeon/go-binarytree.v1"
@@ -349,3 +351,36 @@ func TestNodeAttributes(t *testing.T) {
349351 t .Fatal ("node attributes mismatch" )
350352 }
351353}
354+
355+ func TestWriteDot (t * testing.T ) {
356+ // Our test tree
357+ //
358+ // 1__
359+ // / \
360+ // 2 3
361+ // / \
362+ // 4 5
363+ root := binarytree .NewNode (1 )
364+ root .InsertLeft (2 )
365+ three := root .InsertRight (3 )
366+ three .InsertLeft (4 )
367+ three .InsertRight (5 )
368+
369+ var buf bytes.Buffer
370+ if err := root .WriteDot (& buf ); err != nil {
371+ t .Fatal (err )
372+ }
373+
374+ output := buf .String ()
375+ if output == "" {
376+ t .Fatal ("got empty dot representation" )
377+ }
378+
379+ if ! strings .HasPrefix (output , "digraph {" ) {
380+ t .Fatal ("missing dot prefix" )
381+ }
382+
383+ if ! strings .HasSuffix (output , "}\n " ) {
384+ t .Fatal ("missing dot suffix" )
385+ }
386+ }
You can’t perform that action at this time.
0 commit comments