Skip to content

Commit 455501e

Browse files
committed
Adding a time limit.
1 parent 384756b commit 455501e

File tree

6 files changed

+87
-9
lines changed

6 files changed

+87
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ 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]
8+
### Added
9+
- Time limit.
10+
711
## [3.2.0] - 2022-02-18
812
### Added
913
- Tests for "Container terminal".

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM php:7.3-cli-alpine
22
RUN apk update \
33
&& apk add gpg $PHPIZE_DEPS \
4-
&& docker-php-ext-install mbstring \
4+
&& docker-php-ext-install pcntl mbstring \
55
&& pecl install xdebug \
6-
&& docker-php-ext-enable mbstring xdebug \
6+
&& docker-php-ext-enable mbstring pcntl xdebug \
77
&& wget -O /usr/local/bin/phive https://phar.io/releases/phive.phar \
88
&& chmod +x /usr/local/bin/phive \
99
&& apk del --purge $PHPIZE_DEPS \

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ fscanf(STDIN, "%d", $N);
7474
```
7575

7676

77-
## Timed out
77+
## Time limit
7878

79-
Your code can work through this project and timed out on CodinGame.
80-
It means your solution is not optimum and you should find another algorithm.
79+
The maximum time allowed for a puzzle may differ from CodinGame.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": "7.3.*"
23+
"php": "7.3.*",
24+
"phpunit/php-invoker": "^3.1"
2425
}
2526
}

composer.lock

Lines changed: 66 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/PuzzleTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@
55
namespace CyrilVerloop\Codingame\Tests;
66

77
use PHPUnit\Framework\TestCase;
8+
use SebastianBergmann\Invoker\Invoker;
89

910
/**
1011
* Base class for testing puzzles.
1112
*/
1213
abstract class PuzzleTest extends TestCase
1314
{
15+
// Constants :
16+
17+
/**
18+
* @var int the time limit in seconds.
19+
*/
20+
const TIME_LIMIT = 6;
21+
22+
1423
// Properties :
1524

1625
/** @var \CyrilVerloop\Codingame\Puzzle the puzzle. */
@@ -30,6 +39,7 @@ protected function expectExecuteOutputAnswer(string $filename, string $expectedA
3039

3140
$this->expectOutputString($expectedAnswer);
3241

33-
$this->puzzle->execute($stdin);
42+
$invoker = new Invoker();
43+
$invoker->invoke([$this->puzzle, "execute"], [$stdin], self::TIME_LIMIT);
3444
}
3545
}

0 commit comments

Comments
 (0)