| 1 | package Test2::Tools::DataFrame; | ||||||||||
| 2 | 5 | $Test2::Tools::DataFrame::VERSION = '0.006005'; | |||||||||
| 3 | # ABSTRACT: Tools for verifying Data::Frame data frames | ||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # VERSION | ||||||||||
| 10 | |||||||||||
| 11 | 5 | ▶ | use Safe::Isa; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 5 | ▶ | use Test2::API qw/context/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 5 | ▶ | use Test2::Util::Table qw/table/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 5 | ▶ | use Test2::Util::Ref qw/render_ref/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 5 | ▶ | use parent qw(Exporter::Tiny); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 5 | our @EXPORT = qw(dataframe_ok dataframe_is); | |||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub dataframe_ok ($;$) { | ||||||||
|
Subroutine
dataframe_ok: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 21 | 0 | my ( $thing, $name ) = @_; | |||||||||
| 22 | 0 | my $ctx = context(); | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | unless ( $thing->$_DOES('Data::Frame') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | my $thingname = render_ref($thing); | |||||||||
| 26 | 0 | $ctx->ok( 0, $name, ["'$thingname' is not a data frame object."] ); | |||||||||
| 27 | 0 | $ctx->release; | |||||||||
| 28 | 0 | return 0; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | $ctx->ok( 1, $name ); | |||||||||
| 32 | 0 | $ctx->release; | |||||||||
| 33 | 0 | return 1; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 57 | ▶ | sub dataframe_is ($$;$@) { | ||||||||
|
Subroutine
dataframe_is: called CC=6 SCAR=25.0
Pod
documented
| |||||||||||
| 38 | 57 | my ( $got, $exp, $name, @diag ) = @_; | |||||||||
| 39 | 57 | my $ctx = context(); | |||||||||
| 40 | |||||||||||
| 41 | 57 | ▶ | local $Data::Frame::TOLERANCE_REL = 1e-8 unless $Data::Frame::TOLERANCE_REL; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | 57 | ▶ | unless ( $got->$_DOES('Data::Frame') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | my $gotname = render_ref($got); | |||||||||
| 45 | 0 | $ctx->ok( 0, $name, | |||||||||
| 46 | ["First argument '$gotname' is not a data frame object."] ); | ||||||||||
| 47 | 0 | $ctx->release; | |||||||||
| 48 | 0 | return 0; | |||||||||
| 49 | } | ||||||||||
| 50 | 57 | ▶ | unless ( $exp->$_DOES('Data::Frame') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | my $expname = render_ref($exp); | |||||||||
| 52 | 0 | $ctx->ok( 0, $name, | |||||||||
| 53 | ["Second argument '$expname' is not a data frame object."] ); | ||||||||||
| 54 | 0 | $ctx->release; | |||||||||
| 55 | 0 | return 0; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 57 | my $diff; | |||||||||
| 59 | 57 | eval { $diff = ( $got != $exp ); }; | |||||||||
| 60 | 57 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | my $gotname = render_ref($got); | |||||||||
| 62 | 0 | $ctx->ok( 0, $name, [ "'$gotname' is different from expected.", $@ ], | |||||||||
| 63 | @diag ); | ||||||||||
| 64 | 0 | $ctx->release; | |||||||||
| 65 | 0 | return 0; | |||||||||
| 66 | } | ||||||||||
| 67 | 57 | my $diff_which = $diff->which( bad_to_val => 1 ); | |||||||||
| 68 | 57 | ▶ | unless ( $diff_which->isempty ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | 0 | my $gotname = render_ref($got); | |||||||||
| 70 | 0 | my $column_names = $exp->column_names; | |||||||||
| 71 | my @table = table( | ||||||||||
| 72 | sanitize => 1, | ||||||||||
| 73 | max_width => 80, | ||||||||||
| 74 | collapse => 1, | ||||||||||
| 75 | header => [qw(ROWIDX COLUMN GOT CHECK)], | ||||||||||
| 76 | rows => [ | ||||||||||
| 77 | map { | ||||||||||
| 78 | 0 | my ( $ridx, $cidx ) = @$_; | |||||||||
| 79 | [ | ||||||||||
| 80 | 0 | $ridx, $column_names->[$cidx], | |||||||||
| 81 | $got->at( $ridx, $cidx ), $exp->at( $ridx, $cidx ) | ||||||||||
| 82 | ] | ||||||||||
| 83 | 0 | } @{ $diff_which->unpdl } | |||||||||
| 84 | ] | ||||||||||
| 85 | ); | ||||||||||
| 86 | 0 | $ctx->ok( 0, $name, | |||||||||
| 87 | [ "'$gotname' is different from expected.", @table ], @diag ); | ||||||||||
| 88 | 0 | $ctx->release; | |||||||||
| 89 | 0 | return 0; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 57 | $ctx->ok( 1, $name ); | |||||||||
| 93 | 57 | $ctx->release; | |||||||||
| 94 | 57 | return 1; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 5 | 1; | |||||||||
| 98 | |||||||||||
| 99 | __END__ | ||||||||||