forked from OpenKore/openkore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActorListTest.pm
More file actions
102 lines (87 loc) · 2.65 KB
/
ActorListTest.pm
File metadata and controls
102 lines (87 loc) · 2.65 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package ActorListTest;
# TODO: write test for deepCopy()
use strict;
use Test::More;
use ActorList;
use Actor::Player;
use ObjectListTest;
use base qw(ObjectListTest);
sub start {
print "### Starting ActorListTest\n";
ActorListTest->new()->run();
}
#########################
my $count = 0;
sub run {
my ($self) = @_;
$self->SUPER::run();
$self->testGetAndRemoveByID();
}
# overloaded
sub init {
my ($self) = @_;
$self->{list} = new ActorList('Actor::Player');
for (my $i = 1; $i <= 6; $i++) {
$self->{"item$i"} = $self->createTestObject();
}
is($self->{list}->size(), 0);
$self->{list}->checkValidity();
}
# overloaded
sub createTestObject {
my $actor = new Actor::Player();
$count++;
$actor->{ID} = pack("V", $count);
return $actor;
}
# overloaded
sub testDuplicate {
# Do nothing; ActorList doesn't allow duplicates.
}
sub testGetAndRemoveByID {
my ($self) = @_;
$self->init();
my $list = $self->{list};
$list->add($self->{item1});
$list->add($self->{item2});
$list->add($self->{item3});
is($list->size(), 3);
ok($list->getByID($self->{item1}{ID}) == $self->{item1});
ok($list->getByID($self->{item2}{ID}) == $self->{item2});
ok($list->getByID($self->{item3}{ID}) == $self->{item3});
ok(!defined $list->getByID($self->{item4}{ID}));
ok(!defined $list->getByID($self->{item5}{ID}));
ok(!defined $list->getByID($self->{item6}{ID}));
$list->checkValidity();
my $result = $list->removeByID($self->{item2}{ID});
ok($result);
is($list->size(), 2);
ok($list->getByID($self->{item1}{ID}) == $self->{item1});
ok(!defined $list->getByID($self->{item2}{ID}));
ok($list->getByID($self->{item3}{ID}) == $self->{item3});
ok(!defined $list->getByID($self->{item4}{ID}));
ok(!defined $list->getByID($self->{item5}{ID}));
ok(!defined $list->getByID($self->{item6}{ID}));
$list->checkValidity();
my $result = $list->removeByID($self->{item2}{ID});
ok(!$result);
is($list->size(), 2);
ok($list->getByID($self->{item1}{ID}) == $self->{item1});
ok(!defined $list->getByID($self->{item2}{ID}));
ok($list->getByID($self->{item3}{ID}) == $self->{item3});
ok(!defined $list->getByID($self->{item4}{ID}));
ok(!defined $list->getByID($self->{item5}{ID}));
ok(!defined $list->getByID($self->{item6}{ID}));
$list->checkValidity();
my $result = $list->removeByID($self->{item4}{ID});
ok(!$result);
is($list->size(), 2);
ok($list->getByID($self->{item1}{ID}) == $self->{item1});
ok(!defined $list->getByID($self->{item2}{ID}));
ok($list->getByID($self->{item3}{ID}) == $self->{item3});
ok(!defined $list->getByID($self->{item4}{ID}));
ok(!defined $list->getByID($self->{item5}{ID}));
ok(!defined $list->getByID($self->{item6}{ID}));
$list->checkValidity();
}
1;