diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2234772 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor/ +composer.lock +.idea/ diff --git a/EquilibriumIndex.php b/EquilibriumIndex.php index 020dd2b..69d7302 100644 --- a/EquilibriumIndex.php +++ b/EquilibriumIndex.php @@ -1,9 +1,62 @@ assertEquals(array(3,6), getEquilibriums($arr)); - } -} diff --git a/README.md b/README.md index c88ac00..96908d6 100644 --- a/README.md +++ b/README.md @@ -10,5 +10,6 @@ Write a function that, given a sequence, returns its equilibrium indices (if any ## Running the Test ``` -phpunit EquilibriumIndexTest.php +composer install +vendor/phpunit/phpunit/phpunit ``` diff --git a/Test/EquilibriumIndexTest.php b/Test/EquilibriumIndexTest.php new file mode 100644 index 0000000..9c72beb --- /dev/null +++ b/Test/EquilibriumIndexTest.php @@ -0,0 +1,47 @@ +assertEquals([3,6], getEquilibriums($input)); + + // special case of empty array + $input = []; + $this->assertEquals([], getEquilibriums($input)); + + // special case of [0, N] solution + $input = [0, -3, -2, -1, 1, 2, 3, 0]; + $this->assertEquals([0, 7], getEquilibriums($input)); + + // special case of null element + $input = [1, 0, -1, null]; + $this->assertEquals([3], getEquilibriums($input)); + } + + /** + * @expectedException Exception + */ + public function testComputeEquilibriumExceptions() + { + // special case of array in an array + $input = [1, 0, -1, [8, 9]]; + getEquilibriums($input); + + // special case of an array with an object + $input = [1, 0, -1, new \StdClass]; + getEquilibriums($input); + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..092c746 --- /dev/null +++ b/composer.json @@ -0,0 +1,16 @@ +{ + "name": "jscodefix/codetest", + "description": "Fork of Booj PHP code test.", + "require": { + }, + "require-dev": { + "phpunit/phpunit": "^6.1" + }, + "authors": [ + { + "name": "Jeff Sheffel", + "email": "jeff@sheffel.org" + } + ], + "minimum-stability": "dev" +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..48663df --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,13 @@ + + + + + ./Test + + + + + ./vendor + + +