Skip to content

Commit 953412a

Browse files
committed
Increase tests coverage.
1 parent 170ed5f commit 953412a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

spec/drupol/phptree/Node/NaryNodeSpec.php

+31
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
namespace spec\drupol\phptree\Node;
66

77
use drupol\phptree\Node\NaryNode;
8+
use drupol\phptree\Node\Node;
89
use drupol\phptree\Node\ValueNode;
10+
use drupol\phptree\Traverser\BreadthFirst;
11+
use drupol\phptree\Traverser\PreOrder;
912
use drupol\phptree\Traverser\TraverserInterface;
1013

1114
class NaryNodeSpec extends NodeObjectBehavior
@@ -44,6 +47,25 @@ public function it_can_get_the_capacity_when_using_a_custom_capacity()
4447
->shouldReturn(3);
4548
}
4649

50+
public function it_can_have_children()
51+
{
52+
$this->beConstructedWith(2);
53+
54+
$child1 = new Node();
55+
$child2 = new NaryNode(2);
56+
$child3 = new Node();
57+
$child4 = new Node();
58+
$child5 = new Node();
59+
$child6 = new Node();
60+
$child7 = new Node();
61+
62+
$this
63+
->add($child1, $child2, $child3, $child4, $child5, $child6, $child7);
64+
65+
$this->degree()->shouldReturn(2);
66+
$this->count()->shouldReturn(4);
67+
}
68+
4769
public function it_can_throw_an_error_when_capacity_is_invalid()
4870
{
4971
$this->beConstructedWith(-5);
@@ -53,8 +75,17 @@ public function it_can_throw_an_error_when_capacity_is_invalid()
5375
->shouldReturn(0);
5476
}
5577

78+
public function it_can_use_a_different_traverser()
79+
{
80+
$this->beConstructedWith(2, null, new PreOrder());
81+
82+
$this->getTraverser()->shouldBeAnInstanceOf(PreOrder::class);
83+
}
84+
5685
public function it_is_initializable()
5786
{
5887
$this->shouldHaveType(NaryNode::class);
88+
89+
$this->getTraverser()->shouldBeAnInstanceOf(BreadthFirst::class);
5990
}
6091
}

spec/drupol/phptree/Node/NodeSpec.php

+12
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ public function it_has_a_degree()
269269
->shouldReturn(1);
270270
}
271271

272+
public function it_is_a_traversable()
273+
{
274+
$node1 = new Node();
275+
$node2 = new Node();
276+
$node3 = new Node();
277+
278+
$this
279+
->add($node1, $node2, $node3);
280+
281+
$this->shouldIterateLike($this->children());
282+
}
283+
272284
public function it_is_initializable()
273285
{
274286
$this->shouldHaveType(Node::class);

spec/drupol/phptree/Node/ValueNodeSpec.php

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function it_can_be_manipulated_like_an_array()
4747
$this->shouldThrow(\InvalidArgumentException::class)->during('offsetSet', [0, 'This is not a node']);
4848
$this->offsetGet(0)->getValue()->shouldReturn('zero');
4949
}
50+
5051
public function it_can_be_set_with_a_value()
5152
{
5253
$this

0 commit comments

Comments
 (0)