CCS/Utils/t/02_encode.t

filter: Statementstmt 100% 55 / 55 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 98.5% 69 / 70 CC 3 SCAR 3.4
CC
3
Cov
98%
BEGIN
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« CCS/t/common.plt ↑ Summary CCS/Utils/t/03_decode.t »
1 # -*- Mode: CPerl -*-
2 # t/02_encode.t: test ccs encoding
3 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 ##-- common subs
8 1 my $TEST_DIR;
9 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
10 1 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $TEST_DIR = Cwd::abs_path dirname( __FILE__ );
13 1 ▶ eval qq{use lib ("$TEST_DIR/$_/blib/lib","$TEST_DIR/$_/blib/arch");} foreach (qw(../../.. ../.. ..));
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ do "$TEST_DIR/common.plt" or die("$0: failed to load $TEST_DIR/common.plt: $@");
Branch: 1 branch
BranchTrueFalseTotal
do "$TEST_DIR/common.plt" or die "$0: failed to load $TEST_DIR/common.plt: $@" 1 0 1
15 }
16  
17 ##-- common modules
18 1 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use PDL::CCS::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use PDL::VectorValued;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 ##-- setup
23 1 my $a = pdl(double, [
24 [10,0,0,0,-2],
25 [3,9,0,0,0],
26 [0,7,8,7,0],
27 [3,0,8,7,5],
28 [0,8,0,9,9],
29 [0,4,0,0,2],
30 ]);
31  
32 ##-- test: encode_pointers
33 1 my $awhich = $a->whichND()->vv_qsortvec;
34 1 my $avals = $a->indexND($awhich);
35 1 my ($aptr0,$awi0) = ccs_encode_pointers($awhich->slice("(0),"));
36 1 my ($aptr1,$awi1) = ccs_encode_pointers($awhich->slice("(1),"));
37  
38 ##-- 1..2
39 1 my $awhich_want = pdl(long, [[0,0],[0,1],[0,3],[1,1],[1,2],[1,4],[1,5],[2,2],[2,3],[3,2],[3,3],[3,4],[4,0],[4,3],[4,4],[4,5]]);
40 #my $avals_want = pdl([10,3,3,9,7,8,4,8,8,7,7,9,-2,5,9,2]); # this is what we expect to expect
41 1 my $avals_want = $a->indexND($awhich_want); # ... but what we actually expect is whatever PDL::indexND() does
42 1 pdlok("whichND", $awhich,$awhich_want);
43 1 pdlok("vals", $avals, $avals_want);
44  
45 ##-- 3..4: ptr0
46 1 pdlok("ccs_encode_pointers:ptr0", $aptr0, pdl(long,[0,3,7,9,12,16]));
47 1 pdlok("ccs_encode_pointers:awi0", $awi0, $awi0->sequence);
48  
49 ##-- 5..6: ptr1
50 1 pdlok("ccs_encode_pointers:ptr1", $aptr1, pdl(long,[0,2,4,7,11,14,16]));
51 1 my $awi1x = $awhich->slice("(1),")->index($awi1);
52 1 pdlok("ccs_encode_pointers:awi1", $awi1x, $awi1x->qsort);
53  
54 1 done_testing;
« CCS/t/common.plt ↑ Summary CCS/Utils/t/03_decode.t »