Skip to content

Commit

Permalink
Merge pull request #17 from ericksonreyes/string-functions
Browse files Browse the repository at this point in the history
String functions
  • Loading branch information
ericksonreyes committed May 16, 2019
2 parents 2745823 + 54cd1ae commit 25c61c5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,27 @@ public function it_knows_when_it_contains_a_string()
$this->doesNotContain($word)->shouldReturn(false);
$this->doesNotContain('Ginebra')->shouldReturn(true);
}

public function it_can_be_broken_down_into_words()
{
$words = explode(' ', $this->value);
$strings = [];

foreach ($words as $word) {
$strings[] = new StringValue($word);
}

$this->words()->shouldHaveCount(count($strings));

foreach ($this->words() as $wordObject) {
$wordObject->shouldHaveType(StringValue::class);
}
}

public function it_counts_the_number_of_words()
{
$words = explode(' ', $this->value);
$numberOfWords = count($words);
$this->numberOfWords()->shouldReturn($numberOfWords);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,28 @@ public function doesNotContain(string $keyword): bool
{
return $this->contains($keyword) === false;
}

/**
* @return array
*/
public function words(): array
{
$words = explode(' ', $this->value());
$strings = [];

foreach ($words as $word) {
$strings[] = new StringValue($word);
}

return $strings;
}

/**
* @return int
*/
public function numberOfWords(): int
{
$words = explode(' ', $this->value());
return count($words);
}
}

0 comments on commit 25c61c5

Please sign in to comment.