-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDictionaryTest.php
81 lines (69 loc) · 2.19 KB
/
DictionaryTest.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
<?php
require_once dirname(dirname(__FILE__)) . "/src/Ginq/Core/Dictionary.php";
require_once dirname(dirname(__FILE__)) . "/src/Ginq/Core/EqualityComparer.php";
use \Ginq\Core\Dictionary;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\TestSuite;
use PHPUnit\TextUI\TestRunner;
class DictionaryTest extends TestCase
{
/**
* Runs the test methods of this class.
*
* @access public
* @static
*/
public static function main()
{
$suite = new TestSuite("DictionaryTest");
$result = TestRunner::run($suite);
}
public function testScalarKeys()
{
$dict = new Dictionary();
$dict->put(1, "1:int");
$dict->put("1", "one:string");
$dict->put(2, "2:int");
$dict->put(null, "null:null");
$dict->put(0, "0:int");
$this->assertEquals("1:int", $dict->get(1));
$this->assertEquals("one:string", $dict->get("1"));
$this->assertEquals("2:int", $dict->get(2));
$this->assertEquals("null:null", $dict->get(null));
$this->assertEquals("0:int", $dict->get(0));
}
public function testObjectKeys()
{
$josephine = new Rabbit("Josephine");
$flopsy = new Rabbit("Flopsy");
$mopsy = new Rabbit("Mopsy");
$cottontail = new Rabbit("Cotton-tail");
$josephine->addChild($flopsy);
$josephine->addChild($mopsy);
$josephine->addChild($cottontail);
$dict = new Dictionary();
$dict->put($josephine, "josephine");
$dict->put($flopsy, "flopsy");
$dict->put($mopsy, "mopsy");
$dict->put($cottontail,"cottontail");
$this->assertEquals("josephine", $dict->get($josephine));
$this->assertEquals("flopsy", $dict->get($flopsy));
$this->assertEquals("mopsy", $dict->get($mopsy));
$this->assertEquals("cottontail", $dict->get($cottontail));
}
}
class Rabbit
{
public $mother;
public $children;
public function __construct($name)
{
$this->name = $name;
$this->children = array();
}
public function addChild($child)
{
$this->children[] = $child;
$child->mother = $this;
}
}