tree_test.go 678 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // tree_tes
  2. package tree
  3. import (
  4. _ "strings"
  5. "testing"
  6. )
  7. func TestNode(test *testing.T) {
  8. tree := New(nil, "root")
  9. s1 := "l1 c1"
  10. s2 := "l1 c2"
  11. s3 := "l1 c3"
  12. s4 := "l2 c1"
  13. l1c1 := tree.NewChild(s1)
  14. l1c2 := tree.NewChild(s2)
  15. l1c3 := tree.NewChild(s3)
  16. l2c1 := l1c1.NewChild(s4)
  17. if l1c1.Data != s1 {
  18. test.Error("Data ")
  19. }
  20. if l1c2.Data != s2 {
  21. test.Error("Data ")
  22. }
  23. if l1c3.Data != s3 {
  24. test.Error("Data ")
  25. }
  26. if l2c1.Data != s4 {
  27. test.Error("Data ")
  28. }
  29. n := tree.Walk(func(node *Node) *Node {
  30. if node.Data == s4 {
  31. return node
  32. }
  33. return nil
  34. })
  35. if n.Data != s4 {
  36. test.Error("Data ")
  37. }
  38. test.Logf("%v", n.Data)
  39. test.Log("Hi tree!")
  40. }