Skip to content

Commit d1249d9

Browse files
committed
Adding tests for "Binary search tree
traversal".
1 parent a5fa69e commit d1249d9

File tree

15 files changed

+169
-0
lines changed

15 files changed

+169
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Tests for "Game of life".
3333
- Tests for "Maximum sub-sequence".
3434
- Tests for "Snake encoding".
35+
- Tests for "Binary search tree traversal".
3536

3637
## [3.13.0] - 2022-09-30
3738
### Added
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\BinarySearchTreeTraversal;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Binary search tree traversal" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/binary-search-tree-traversal
12+
*/
13+
class BinarySearchTreeTraversal implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d", $n);
18+
$inputs = explode(" ", fgets($stdin));
19+
for ($i = 0; $i < $n; $i++)
20+
{
21+
$vi = intval($inputs[$i]);
22+
}
23+
for ($i = 0; $i < 4; $i++)
24+
{
25+
26+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
27+
28+
echo("answer\n");
29+
}
30+
}
31+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\BinarySearchTreeTraversal;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\BinarySearchTreeTraversal\BinarySearchTreeTraversal;
9+
10+
/**
11+
* Tests for the "Binary search tree traversal" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\BinarySearchTreeTraversal\BinarySearchTreeTraversal
14+
* @group binarySearchTreeTraversal
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new BinarySearchTreeTraversal();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Example".
26+
*
27+
* @group binarySearchTreeTraversal_example
28+
*/
29+
public function testCanExecuteExample(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - example.txt',
33+
file_get_contents(__DIR__ . '/output/01 - example.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Positive values only".
39+
*
40+
* @group binarySearchTreeTraversal_positiveValuesOnly
41+
*/
42+
public function testCanExecutePositiveValuesOnly(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - positive values only.txt',
46+
file_get_contents(__DIR__ . '/output/02 - positive values only.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Small random values".
52+
*
53+
* @group binarySearchTreeTraversal_smallRandomValues
54+
*/
55+
public function testCanExecuteSmallRandomValues(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - small random values.txt',
59+
file_get_contents(__DIR__ . '/output/03 - small random values.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Large random values".
65+
*
66+
* @group binarySearchTreeTraversal_largeRandomValues
67+
*/
68+
public function testCanExecuteLargeRandomValues(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - large random values.txt',
72+
file_get_contents(__DIR__ . '/output/04 - large random values.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "More random values".
78+
*
79+
* @group binarySearchTreeTraversal_moreRandomValues
80+
*/
81+
public function testCanExecuteMoreRandomValues(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - more random values.txt',
85+
file_get_contents(__DIR__ . '/output/05 - more random values.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Ordered values".
91+
*
92+
* @group binarySearchTreeTraversal_orderedValues
93+
*/
94+
public function testCanExecuteOrderedValues(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - ordered values.txt',
98+
file_get_contents(__DIR__ . '/output/06 - ordered values.txt')
99+
);
100+
}
101+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
8 6 13 10 5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
8
2+
135 151 128 13 201 260 158 195
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10
2+
-4 2 17 -15 -17 15 -12 11 30 29
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
14
2+
80549 235191 118837 -498143 -185405 -475495 428331 -146618 -479044 -173808 417544 204945 -479692 -70525
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
30
2+
-364052 -781443 796022 298864 295887 -614308 -296991 -1129497 838567 22573 40801 273590 1033779 715337 -38508 356628 514888 386934 930494 -907064 -916571 762755 -657230 -293721 822425 -314334 -862634 -146274 228429 1042357
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
50
2+
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 43 44 45 46 47 48 49 50
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
8 6 5 13 10
2+
5 6 8 10 13
3+
5 6 10 13 8
4+
8 6 13 5 10

0 commit comments

Comments
 (0)