-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobject_directory_test.go
More file actions
42 lines (38 loc) · 1.37 KB
/
object_directory_test.go
File metadata and controls
42 lines (38 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package caskin_test
import (
"math/rand"
"testing"
"time"
"github.com/awatercolorpen/caskin"
"github.com/awatercolorpen/caskin/example"
"github.com/stretchr/testify/assert"
)
func TestNewObjectDirectory(t *testing.T) {
// object1 := &example.Object{ID: 1, ParentID: 0}
object2 := &example.Object{ID: 2, ParentID: 1}
// object3 := &example.Object{ID: 3, ParentID: 1}
object4 := &example.Object{ID: 4, ParentID: 2}
object5 := &example.Object{ID: 5, ParentID: 2}
object6 := &example.Object{ID: 6, ParentID: 3}
object7 := &example.Object{ID: 7, ParentID: 3}
object8 := &example.Object{ID: 8, ParentID: 5}
directory := []*caskin.Directory{
{Object: object2, TopItemCount: 2},
{Object: object4, TopItemCount: 4},
{Object: object5, TopItemCount: 5},
{Object: object6, TopItemCount: 6},
{Object: object7, TopItemCount: 7},
{Object: object8, TopItemCount: 8},
}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(directory), func(i, j int) { directory[i], directory[j] = directory[j], directory[i] })
od := caskin.NewObjectDirectory(directory)
assert.Equal(t, uint64(3), od.Node[2].AllDirectoryCount)
assert.Equal(t, uint64(19), od.Node[2].AllItemCount)
assert.Equal(t, uint64(1), od.Node[5].AllDirectoryCount)
assert.Equal(t, uint64(13), od.Node[5].AllItemCount)
list1 := od.Search(0, "")
assert.Len(t, list1, 3)
list2 := od.Search(0, "all")
assert.Len(t, list2, 6)
}