Skip to content

Commit fe1fefb

Browse files
committed
Adding tests for "2nd degree polynomial - simple analysis".
1 parent 3207eba commit fe1fefb

File tree

9 files changed

+131
-0
lines changed

9 files changed

+131
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Tests for "Detective geek".
3434
- Tests for "Largest number".
3535
- Tests for "Smooth!".
36+
- Tests for "2nd degree polynomial - simple analysis".
3637

3738
## [3.9.0] - 2022-06-01
3839
### Added
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Easy\SecondDegreePolynomialSimpleAnalysis;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "2nd degree polynomial - simple analysis" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/2nd-degree-polynomial---simple-analysis
12+
*/
13+
class SecondDegreePolynomialSimpleAnalysis implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%f %f %f", $a, $b, $c);
18+
19+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
20+
21+
echo("(X1,Y1),...,(Xn,Yn)\n");
22+
}
23+
}
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\Easy\SecondDegreePolynomialSimpleAnalysis;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Easy\SecondDegreePolynomialSimpleAnalysis\SecondDegreePolynomialSimpleAnalysis;
9+
10+
/**
11+
* Tests for the "2nd degree polynomial - simple analysis" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Easy\SecondDegreePolynomialSimpleAnalysis\SecondDegreePolynomialSimpleAnalysis
14+
* @group secondDegreePolynomialSimpleAnalysis
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new SecondDegreePolynomialSimpleAnalysis();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Centered parabol, 1 intersection".
26+
*
27+
* @group secondDegreePolynomialSimpleAnalysis_centeredParabol1Intersection
28+
*/
29+
public function testCanExecuteCenteredParabol1Intersection(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - centered parabol, 1 intersection.txt',
33+
"(0,1)" . PHP_EOL
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Horizontal line, 1 intersection to be rounded".
39+
*
40+
* @group secondDegreePolynomialSimpleAnalysis_horizontalLine1IntersectionToBeRounded
41+
*/
42+
public function testCanExecuteHorizontalLine1IntersectionToBeRounded(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - horizontal line, 1 intersection to be rounded.txt',
46+
"(0,1.34)" . PHP_EOL
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Straight line, 2 intersections".
52+
*
53+
* @group secondDegreePolynomialSimpleAnalysis_straightLine2Intersections
54+
*/
55+
public function testCanExecuteStraightLine2Intersections(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - straight line, 2 intersections.txt',
59+
"(0,2),(2,0)" . PHP_EOL
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Centered parabol, 3 intersections".
65+
*
66+
* @group secondDegreePolynomialSimpleAnalysis_centeredParabol3Intersections
67+
*/
68+
public function testCanExecuteCenteredParabol3Intersections(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - centered parabol, 3 intersections.txt',
72+
"(-0.5,0),(0,-0.75),(0.5,0)" . PHP_EOL
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Parabol on the right, 2 intersections".
78+
*
79+
* @group secondDegreePolynomialSimpleAnalysis_parabolOnTheRight2Intersections
80+
*/
81+
public function testCanExecuteParabolOnTheRight2Intersections(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - parabol on the right, 2 intersections.txt',
85+
"(0,1),(1,0)" . PHP_EOL
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Special case".
91+
*
92+
* @group secondDegreePolynomialSimpleAnalysis_specialCase
93+
*/
94+
public function testCanExecuteSpecialCase(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - special case.txt',
98+
"(0,0)" . PHP_EOL
99+
);
100+
}
101+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 0 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 0 1.3357
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 -1 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3 0 -0.75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 -2 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 0 0

0 commit comments

Comments
 (0)