File: family-array.t

package info (click to toggle)
libtest-memory-cycle-perl 1.06-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 136 kB
  • sloc: perl: 420; makefile: 2
file content (93 lines) | stat: -rw-r--r-- 2,643 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
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
#!perl -T

use strict;
use warnings FATAL => 'all';

use Scalar::Util qw( weaken );

use Test::More tests => 7;
use Test::Builder::Tester;

BEGIN {
    use_ok( 'Test::Memory::Cycle' );
}

my $mom = {
    name => "Marilyn Lester",
};

my $dad = {
    name => "Dan Lester",
};

my $me = {
    name => "Andy Lester",
    parents => [$mom,$dad],
};
my $andy = $me;

my $amy = {
    name => "Amy Lester",
};

my $quinn = {
    name => "Quinn Lester",
    parents => [$andy,$amy],
};

$mom->{children} = [$andy];
$mom->{grandchildren} = [$quinn];

test_out( "not ok 1 - The Array Family" );
test_fail( +13 );
test_diag( 'Cycle #1' );
test_diag( '    %A->{parents} => @B' );
test_diag( '    @B->[0] => %C' );
test_diag( '    %C->{children} => @D' );
test_diag( '    @D->[0] => %A' );
test_diag( 'Cycle #2' );
test_diag( '    %A->{parents} => @B' );
test_diag( '    @B->[0] => %C' );
test_diag( '    %C->{grandchildren} => @E' );
test_diag( '    @E->[0] => %F' );
test_diag( '    %F->{parents} => @G' );
test_diag( '    @G->[0] => %A' );
memory_cycle_ok( $me, "The Array Family" );
test_test( "Array family testing" );

test_out( "ok 1 - The Array Family has Cycles" );
memory_cycle_exists( $me, "The Array Family has Cycles" );
test_test( "Array family testing for cycles" );

weaken($me->{parents}->[0]->{children}->[0]);
weaken($me->{parents}->[0]->{grandchildren}->[0]->{parents}->[0]);

test_out( "ok 1 - The Array Family (weakened)" );
memory_cycle_ok( $me, "The Array Family (weakened)" );
test_test( "Array family (weakened) testing (no cycles)" );

test_out( "not ok 1 - The Array Family (weakened)" );
test_fail( +13 );
test_diag( 'Cycle #1' );
test_diag( '    %A->{parents} => @B' );
test_diag( '    @B->[0] => %C' );
test_diag( '    %C->{children} => @D' );
test_diag( '    w->@D->[0] => %A' );
test_diag( 'Cycle #2' );
test_diag( '    %A->{parents} => @B' );
test_diag( '    @B->[0] => %C' );
test_diag( '    %C->{grandchildren} => @E' );
test_diag( '    @E->[0] => %F' );
test_diag( '    %F->{parents} => @G' );
test_diag( '    w->@G->[0] => %A' );
weakened_memory_cycle_ok( $me, "The Array Family (weakened)" );
test_test( "Array family (weakened) testing (weakened cycles showing)" );

test_out( "not ok 1 - The Array Family (weakened) has Cycles" );
test_fail( +1 );
memory_cycle_exists( $me, "The Array Family (weakened) has Cycles" );
test_test( "Array family (weakened) testing for cycles (no cycles)" );

test_out( "ok 1 - The Array Family (weakened) has Cycles" );
weakened_memory_cycle_exists( $me, "The Array Family (weakened) has Cycles" );
test_test( "Array family (weakened) testing for cycles (weakened cycles showing)" );