Skip to content

Commit fcafd35

Browse files
committed
Adding tests for "Gravity centrifuge".
1 parent 1badf41 commit fcafd35

25 files changed

+558
-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 "Maximum sub-sequence".
3434
- Tests for "Snake encoding".
3535
- Tests for "Binary search tree traversal".
36+
- Tests for "Gravity centrifuge".
3637

3738
## [3.13.0] - 2022-09-30
3839
### 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\GravityCentrifuge;
6+
7+
use CyrilVerloop\Codingame\Puzzle;
8+
9+
/**
10+
* The "Gravity centrifuge" puzzle.
11+
* @link https://www.codingame.com/ide/puzzle/gravity-centrifuge
12+
*/
13+
class GravityCentrifuge implements Puzzle
14+
{
15+
public function execute($stdin): void
16+
{
17+
fscanf($stdin, "%d %d", $width, $height);
18+
$bitstream = stream_get_line($stdin, 10000 + 1, "\n");
19+
for ($i = 0; $i < $height; $i++)
20+
{
21+
$raster = stream_get_line($stdin, $width + 1, "\n");
22+
}
23+
24+
// Write an answer using echo(). DON'T FORGET THE TRAILING \n
25+
26+
echo("...\n");
27+
echo("write ###\n");
28+
}
29+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CyrilVerloop\Codingame\Tests\Community\Training\Medium\GravityCentrifuge;
6+
7+
use CyrilVerloop\Codingame\Tests\PuzzleTest;
8+
use CyrilVerloop\Codingame\Community\Training\Medium\GravityCentrifuge\GravityCentrifuge;
9+
10+
/**
11+
* Tests for the "Gravity centrifuge" puzzle.
12+
*
13+
* @covers \CyrilVerloop\Codingame\Community\Training\Medium\GravityCentrifuge\GravityCentrifuge
14+
* @group gravityCentrifuge
15+
* @medium
16+
*/
17+
final class CGTest extends PuzzleTest
18+
{
19+
public function setUp(): void
20+
{
21+
$this->puzzle = new GravityCentrifuge();
22+
}
23+
24+
/**
25+
* Test that the code can be executed for "Tumble".
26+
*
27+
* @group gravityCentrifugeTuning_tumble
28+
*/
29+
public function testCanExecuteTumble(): void
30+
{
31+
$this->expectExecuteOutputAnswer(
32+
__DIR__ . '/input/01 - tumble.txt',
33+
file_get_contents(__DIR__ . '/output/01 - tumble.txt')
34+
);
35+
}
36+
37+
/**
38+
* Test that the code can be executed for "Double tumble".
39+
*
40+
* @group gravityCentrifugeTuning_doubleTumble
41+
*/
42+
public function testCanExecuteDoubleTumble(): void
43+
{
44+
$this->expectExecuteOutputAnswer(
45+
__DIR__ . '/input/02 - double tumble.txt',
46+
file_get_contents(__DIR__ . '/output/02 - double tumble.txt')
47+
);
48+
}
49+
50+
/**
51+
* Test that the code can be executed for "Triple tumble".
52+
*
53+
* @group gravityCentrifugeTuning_tripleTumble
54+
*/
55+
public function testCanExecuteTripleTumble(): void
56+
{
57+
$this->expectExecuteOutputAnswer(
58+
__DIR__ . '/input/03 - triple tumble.txt',
59+
file_get_contents(__DIR__ . '/output/03 - triple tumble.txt')
60+
);
61+
}
62+
63+
/**
64+
* Test that the code can be executed for "Octal, remember?".
65+
*
66+
* @group gravityCentrifugeTuning_octalRemember
67+
*/
68+
public function testCanExecuteOctalRemember(): void
69+
{
70+
$this->expectExecuteOutputAnswer(
71+
__DIR__ . '/input/04 - octal, remember?.txt',
72+
file_get_contents(__DIR__ . '/output/04 - octal, remember?.txt')
73+
);
74+
}
75+
76+
/**
77+
* Test that the code can be executed for "Dead beef!".
78+
*
79+
* @group gravityCentrifugeTuning_deadBeef
80+
*/
81+
public function testCanExecuteDeadBeef(): void
82+
{
83+
$this->expectExecuteOutputAnswer(
84+
__DIR__ . '/input/05 - dead beef!.txt',
85+
file_get_contents(__DIR__ . '/output/05 - dead beef!.txt')
86+
);
87+
}
88+
89+
/**
90+
* Test that the code can be executed for "Wait, what?".
91+
*
92+
* @group gravityCentrifugeTuning_waitWhat
93+
*/
94+
public function testCanExecuteWaitWhat(): void
95+
{
96+
$this->expectExecuteOutputAnswer(
97+
__DIR__ . '/input/06 - wait, what?.txt',
98+
file_get_contents(__DIR__ . '/output/06 - wait, what?.txt')
99+
);
100+
}
101+
102+
/**
103+
* Test that the code can be executed for "Leonardo would be proud of you!".
104+
*
105+
* @group gravityCentrifugeTuning_leonardoWouldBeProudOfYou
106+
*/
107+
public function testCanExecuteLeonardoWouldBeProudOfYou(): void
108+
{
109+
$this->expectExecuteOutputAnswer(
110+
__DIR__ . '/input/07 - leonardo would be proud of you!.txt',
111+
file_get_contents(__DIR__ . '/output/07 - leonardo would be proud of you!.txt')
112+
);
113+
}
114+
115+
/**
116+
* Test that the code can be executed for "Randomize this! 1".
117+
*
118+
* @group gravityCentrifugeTuning_randomizeThis1
119+
*/
120+
public function testCanExecuteRandomizeThis1(): void
121+
{
122+
$this->expectExecuteOutputAnswer(
123+
__DIR__ . '/input/08 - randomize this! 1.txt',
124+
file_get_contents(__DIR__ . '/output/08 - randomize this! 1.txt')
125+
);
126+
}
127+
128+
/**
129+
* Test that the code can be executed for "Randomize this! 2".
130+
*
131+
* @group gravityCentrifugeTuning_randomizeThis2
132+
*/
133+
public function testCanExecuteRandomizeThis2(): void
134+
{
135+
$this->expectExecuteOutputAnswer(
136+
__DIR__ . '/input/09 - randomize this! 2.txt',
137+
file_get_contents(__DIR__ . '/output/09 - randomize this! 2.txt')
138+
);
139+
}
140+
141+
/**
142+
* Test that the code can be executed for "Randomize this! 3".
143+
*
144+
* @group gravityCentrifugeTuning_randomizeThis3
145+
*/
146+
public function testCanExecuteRandomizeThis3(): void
147+
{
148+
$this->expectExecuteOutputAnswer(
149+
__DIR__ . '/input/10 - randomize this! 3.txt',
150+
file_get_contents(__DIR__ . '/output/10 - randomize this! 3.txt')
151+
);
152+
}
153+
154+
/**
155+
* Test that the code can be executed for "Binary overflow".
156+
*
157+
* @group gravityCentrifugeTuning_binaryOverflow
158+
*/
159+
public function testCanExecuteBinaryOverflow(): void
160+
{
161+
$this->expectExecuteOutputAnswer(
162+
__DIR__ . '/input/11 - binary overflow.txt',
163+
file_get_contents(__DIR__ . '/output/11 - binary overflow.txt')
164+
);
165+
}
166+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
17 5
2+
1
3+
.................
4+
.................
5+
...##...###..#...
6+
.####..#####.###.
7+
#################
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
17 5
2+
2
3+
.................
4+
.................
5+
...##...###..#...
6+
.####..#####.###.
7+
#################
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
17 5
2+
3
3+
.................
4+
.................
5+
...##...###..#...
6+
.####..#####.###.
7+
#################
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
53 5
2+
21
3+
#.....#...#.#.......#...#...#.#.....#...#.#...#.#....
4+
#.....#...#.#.......#...#...#.#..#..#...#.#...#.#....
5+
#.....#...#.#...#...#...#...#.#.##..#...#.#...#.###..
6+
#####.#####.#####.#####.#...#.#####.#####.#...#.#####
7+
#####.#####.#####.#####.#####.#####.#####.#####.#####
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
17 5
2+
33653337357
3+
.................
4+
.................
5+
...##...###..#...
6+
.####..#####.###.
7+
#################
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
30 30
2+
0
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+
##############################
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
53 5
2+
036552005474503316045244671230763257003205014454317576646651415104774736246223373530313543560352164675733542160416774256562757577303267565012230756331362352034623360206073524577272542727226442237112601327613774057747725750341340753703545317067320271760727065756551547627517027756041053372433206524506305322662235721143776644653261365351545655002362143663425275352313534465104446036610600643036025772116355212061200241173664361043257311542104115720766553324425510464301637020654061515334351050457145403553442710724323272370165061645576562621353341046006465300722065367354371476040217304462317524626601116071471704311723534624446517016162546173154627355536105332145302452666667052741627742567041144634255113226074163450446340730577023251132562517764132661643634561101441605234725545672745147604047344107476323035165312334227520113715470352043224655552333531070060723733560137766353333476227620573710253513265475317654630057735435711244616721716003013704331332524464463622072302160525633656622276147130635210036151214373652774273660761320071053620621133557625334726662556436641742653246703131246066013553507376333015270160553757012763260125267743524524636030372645535203666750146610307147510144326347611134441256264766060726753173071641152023702530047241137740756725637666606025473241622520615527123673042600110346506536722372313355225463517175657475547503115103401362664075702426242144651613520651506777122360441166024773013444547461651724534302031343001147716263700252434406137523477300047534766512053651416524721362034205354172626744241146174301440216722041206622536315466023562476472430030006430603117002270204432726026454520035276670450431423020741205736652401724750355312225133510031717076564744555057350261100720427166027015615375177604577601164757003403444352471033655143723650320252674114315570223754537624102150012732443540551117225757056221102550141204076031570772177453344431514243705133567727310524640054624235456547520216717561536731021652540536375230055371650406261061745601110745003265216067544444550112227770343064763221111673171606516155512047663603130016501071257373376402305013340130367622760227271407353523022000701475236314772534000346752201356232615163574234002630675714211336714702060516663206015110067475047513142646330257055000277455200325061130657337316317554376162466055136155274054476145533163236466107467336747076613717223002745577657411627407725276747074567060763043646607724505664204427301661240615063577147445710213104031553504657301763373331262703553741317134271442306507670012276121100274304637243725253513214504246357470101416140032612206630415515123255662054100130013566517065461265407541006505531506707750631246524223542615004553564176641330356441502623631557520643635125022232750152112551576134720555414646530356414333546343723476573247167126166434111020045433364714613466022126163200737703664610034454501242354610660337744704732722736550631174224525627522620712231533253256744620435613663510675530565660636054015747727625204411141040701232260266324521361202704763406601210112636215103441353253031446312064451667417607145634430554561724211275363376756226272721514200415627737551614517560665643277776441366327407654272157735001157106744167475466657043537136066555562660774237250201512633010775404740262123501065250127473765550533045555740006355107070740045574766254354421774141716702051007035611103530567512220545040074203422355563562122577015565733135641377544727131474400533003316156434711750132507255503150625067041703333055757674071757660225173744650453543114705213253542074342640374204637310673460330374535070164174431727624324516252171644520355540417022403570353471127310176532661233043322177303137126101321532156631432760650705762422032636077130264643442716315175643750152013210665523346471047174003565736167173371504066137551633654255346563154367172465053317211533211545567276724767710047310503416674564751067127275053616001711644073225554250206115422671666204650143500277735400617472506327254661072236765413611213102743733715031404722155440022612574343350047603560515262276270437362305254516652017432742517671260073527064473216267173565511412605463176710343364471056641717311545145157037623411453260366064640633676714025772154736533152426253026771221625361631603466760444357706447144056565217225215450341432533136543670514756662324251711533713203013363740726411556072045307041021542331316160313436115016512506621713730672650273727213217135716064667326256170515764303344077024012231023100566264445374176356265152321170114463602432641517057661415512556046557411537512765577526554132654375524406675222306352325415150514321275503101277135423312150026713511432175572430001266173720271556443341134021562304331755716335451000227463526604422624033677623422124007637116336172346302205435713652021444620603066132311211054752010670235114733377751170700274114400654647567701714707160077141614437337570145366005401763532706420555772112544230356263715766037202021002643271675641424227607222405551224615156147513130716523306671341016352574273642202646071143443503662163165315200612501550461711373445675667361401725575065104535667412115722276340725623405060104117211372271057471721043201614773666744607020015421531071560203234776074501361400361036463660662172147607201462303020711563147517061631071433300531245210103132642112314104716321737773412725670634132565723076315625743207317065572360542674020662317753611274027557261442604770042022341653525077652026110217527243752317571526455306130443142353531513446665030046013635713616742556514345607516252623010131772346406366505126555326320212747764025322210676352724531633661116256736431565514640072033461166331506406605200032063427073710133213437677044347124443752127460654365072270512314644757023650423774066311014735413255226066763535651741611770210151171270060512554461207412630206256717660223510651517372532615134643170764260370235357774757573625415441043422752776341467403610127372203663757576775441443566432516175237464134072201251141230027735555324732012253710400025576773022016134705512211346056662746225563321404530402723321124045454312446263064450702057710703763043601001356234030540342630445420461773475524455605427050407265155516715556037444722011633634442275554137170577305721625614665603434474465320673700052405440701241565333651100636357214244313760164021241541233264624453147021032637237454505071025205217304415672345117273737325073356224235034334373637025551213237331243302674176164247005177532340650401543045310554471312127460651542701745223555723643105510077643071753755420141676317615775750550770033314550215361305523571016125357651712564130772652366126651176765517522004275757676565564326142350011376521354472337400530535214654230430750303412633206544517042411414222233312560342544143313617623656515625777303472342060410751325633262252342423762756136562576237067647104044637007332055516007564156702776157355477432746314101102032767722131574757066157527046375674164116442307204202123326203403404477544411377450443317347541563660021053764221624253735547447652131352660676541753355451656654434570473347144524244661112127760723132020556005470657210250376676565512043573473142306241742224140621226415551145214253714536030156055350051601423062607236571245027432451146455371744235007712343121447035023507726157776500115707370050512271211474506632657305457307260523306307532362255124760346246115457600531231617673671111660040056002157556064326634303602763564545135022074537704601333324577554306555741415152264210116206255411642213164671635574111431454655203255420570570401754561535777444447160634220256601514030111010332441145100046247102003124702146455151532550246173024117247675073664640561560112445705064766021103124575715030441672614451710520027746057147602150327130700214046032615516170043123270112330421604647642473251543656725677662542022146605214515035221063751253300443650701106165631531771353022417624147554746450337773647607170432421365324016552576457447427737200345443303241445120066000405343005750726204232120410154143514765050044127574147533527415004501305321565420562170763313272363544044437606410541246123666641377436413747557274733654517007643561431451250405211033245012010507167200326541235640037322213751413752601272665743755174400517223746457665436715256216307050360530074664660606322705153533411451246330225541722126316456424706732263061457553733554440234132542547166446724245016650501760170536035736617263400716451211050160635052747314207144515772265351243570574027165160747656022365422446632756473162201467075025315663654510224326246752677640375277376726607441043637300411767076626310777756161514275514523154111503662653302110533154356373043377156341613735747730412616062725553502526712132724723753753143366045741727237404756342727013443552157703435145333766605240573252050433447577505661740304645424306763646572305637227012332362467447410232022105305611045345353431027615702020672124020736646311231656357345746065245011606315437124322275207057021546436415132612607601003705252023306726704215672021007201664150171140164742342755651652566555063307255543051067027205070437614001524531003376645163563760643603025401640721110300154533004202433433427621513574040714611633457373001235350274541311655545706350536617772677664037136233560672147506360717265300303260474417416266443037501273073323766607203245661276055137716051622705400676534374735123563015156070416607020520017600176101514725260645242004153622442116205027174444425675466754123053633270332737527415407474220712276170432411705560512731425145361555326421567477464714443567164175714401756005415634032516254202746210262706345246366703264575400176467523315213467757653172244353441013646644504100744115672072605364346725552014561715306621162717262431700726071761311444216160650651310265560607231472567062602747264636370142025230671361254246023160126570417064746
3+
#.....#...#.#.......#...#...#.#.....#...#.#...#.#....
4+
#.....#...#.#.......#...#...#.#..#..#...#.#...#.#....
5+
#.....#...#.#...#...#...#...#.#.##..#...#.#...#.###..
6+
#####.#####.#####.#####.#...#.#####.#####.#...#.#####
7+
#####.#####.#####.#####.#####.#####.#####.#####.#####

0 commit comments

Comments
 (0)