-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package tree | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cfoust/cy/pkg/geom" | ||
"github.com/cfoust/cy/pkg/mux/stream" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRoot(t *testing.T) { | ||
tree := NewTree() | ||
require.Equal(t, NodeID(1), tree.Root().Id()) | ||
require.Equal(t, 0, len(tree.Leaves())) | ||
} | ||
|
||
func emptyPane(g *Group) *Pane { | ||
return g.NewPane( | ||
context.Background(), | ||
stream.NewReader(), | ||
geom.DEFAULT_SIZE, | ||
) | ||
} | ||
|
||
func TestLeaves(t *testing.T) { | ||
tree := NewTree() | ||
g := tree.Root().NewGroup() | ||
for i := 0; i < 3; i++ { | ||
emptyPane(g) | ||
} | ||
require.Equal(t, 3, len(g.Children())) | ||
require.Equal(t, 3, len(tree.Leaves())) | ||
} | ||
|
||
func TestRemoveGroup(t *testing.T) { | ||
tree := NewTree() | ||
g := tree.Root().NewGroup() | ||
for i := 0; i < 3; i++ { | ||
emptyPane(g) | ||
} | ||
|
||
tree.RemoveNode(g.Id()) | ||
require.Equal(t, 0, len(tree.Leaves())) | ||
} | ||
|
||
func TestRemoveNode(t *testing.T) { | ||
tree := NewTree() | ||
g := tree.Root().NewGroup() | ||
for i := 0; i < 3; i++ { | ||
emptyPane(g) | ||
} | ||
|
||
child := g.Children()[1] | ||
tree.RemoveNode(child.Id()) | ||
require.Equal(t, 2, len(tree.Leaves())) | ||
require.Equal(t, 2, len(g.Children())) | ||
} | ||
|
||
func TestRemoveRoot(t *testing.T) { | ||
tree := NewTree() | ||
require.Error(t, tree.RemoveNode(tree.Root().Id())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,6 @@ func getLeaves(node Node) (result []Node) { | |
result, | ||
getLeaves(child)..., | ||
) | ||
return | ||
} | ||
} | ||
|
||
|