https://github.com/quickshiftin/php-test-taker
Run tests on your local machine for sites like HackerRank and Codility
https://github.com/quickshiftin/php-test-taker
Last synced: about 2 months ago
JSON representation
Run tests on your local machine for sites like HackerRank and Codility
- Host: GitHub
- URL: https://github.com/quickshiftin/php-test-taker
- Owner: quickshiftin
- License: mit
- Created: 2016-11-17T15:52:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-17T16:25:06.000Z (over 8 years ago)
- Last Synced: 2025-02-15T06:16:53.268Z (4 months ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP Test Taker
--------------
Write and test your solutions locally with you favorite editory and debugger.Currently supports [HackerRank](https://www.hackerrank.com) and [Codility](https://codility.com/programmers/).
How to use it?
--------------* Clone the repo
* Create a directory for a test
* Create a config file for the test
* Write solutions
* Test, Refine, Paste your solutionConfig Files
------------Config files define what platform the test is on and test cases.
* `type` - One of the supported test types, currently HackerRank or Codility
* `name` - A name to identify the test
* `cases` - One or more test casesTest cases allow you to provide input for the test and expectations for the input. Both input and expectations can be arrays indicating there are multiple inputs or outputs for the algorithm.
```php
'HackerRank',
'name' => 'Steady Gene',
'cases' => [
['t' => [4, 'GATC'], 'e' => '0'],
['t' => [8, 'GATCGATC'], 'e' => 0],
['t' => [8, 'AGACAGTT'], 'e' => 1],
]];
```Test Scripts
------------
php-test-taker abstracts the differences between platforms, however your tests will need to be platform specific. The idea is you paste your solution right into the site you're working on.Codility Example - Practice test
```php
$v) {
if(!isset($aRightHist[$k]) || $aRightHist[$k] != $v) {
$bMatch = false;
}
}
if($bMatch) {
$iAnagramPairs++;
}
}
}
}
}
}
echo "$iAnagramPairs\n";
}
```Writing and Running Tests
-------------------------When you clone the project, you will see a *tests* directory, this is where you put test files. You can organize tests however you wish. What I do is create a directory for each test, then put the config and solutions for the test in that directory. Here's what my tests directory looks like
tests/steady-gene
tests/steady-gene/solution1.php
tests/steady-gene/solution2.php
tests/steady-gene/solution3.php
tests/steady-gene/config.php
tests/practice
tests/practice/solution1.php
tests/practice/solution2.php
tests/practice/config.phpYou might want another subdirectory for each site like tests/hacker-rank/steady-gene etc.
To run a test use the `run-test` script, passing it the path to a test config and solution.
`./run-test tests/sherlock-and-anagrams/config.php tests/sherlock-and-anagrams/solution1.php`
```
================================================================================
Running HackerRank Sherlock and Anagrams Test
================================================================================Testing case: (2, abba, abcd)
OK: Ran in 17.05Testing case: (5, ifailuhkqq, hucpoltgty, ovarjsnrbf, pvmupwjjjf, iwwhrlkpek)
OK: Ran in 29.13********************************************************************************
YOU PASSED THE TEST
********************************************************************************
```