import Devel-Size 0.58 from CPAN
[p5sagit/Devel-Size.git] / t / basic.t
CommitLineData
e98cedbf 1# Before `make install' is performed this script should be runnable with
2# `make test'. After `make install' it should work as `perl test.pl'
3
4######################### We start with some black magic to print on failure.
5
6# Change 1..1 below to 1..last_test_to_print .
7# (It may become useful if the test is moved to ./t subdirectory.)
8
78dfb4e7 9BEGIN { $| = 1; print "1..7\n"; }
e98cedbf 10END {print "not ok 1\n" unless $loaded;}
b98fcdb9 11use Devel::Size qw(size total_size);
e98cedbf 12$loaded = 1;
13print "ok 1\n";
14
15######################### End of black magic.
16
17# Insert your test code below (better if it prints "ok 13"
18# (correspondingly "not ok 13") depending on the success of chunk 13
19# of the test code):
20
b98fcdb9 21
22my $x = "A string";
23my $y = "A longer string";
24if (size($x) < size($y)) {
25 print "ok 2\n";
26} else {
27 print "not ok 2\n";
28}
29
30if (total_size($x) < total_size($y)) {
31 print "ok 3\n";
32} else {
33 print "not ok 3\n";
34}
35
36my @x = (1..4);
37my @y = (1..10);
38
39if (size(\@x) < size(\@y)) {
40 print "ok 4\n";
41} else {
42 print "not ok 4\n";
43}
44
45if (total_size(\@x) < total_size(\@y)) {
46 print "ok 5\n";
47} else {
48 print "not ok 5\n";
49}
50
78dfb4e7 51# check that the tracking_hash is working
52
53my($a,$b) = (1,2);
54my @ary1 = (\$a, \$a);
55my @ary2 = (\$a, \$b);
56
57if (total_size(\@ary1) < total_size(\@ary2)) {
58 print "ok 6\n";
59} else {
60 print "not ok 6\n";
61}
62
63# check that circular references don't mess things up
64
65my($c1,$c2); $c2 = \$c1; $c1 = \$c2;
66
67if( total_size($c1) == total_size($c2) ) {
68 print "ok 7\n";
69} else {
70 print "not ok 7\n";
71}
72