File: array.t

package info (click to toggle)
libtest-data-perl 1.248-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 200 kB
  • sloc: perl: 471; makefile: 2
file content (144 lines) | stat: -rw-r--r-- 3,696 bytes parent folder | download | duplicates (5)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use Test::Builder::Tester tests => 3;
use Test::More;
use Test::Data qw(Array);

#use Carp;
#$SIG{__WARN__} = \&confess;
my %line;

TEST_ARRAY_FUNCS: {
my @array = 4..6;
my @empty = ();

test_err();

array_any_ok(  5, @array );
test_out( "ok 1 - Array contains item" );

array_any_ok(  9, @array, "Array does not contain 9, go fish" ); $line{'9x0'} = __LINE__;
test_out( "not ok 2 - Array does not contain 9, go fish" );

array_once_ok( 5, @array, "Array contains 5 once" );
test_out( "ok 3 - Array contains 5 once" );

{
my @array = (5, 5);
array_once_ok( 5, @array, "Array has 5 twice, not once" ); $line{'5x2'} = __LINE__;
test_out( "not ok 4 - Array has 5 twice, not once" );

@array = ();
array_once_ok( 5, @array, "Array has no items" ); $line{'5x0'} = __LINE__;
test_out( "not ok 5 - Array has no items" ); 

@array = ( 6, 6 );
array_once_ok( 5, @array, "Array has no 5's, but two 6's" );  $line{'6x2'} = __LINE__;
test_out( "not ok 6 - Array has no 5's, but two 6's" );
}


array_none_ok( 7, @array );
array_sum_ok( 15, @array );
array_max_ok(  6, @array );
array_min_ok(  3, @array );
array_empty_ok( @empty );
array_length_ok( @array, 3 );
test_out( 
    "ok 7 - Array does not contain item",
    "ok 8 - Array sum is correct",
    "ok 9 - Array maximum is okay",
    "ok 10 - Array minimum is okay",
    "ok 11 - Array is empty",
    "ok 12 - Array length is correct",
	);

test_err( "#     Failed test ($0 at line $line{'9x0'})",
	"#     Failed test ($0 at line $line{'5x2'})",
	"#     Failed test ($0 at line $line{'5x0'})",
	"#     Failed test ($0 at line $line{'6x2'})"
	);
test_test('Array functions work');
}

TEST_STR_SORTS: {
my @array   = 'a' .. 'f';
my @reverse = reverse @array;

test_err();

array_sortedstr_ascending_ok( @array );
array_sortedstr_descending_ok( @reverse );

test_out(
	"ok 1 - Array is in ascending order",
	"ok 2 - Array is in descending order",
	);

array_sortedstr_ascending_ok( @reverse ); $line{'up'} = __LINE__;
array_sortedstr_descending_ok( @array ); $line{'down'} = __LINE__;
test_out(
	'not ok 3 - Array is in ascending order',
	'not ok 4 - Array is in descending order',
	);
test_err(
	"#     Failed test ($0 at line $line{up})",
	"#     Failed test ($0 at line $line{down})",
	);

my @bad = ( 'a' .. 'f', 'b' );
my @bad_reverse = reverse @bad;

array_sortedstr_ascending_ok( @bad ); $line{'up'} = __LINE__;
array_sortedstr_descending_ok( @bad_reverse ); $line{'down'} = __LINE__;
test_out(
	'not ok 5 - Array is in ascending order',
	'not ok 6 - Array is in descending order',
	);
test_err(
	"#     Failed test ($0 at line $line{up})",
	"#     Failed test ($0 at line $line{down})",
	);

test_test('Sort comparisons work');
}

TEST_NUM_SORTS: {
my @array   = 1 .. 5;
my @reverse = reverse @array;

test_err();

array_sorted_ascending_ok( @array );
array_sorted_descending_ok( @reverse );

test_out(
	"ok 1 - Array is in ascending order",
	"ok 2 - Array is in descending order",
	);

array_sorted_ascending_ok( @reverse ); $line{up} = __LINE__;
array_sorted_descending_ok( @array ); $line{down} = __LINE__;
test_out(
	'not ok 3 - Array is in ascending order',
	'not ok 4 - Array is in descending order',
	);
test_err(
	"#     Failed test ($0 at line $line{up})",
	"#     Failed test ($0 at line $line{down})",
	);

my @bad = ( 1 .. 5, 3 );
my @bad_reverse = reverse @bad;

array_sorted_ascending_ok( @bad ); $line{up} = __LINE__;
array_sorted_descending_ok( @bad_reverse ); $line{down} = __LINE__;
test_out(
	'not ok 5 - Array is in ascending order',
	'not ok 6 - Array is in descending order',
	);
test_err(
	"#     Failed test ($0 at line $line{up})",
	"#     Failed test ($0 at line $line{down})",
	);

test_test('Sort comparisons work');
}