1
0
Fork 0
ruspa/tree/dynamic_tree_test.go

104 Zeilen
2,6 KiB
Go

package tree
import (
"fmt"
"testing"
"time"
)
const result = `(0.00 KB) /
├──(0.00 KB) i1
│ ├──(0.00 KB) i1s1
│ │ ├──(0.00 KB) i1s1b1
│ │ ├──(0.00 KB) i1s1b2
│ │ └──(0.00 KB) i1s1b3
│ ├──(0.00 KB) i1s2
│ │ ├──(0.00 KB) i1s2b1
│ │ └──(0.00 KB) i1s2b2
│ ├──(0.00 KB) i1s3
│ │ ├──(0.00 KB) i1s3s1
│ │ │ ├──(0.00 KB) i1s3s1b1
│ │ │ ├──(0.00 KB) i1s3s1b2
│ │ │ └──(0.00 KB) i1s3s1b3
│ │ └──(0.00 KB) i1s3b1
│ └──(0.00 KB) i1s4
│ └──(0.00 KB) i1s4b1
├──(0.00 KB) i2
│ ├──(0.00 KB) i2b1
│ └──(0.00 KB) i2b2
└──(0.00 KB) i3
├──(0.00 KB) i3s1
│ └──(0.00 KB) i3s1b1
├──(0.00 KB) i3s2
│ ├──(0.00 KB) i3s2b1
│ └──(0.00 KB) i3s2b2
└──(0.00 KB) i3s3
└──(0.00 KB) i3s3b1
`
func createTree() *Top {
t := NewTop("/")
t.SetUnit("KB")
i1 := t.newIntermediate("i1")
i2 := t.newIntermediate("i2")
i3 := t.newIntermediate("i3")
i1s1 := i1.newIntermediate("i1s1")
i1s2 := i1.newIntermediate("i1s2")
i1s3 := i1.newIntermediate("i1s3")
i1s4 := i1.newIntermediate("i1s4")
i3s1 := i3.newIntermediate("i3s1")
i3s2 := i3.newIntermediate("i3s2")
i3s3 := i3.newIntermediate("i3s3")
_ = i1s1.newBottom("i1s1b1")
_ = i1s1.newBottom("i1s1b2")
_ = i1s1.newBottom("i1s1b3")
_ = i1s2.newBottom("i1s2b1")
_ = i1s2.newBottom("i1s2b2")
i1s3s1 := i1s3.newIntermediate("i1s3s1")
_ = i1s3.newBottom("i1s3b1")
_ = i1s4.newBottom("i1s4b1")
_ = i2.newBottom("i2b1")
_ = i2.newBottom("i2b2")
_ = i3s1.newBottom("i3s1b1")
_ = i3s2.newBottom("i3s2b1")
_ = i3s2.newBottom("i3s2b2")
_ = i3s3.newBottom("i3s3b1")
_ = i1s3s1.newBottom("i1s3s1b1")
_ = i1s3s1.newBottom("i1s3s1b2")
_ = i1s3s1.newBottom("i1s3s1b3")
return t
}
func TestString(t *testing.T) {
tree := createTree()
repr := fmt.Sprintf("%s", tree)
if repr != result {
t.Errorf("repr:\n%s\n\nresult:\n%s", repr, result)
}
}
func TestSize(t *testing.T) {
root := NewTop(".")
i := NewIntermediate("i", root)
b := NewBottom("b", i)
go func() {
ch := b.Collector()
ch <- 1024
}()
go b.Collect()
go i.Collect()
go root.Collect()
time.Sleep(time.Second)
if bsize := b.Size(); bsize != 1024 {
t.Errorf("b -> wrong size: %d\n", bsize)
}
if isize := i.Size(); isize != 1024 {
t.Errorf("i -> wrong size: %d\n", isize)
}
if tsize := root.Size(); tsize != 1024 {
t.Errorf("t -> wrong size: %d\n", tsize)
}
}