File: insert.t

package info (click to toggle)
libset-object-perl 1.42-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 620 kB
  • sloc: perl: 1,069; makefile: 14
file content (66 lines) | stat: -rw-r--r-- 1,979 bytes parent folder | download | duplicates (3)
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
# -*- perl -*-

use Set::Object;

require './t/object/Person.pm';
package Person;
use Test::More tests => 18;

populate();

$simpsons = Set::Object->new;

is($simpsons->size(), 0, "Set::Object->size() [ no contents ]");

$added = $simpsons->insert($homer);
is($added, 1, "Set::Object->insert() [ returned # added ]");
is($simpsons->size(), 1, "Set::Object->size() [ one member ]");

$added = $simpsons->insert($homer);
is($added, 0, "Set::Object->insert() [ returned # added ]");
is($simpsons->size(), 1, "Set::Object->size() [ one member ]");

$added = $simpsons->insert($marge);
is($added, 1, "Set::Object->insert() [ returned # added ]");
is($simpsons->size(), 2, "Set::Object->size() [ two members ]");

$simpsons->insert($maggie, $homer, $bart, $marge, $bart, $lisa, $lisa, $maggie);
is($simpsons->size(), 5, "Set::Object->size() [ lots of inserts ]");

# Now be really abusive
#eval { $simpsons->insert("bogon") };
#like($@, qr/Tried to insert/i, "Caught feeding in a bogon OK");
#

my $test = new Set::Object;
eval { $test->insert("bogon"); };
is ( $test."", "Set::Object(bogon)", "as_string on bogon-ified set");

eval { $simpsons->remove("bogon"); };

# array refs
my $array;
$test->insert($array = [ "array", "ref" ]);
my $array2 = [ "array", "ref" ];

$test->insert($array);
is ($test->size(), 2, "Inserted an array OK");
ok ($test->includes($array), "Can put non-objects in a set");
ok ($test->includes("bogon"), "Can put scalars in a set");
ok (!$test->includes($array2), "Lookup of identical item doesn't work");

like ( $test."", qr/Set::Object\(ARRAY/, "Inserted an array OK");

# hash refs
$test->clear();
my $hash;
$test->insert($hash = { "hash" => "ref" });
my $hash2 = { "hash" => "ref" };

$test->insert($hash);
is ($test->size(), 1, "Inserted an hash OK");
ok ($test->includes($hash), "Can put non-objects in a set");
ok (!$test->includes($hash2), "Lookup of identical item doesn't work");

like ( $test."", qr/Set::Object\(HASH/, "Inserted an array OK");