File: 02-delta.t

package info (click to toggle)
libtest-number-delta-perl 1.06-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 232 kB
  • sloc: perl: 305; makefile: 2
file content (200 lines) | stat: -rw-r--r-- 6,765 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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use strict;

use Test::Builder::Tester 1.02 tests => 25;
use Test::Number::Delta;

select(STDERR);
$|++;
select(STDOUT);
$|++;

#--------------------------------------------------------------------------#
# scalar - delta_ok
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("0.0000100 and 0.0000200 are not equal to within 0.000001");
delta_ok( 1e-5, 2e-5, "foo" );
test_test("delta_ok(\$a,\$b) fail works");

test_out("ok 1 - foo");
delta_ok( 1.1e-6, 2e-6, "foo" );
test_test("delta_ok(\$a,\$b) pass works");

#--------------------------------------------------------------------------#
# scalar - delta_not_ok
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Arguments are equal to within 0.000001");
delta_not_ok( 1e-7, 2e-7, "foo" );
test_test("delta_not_ok(\$a,\$b) fail works");

test_out("ok 1 - foo");
delta_not_ok( 1.2e-5, 1e-5, "foo" );
test_test("delta_not_ok(\$a,\$b) pass works");

#--------------------------------------------------------------------------#
# scalar -- delta_within
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("0.00100 and 0.00200 are not equal to within 0.0001");
delta_within( 1e-3, 2e-3, 1e-4, "foo" );
test_test("delta_within(\$a,\$b,\$e) fail works");

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("0.00100 and 0.00200 are not equal to within 0.0001");
delta_within( 1e-3, 2e-3, -1e-4, "foo" );
test_test("delta_within(\$a,\$b,-\$e) fail works");

test_out("ok 1 - foo");
delta_within( 1.1e-4, 2e-4, 1e-4, "foo" );
test_test("delta_within(\$a,\$b,\$e) pass works");

test_out("ok 1 - foo");
delta_within( 1.1e-4, 2e-4, -1e-4, "foo" );
test_test("delta_within(\$a,\$b,-\$e) pass works");

#--------------------------------------------------------------------------#
# scalar -- delta_not_within
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Arguments are equal to within 0.01");
delta_not_within( 1e-3, 2e-3, 1e-2, "foo" );
test_test("delta_not_within(\$a,\$b,\$e) fail works");

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Arguments are equal to within 0.01");
delta_not_within( 1e-3, 2e-3, -1e-2, "foo" );
test_test("delta_not_within(\$a,\$b,-\$e) fail works");

test_out("ok 1 - foo");
delta_not_within( 1.1e-4, 2e-4, 1e-5, "foo" );
test_test("delta_not_within(\$a,\$b,\$e) pass works");

test_out("ok 1 - foo");
delta_not_within( 1.1e-4, 2e-4, -1e-5, "foo" );
test_test("delta_not_within(\$a,\$b,-\$e) pass works");

#--------------------------------------------------------------------------#
# list - length
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Got an array of length 2, but expected an array of length 1");
delta_ok( [ 1e-5, 2e-5 ], [1e-5], "foo" );
test_test("delta_ok(\\\@a,\\\@b) unequal length fail works");

#--------------------------------------------------------------------------#
# list -- delta_ok
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("At [1]: 0.0000200 and 0.0000300 are not equal to within 0.000001");
delta_ok( [ 1e-5, 2e-5 ], [ 1e-5, 3e-5 ], "foo" );
test_test("delta_ok(\\\@a,\\\@b) pairwise fail works");

test_out("ok 1 - foo");
delta_ok( [ 1e-5, 2e-5 ], [ 1e-5, 2e-5 ], "foo" );
test_test("delta_ok(\\\@a,\\\@b) pairwise pass works");

#--------------------------------------------------------------------------#
# list -- delta_not_ok
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Arguments are equal to within 0.000001");
delta_not_ok( [ 1e-7, 2e-7 ], [ 1e-7, 2e-7 ], "foo" );
test_test("delta_not_ok(\\\@a,\\\@b) pairwise fail at [0] works");

test_out("ok 1 - foo");
delta_not_ok( [ 1e-5, 2e-5 ], [ 1e-5, 3e-5 ], "foo" );
test_test("delta_not_ok(\\\@a,\\\@b) pairwise pass works");

#--------------------------------------------------------------------------#
# matrix -- delta_ok
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("At [1][0]: 0.0000300 and 0.0000100 are not equal to within 0.000001");
delta_ok( [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ],
    [ [ 1e-5, 2e-5 ], [ 1e-5, 4e-5 ] ], "foo" );
test_test("delta_ok(\\\@a,\\\@b) matrix fail works");

test_out("ok 1 - foo");
delta_ok( [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ],
    [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ], "foo" );
test_test("delta_ok(\\\@a,\\\@b) matrix pass works");

#--------------------------------------------------------------------------#
# matrix -- delta_not_ok
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Arguments are equal to within 0.000001");
delta_not_ok( [ [ 1e-7, 2e-7 ], [ 3e-7, 4e-7 ] ],
    [ [ 2e-7, 3e-7 ], [ 4e-7, 5e-7 ] ], "foo" );
test_test("delta_not_ok(\\\@a,\\\@b) matrix fail works");

test_out("ok 1 - foo");
delta_not_ok( [ [ 1e-7, 2e-7 ], [ 3e-7, 4e-5 ] ],
    [ [ 5e-7, 6e-7 ], [ 7e-7, 8e-5 ] ], "foo" );
test_test("delta_not_ok(\\\@a,\\\@b) matrix pass works");

#--------------------------------------------------------------------------#
# matrix -- delta_within
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("At [1][0]: 0.00300 and 0.00100 are not equal to within 0.0001");
delta_within(
    [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ],
    [ [ 1e-3, 2e-3 ], [ 1e-3, 4e-3 ] ],
    1e-4, "foo"
);
test_test("delta_within(\\\@a,\\\@b,\$e) matrix fail works");

test_out("ok 1 - foo");
delta_within(
    [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ],
    [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ],
    1e-4, "foo"
);
test_test("delta_within(\\\@a,\\\@b,\$e) matrix pass works");

#--------------------------------------------------------------------------#
# matrix -- delta_not_within
#--------------------------------------------------------------------------#

test_out("not ok 1 - foo");
test_fail(+2);
test_diag("Arguments are equal to within 0.0001");
delta_not_within(
    [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ],
    [ [ 5e-5, 6e-5 ], [ 7e-5, 8e-5 ] ],
    1e-4, "foo"
);
test_test("delta_not_within(\\\@a,\\\@b,\$e) matrix fail works");

test_out("ok 1 - foo");
delta_not_within(
    [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ],
    [ [ 5e-3, 6e-3 ], [ 7e-3, 8e-3 ] ],
    1e-4, "foo"
);
test_test("delta_not_within(\\\@a,\\\@b,\$e) matrix pass works");