Skip to content
This repository was archived by the owner on Dec 12, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions solutions/php/reverse-words-in-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

function reverseWordsInStrings($string)
{
return implode(array_reverse(preg_split('/\s+/', $string)), ' ');
return trim(implode(array_reverse(preg_split('/\s+/', $string)), ' '));
}

?>
15 changes: 7 additions & 8 deletions solutions/php/sum-of-array-plus-one.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

function SumOfIntegers ($integerArray) {
$sum = 0;
foreach ($integerArray as $valor) {
$sum += $valor;
}
return $sum + count($integerArray);
function SumOfArrayPlusOne($integerArray)
{
$sum = 0;
foreach ($integerArray as $valor) {
$sum += $valor;
}
return $sum + count($integerArray);
}

?>
15 changes: 7 additions & 8 deletions tests/php/factorialTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?php
use PHPUnit\Framework\TestCase;

require_once 'solutions/php/factorial.php';
require_once 'solutions/php/factorial.php';

class StackTest extends TestCase
class FactorialTest extends TestCase
{
public function test_factorial()
{
$this->assertEquals(1,factorial(1) );
$this->assertEquals(2,factorial(2) );
$this->assertEquals(6,factorial(3) );
$this->assertEquals(120,factorial(5) );
$this->assertEquals(2432902008176640000,factorial(20) );
$this->assertEquals(1, factorial(1));
$this->assertEquals(2, factorial(2));
$this->assertEquals(6, factorial(3));
$this->assertEquals(120, factorial(5));
$this->assertEquals(2432902008176640000, factorial(20));
}
}
?>
16 changes: 16 additions & 0 deletions tests/php/reverseWordsInStringTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
use PHPUnit\Framework\TestCase;

require_once 'solutions/php/reverse-words-in-string.php';

class reverseWordsInStringsTest extends TestCase
{
public function test_reverseWordsInStrings()
{
$this->assertEquals("awesome! are Interviews", reverseWordsInStrings("Interviews are awesome!"));
$this->assertEquals("degree CS", reverseWordsInStrings(" CS degree"));
$this->assertEquals("degree CS", reverseWordsInStrings("CS degree"));
$this->assertEquals("degree CS", reverseWordsInStrings("CS degree "));
$this->assertEquals("degree CS", reverseWordsInStrings(" CS degree "));
}
}
13 changes: 13 additions & 0 deletions tests/php/sumOfArrayPlusOneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
use PHPUnit\Framework\TestCase;

require_once 'solutions/php/sum-of-array-plus-one.php';

class sumOfArrayPlusOneTest extends TestCase
{
public function test_SumOfArrayPlusOne()
{
$this->assertEquals(14, SumOfArrayPlusOne([1, 2, 3, 4]));

}
}