Example #1
0
 public function testReset()
 {
     $string = 'this this is a simple test';
     $this->object->addToSample($string);
     $this->object->addToSample($string);
     $this->object->reset();
     $this->assertEquals(array(), $this->object->getWordCounts());
 }
 /** @test */
 function shouldReturnCountOfWords()
 {
     $file = "testfile.tmp";
     file_put_contents($file, "Keep the bar green to keep the code clean.");
     $counter = WordCounter::fromFile($file);
     //$this->assertEquals(9, $counter->numberOfWords());
     unlink($file);
 }
Example #3
0
<?php

class WordCounter
{
    const ASC = 1;
    const DESC = 2;
    private $words;
    function __construct($filename)
    {
        $file_content = file_get_contents($filename);
        $this->words = array_count_values(str_word_count(strtolower($file_content), 1));
    }
    public function count($order)
    {
        if ($order == self::ASC) {
            asort($this->words);
        } else {
            if ($order == self::DESC) {
                arsort($this->words);
            }
        }
        foreach ($this->words as $key->{$val}) {
            echo $key . " = " . $val . "<br/>";
        }
    }
}
$wc = new WordCounter("words.txt");
$wc->count(WordCounter::DESC);
 /**
  * @ test
  */
 function shouldCountUniqueWordsCaseInsensitive()
 {
     $counter = new WordCounter("green bar Green hat");
     // TODO mark test incomplete with "work in progress, will continue tomorrow"
     $this->assertEquals(["bar", "green", "hat"], $counter->uniqueWords());
 }
 /**
  * @ test
  * TODO take data from tableData method
  */
 function shouldReturnRatioOfGivenWord($sentence, $word, $expectedRratio)
 {
     $counter = new WordCounter($sentence);
     $this->assertEquals($expectedRratio, $counter->ratioOf($word), '', 0.01);
 }
Example #6
0
include_once 'class.dbmanager.php';
include_once 'class.statictester.php';
include_once 'class.student.php';
include_once 'class.overloader.php';
/*----------  Extended Emailer  ----------*/
$emailerobject = new ExtendedEmailer();
$emailerobject->setSender('*****@*****.**');
$emailerobject->addRecipients('*****@*****.**');
$emailerobject->setSubject('Just a Test');
$emailerobject->setBody('Content of Email');
$emailerobject->sendEmail();
/*----------  Factorial  ----------*/
$factorial = new Factorial(5);
$factorial->showResult();
/*----------  WordCounter  ----------*/
$count = new WordCounter('words.txt');
$count->count(WordCounter::ASC);
/*----------  HTML Emailer  ----------*/
$newemailerobject = new HtmlEmailer('wdarking');
$newemailerobject->addRecipients('*****@*****.**');
$newemailerobject->setSubject('*****@*****.**');
$newemailerobject->setBody('Hi there :D');
$newemailerobject->sendEmail();
$newemailerobject->sendHtmlEmail();
/*----------  DBDriver  ----------*/
$dbdriver = DBManager::getMySQLDriver();
/*----------  Static Tester  ----------*/
$tester = new StaticTester();
print "<br>";
StaticTester::checkIdFromStaticMethod();
print "<br>";