1# -*- perl -*-
2
3use Set::Object;
4
5require './t/object/Person.pm';
6package Person;
7use Test::More tests => 18;
8
9populate();
10
11$simpsons = Set::Object->new;
12
13is($simpsons->size(), 0, "Set::Object->size() [ no contents ]");
14
15$added = $simpsons->insert($homer);
16is($added, 1, "Set::Object->insert() [ returned # added ]");
17is($simpsons->size(), 1, "Set::Object->size() [ one member ]");
18
19$added = $simpsons->insert($homer);
20is($added, 0, "Set::Object->insert() [ returned # added ]");
21is($simpsons->size(), 1, "Set::Object->size() [ one member ]");
22
23$added = $simpsons->insert($marge);
24is($added, 1, "Set::Object->insert() [ returned # added ]");
25is($simpsons->size(), 2, "Set::Object->size() [ two members ]");
26
27$simpsons->insert($maggie, $homer, $bart, $marge, $bart, $lisa, $lisa, $maggie);
28is($simpsons->size(), 5, "Set::Object->size() [ lots of inserts ]");
29
30# Now be really abusive
31#eval { $simpsons->insert("bogon") };
32#like($@, qr/Tried to insert/i, "Caught feeding in a bogon OK");
33#
34
35my $test = new Set::Object;
36eval { $test->insert("bogon"); };
37is ( $test."", "Set::Object(bogon)", "as_string on bogon-ified set");
38
39eval { $simpsons->remove("bogon"); };
40
41# array refs
42my $array;
43$test->insert($array = [ "array", "ref" ]);
44my $array2 = [ "array", "ref" ];
45
46$test->insert($array);
47is ($test->size(), 2, "Inserted an array OK");
48ok ($test->includes($array), "Can put non-objects in a set");
49ok ($test->includes("bogon"), "Can put scalars in a set");
50ok (!$test->includes($array2), "Lookup of identical item doesn't work");
51
52like ( $test."", qr/Set::Object\(ARRAY/, "Inserted an array OK");
53
54# hash refs
55$test->clear();
56my $hash;
57$test->insert($hash = { "hash" => "ref" });
58my $hash2 = { "hash" => "ref" };
59
60$test->insert($hash);
61is ($test->size(), 1, "Inserted an hash OK");
62ok ($test->includes($hash), "Can put non-objects in a set");
63ok (!$test->includes($hash2), "Lookup of identical item doesn't work");
64
65like ( $test."", qr/Set::Object\(HASH/, "Inserted an array OK");
66
67