perl Testing读书笔记(简单数据结构比较)

上一篇 / 下一篇  2012-04-08 21:22:45 / 个人分类:perl相关

 

比较数据结构的代码,deeply.pl,使用了Test::Differences模块,这样可以查看其中的差别。

#!/usr/bin/perl

use Test::More tests => 1;
use Test::Differences;

my $list1 =
[
    [
        [ 48, 12 ],
        [ 32, 10 ],
    ],
    [
        [ 03, 28 ],
    ],
];

my $list2 =
[
    [
       [ 48, 12 ],
       [ 32, 11 ],
    ],
    [
       [ 03, 28],
    ],
];

eq_or_diff( $list1, $list2, 'a tale of two references' );

运行结果如下:*号代表的是两个list中不同的地方

D:\loveperl>prove -v deeply.pl
deeply....1..1

not ok 1 - a tale of two references
#   Failed test 'a tale of two references'
#   at deeply.pl line 28.
# +----+-----------+-----------+
# | Elt|Got        |Expected   |
# +----+-----------+-----------+
# |   0|[          |[          |
# |   1|  [        |  [        |
# |   2|    [      |    [      |
# |   3|      48,  |      48,  |
# |   4|      12   |      12   |
# |   5|    ],     |    ],     |
# |   6|    [      |    [      |
# |   7|      32,  |      32,  |
# *   8|      10   |      11   *
# |   9|    ]      |    ]      |
# |  10|  ],       |  ],       |
# |  11|  [        |  [        |
# |  12|    [      |    [      |
# |  13|      3,   |      3,   |
# |  14|      28   |      28   |
# |  15|    ]      |    ]      |
# |  16|  ]        |  ]        |
# |  17|]          |]          |
# +----+-----------+-----------+
# Looks like you failed 1 test of 1.
dubious
        Test returned status 1 (wstat 256, 0x100)
DIED. FAILED test 1
        Failed 1/1 tests, 0.00% okay
Failed Test Stat Wstat Total Fail  List of Failed
-------------------------------------------------------------------------------
deeply.pl      1   256     1    1  1
Failed 1/1 test scripts. 1/1 subtests failed.
Files=1, Tests=1,  0 wallclock secs ( 0.00 cusr +  0.00 csys =  0.00 CPU)
Failed 1/1 test programs. 1/1 subtests failed.


TAG:

 

评分:0

我来说两句

Open Toolbar