forked from vdugeri/UrbanDictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
81 lines (64 loc) · 1.9 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Created by PhpStorm.
* User: andela
* Date: 9/17/15
* Time: 11:03 AM
*/
include("src/Dictionary.php");
include("src/DictionaryManager.php");
include("src/RankWords.php");
include("src/IndexNotFoundException.php");
use Verem\Dictionary\DictionaryManager;
use Verem\Dictionary\RankWords;
use Verem\Dictionary\Dictionary;
class TestDictionary
{
private $dictionaryManager;
private $rank;
public function __construct(DictionaryManager $manager, RankWords $rank)
{
$this->dictionaryManager = $manager;
$this->rank = $rank;
}
public function run()
{
//populate dictionary
Dictionary::populateDictionary();
//get the populated dictionary
print "Populating the dictionary <br/>";
$dictionary = Dictionary::getDictionary();
var_export($dictionary);
print "<br/>";
//create a word
print "Creating a word<br/>";
$word = $this->dictionaryManager->createEntry('Excitement', 'A state of agitation or happiness', 'He was very excited at the thought of dinner with the Whites this night.');
var_export($word);
print "<br/>";
//find a word
print "Finding a word<br/>";
$foundWord = $this->dictionaryManager->findEntry('Excitement');
var_export($foundWord);
print "<br/>";
//edit a word
print "Editing a word<br/>";
$edited = $this->dictionaryManager->editEntry("Excitement", "Extreme happiness","He wasn't very excited this morning. this.");
var_export($edited);
print "<br/>";
//rank word
print "Ranking words<br/>";
try{
$ranked = $this->rank->rankWords($this->dictionaryManager->findEntry('Excitement'));
var_export($ranked);
print "<br/>";
} catch (InvalidArgumentException $e){
echo $e->getMessage() ."<br/>";
}
//delete a word
print "Deleting a word<br/>";
$dictionary = $this->dictionaryManager->deleteEntry('Excitement');
var_export($dictionary);
}
}
$test = new TestDictionary(new DictionaryManager(), new RankWords());
$test->run();