Skip to content

Commit df74ec1

Browse files
committed
Adding tests for "Dynamic sorting".
1 parent d7b9c98 commit df74ec1

File tree

13 files changed

+356
-1
lines changed

13 files changed

+356
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
7+
## [3.13.0] - 2022-09-30
88
### Added
99
- Tests for "Locked in gear".
1010
- Tests for "Robbery optimisation".
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
- Tests for "The lost child.Episode-1".
3535
- Tests for "Gravity tumbler".
3636
- Tests for "Jumping frogs".
37+
- Tests for "Dynamic sorting".
3738

3839
## [3.12.0] - 2022-09-01
3940
### Added
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Community\Training\Medium\DynamicSorting;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Dynamic sorting" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/dynamic-sorting
12+
*/
13+
class DynamicSorting implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
$expression = stream_get_line($stdin, 256 + 1, "\n");
18+
$types = stream_get_line($stdin, 256 + 1, "\n");
19+
fscanf($stdin, "%d", $N);
20+
for ($i = 0; $i < $N; $i++)
21+
{
22+
$ROW = stream_get_line($stdin, 256 + 1, "\n");
23+
}
24+
25+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
26+
27+
echo("answer\n");
28+
}
29+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\DynamicSorting;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\DynamicSorting\DynamicSorting;
9+
10+
/**
11+
* Tests for the "Dynamic sorting" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\DynamicSorting\DynamicSorting
14+
* @group dynamicSorting
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new DynamicSorting();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Simple name sorting".
26+
*
27+
* @group dynamicSorting_simpleNameSorting
28+
*/
29+
public function testCanExecuteSimpleNameSorting(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - simple name sorting.txt',
33+
file_get_contents(__DIR__ . '/output/01 - simple name sorting.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "ThenBy".
39+
*
40+
* @group dynamicSorting_thenBy
41+
*/
42+
public function testCanExecuteThenBy(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - thenBy.txt',
46+
file_get_contents(__DIR__ . '/output/02 - thenBy.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Large dataset".
52+
*
53+
* @group dynamicSorting_largeDataset
54+
*/
55+
public function testCanExecuteLargeDataset(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - large dataset.txt',
59+
file_get_contents(__DIR__ . '/output/03 - large dataset.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "3 sorting parameters".
65+
*
66+
* @group dynamicSorting_3SortingParameters
67+
*/
68+
public function testCanExecute3SortingParameters(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - 3 sorting parameters.txt',
72+
file_get_contents(__DIR__ . '/output/04 - 3 sorting parameters.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "4 sorting parameters".
78+
*
79+
* @group dynamicSorting_4SortingParameters
80+
*/
81+
public function testCanExecute4SortingParameters(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - 4 sorting parameters.txt',
85+
file_get_contents(__DIR__ . '/output/05 - 4 sorting parameters.txt')
86+
);
87+
}
88+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
+name
2+
string
3+
3
4+
id:1,name:maria
5+
id:2,name:jason
6+
id:3,name:robert
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
+age-name
2+
int,string
3+
6
4+
id:1,name:hugo,age:1
5+
id:2,name:maria,age:12
6+
id:3,name:jason,age:2
7+
id:4,name:amit,age:15
8+
id:5,name:maria,age:6
9+
id:6,name:robert,age:12
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
+age+name
2+
int,string
3+
33
4+
id:1,name:hugo,age:10
5+
id:2,name:maria,age:2
6+
id:3,name:jason,age:15
7+
id:4,name:amit,age:8
8+
id:5,name:maria,age:5
9+
id:6,name:david,age:20
10+
id:7,name:theo,age:22
11+
id:8,name:fabien,age:13
12+
id:9,name:michael,age:100
13+
id:10,name:jordan,age:21
14+
id:11,name:jean,age:7
15+
id:12,name:yoan,age:19
16+
id:13,name:marie,age:8
17+
id:14,name:justin,age:19
18+
id:15,name:aria,age:21
19+
id:16,name:stark,age:2
20+
id:17,name:julia,age:18
21+
id:18,name:eva,age:18
22+
id:19,name:angelina,age:8
23+
id:20,name:tori,age:22
24+
id:21,name:ariana,age:21
25+
id:22,name:sasha,age:2
26+
id:23,name:caprice,age:2
27+
id:24,name:clara,age:18
28+
id:25,name:maurice,age:15
29+
id:26,name:johny,age:17
30+
id:27,name:brigitte,age:51
31+
id:28,name:sophie,age:22
32+
id:29,name:sophia,age:21
33+
id:30,name:aurore,age:22
34+
id:31,name:david,age:9
35+
id:32,name:damien,age:19
36+
id:33,name:jason,age:19
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
+age-name+size
2+
int,string,int
3+
62
4+
id:1,name:hugo,age:10,size:165
5+
id:2,name:maria,age:12,size:85
6+
id:3,name:jason,age:15,size:190
7+
id:4,name:amit,age:18,size:60
8+
id:5,name:maria,age:15,size:155
9+
id:6,name:david,age:20,size:160
10+
id:7,name:theo,age:22,size:190
11+
id:8,name:fabien,age:13,size:180
12+
id:9,name:michael,age:15,size:80
13+
id:10,name:jordan,age:21,size:185
14+
id:11,name:jean,age:17,size:190
15+
id:12,name:yoan,age:19,size:165
16+
id:13,name:marie,age:18,size:170
17+
id:14,name:justin,age:19,size:170
18+
id:15,name:aria,age:21,size:170
19+
id:16,name:stark,age:20,size:185
20+
id:17,name:julia,age:18,size:175
21+
id:18,name:eva,age:18,size:185
22+
id:19,name:angelina,age:18,size:65
23+
id:20,name:tori,age:22,size:155
24+
id:21,name:ariana,age:21,size:160
25+
id:22,name:sasha,age:20,size:160
26+
id:23,name:caprice,age:22,size:180
27+
id:24,name:clara,age:18,size:185
28+
id:25,name:maurice,age:15,size:190
29+
id:26,name:johny,age:17,size:195
30+
id:27,name:brigitte,age:18,size:175
31+
id:28,name:eva,age:18,size:170
32+
id:29,name:sophia,age:21,size:80
33+
id:30,name:aurore,age:22,size:190
34+
id:31,name:david,age:19,size:195
35+
id:32,name:damien,age:19,size:185
36+
id:33,name:jason,age:17,size:180
37+
id:34,name:malena,age:24,size:170
38+
id:35,name:morgan,age:75,size:75
39+
id:36,name:alina,age:15,size:160
40+
id:37,name:pierre,age:18,size:190
41+
id:38,name:yan,age:22,size:180
42+
id:39,name:ryan,age:23,size:165
43+
id:40,name:thomas,age:22,size:185
44+
id:41,name:alain,age:15,size:175
45+
id:42,name:ariana,age:21,size:165
46+
id:43,name:ayana,age:20,size:170
47+
id:44,name:arwen,age:20,size:175
48+
id:45,name:daniel,age:17,size:190
49+
id:46,name:joseph,age:18,size:180
50+
id:47,name:charlie,age:19,size:180
51+
id:48,name:ariel,age:24,size:190
52+
id:49,name:georges,age:18,size:170
53+
id:50,name:ariana,age:21,size:175
54+
id:51,name:leonard,age:26,size:165
55+
id:52,name:melissa,age:22,size:180
56+
id:53,name:amine,age:17,size:170
57+
id:54,name:coraline,age:18,size:65
58+
id:55,name:erika,age:15,size:175
59+
id:56,name:eva,age:18,size:185
60+
id:57,name:clara,age:20,size:160
61+
id:58,name:clara,age:20,size:175
62+
id:59,name:melissa,age:21,size:165
63+
id:60,name:mathieu,age:15,size:65
64+
id:61,name:alain,age:15,size:190
65+
id:62,name:morgan,age:17,size:180
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-age+name+sex+surname
2+
int,string,string,string
3+
7
4+
id:1,name:maria,surname:aa,age:1,sex:male
5+
id:2,name:jason,surname:tt,age:12,sex:male
6+
id:3,name:jason,surname:pp,age:14,sex:male
7+
id:4,name:hugo,surname:dd,age:9,sex:female
8+
id:5,name:amit,surname:rr,age:2,sex:female
9+
id:6,name:maria,surname:tt,age:21,sex:male
10+
id:7,name:maria,surname:zz,age:21,sex:female
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2
2+
1
3+
3
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1
2+
3
3+
5
4+
6
5+
2
6+
4

0 commit comments

Comments
 (0)