Chemistry-Mol-0.35/t/File.t

filter: Statementstmt 100% 74 / 74 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 98.8% 88 / 89 CC 2 SCAR 1.5
CC
2
Cov
99%
slurp_mol
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Chemistry-Mok-0.25/mok ↑ Summary Chemistry-Mol-0.35/t/exception.t »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #plan 'no_plan';
8 1 plan tests => 15;
9 1 ▶ use_ok('Chemistry::File');
Subroutine BEGIN: called CC=1 SCAR=0.0
10 }
11  
12  
13 # simple constructor test
14 1 my $f = Chemistry::File->new;
15 1 isa_ok($f, "Chemistry::File");
16  
17 1 require Chemistry::File::Dumper;
18  
19 # file reader test
20 1 my $fname = 't/mol.pl';
21 1 my $file = Chemistry::File::Dumper->new(file => $fname);
22 1 isa_ok($file, "Chemistry::File::Dumper");
23 1 my $mol = $file->read(format => 'dumper');
24  
25 1 isa_ok($mol, "Chemistry::Mol", 'read file');
26 1 is(scalar $mol->atoms, 8, "atoms");
27  
28  
29 # string reader test
30 1 ▶open F, "<$fname" or die;
Branch: 1 branch
BranchTrueFalseTotal
open F, "<$fname" or die 1 0 1
31 1 my $s = do {local $/; <F>};
32 1 $file = Chemistry::File::Dumper->new(file => \$s);
33 1 $mol = $file->read;
34  
35 1 isa_ok($mol, "Chemistry::Mol", 'read string');
36 1 is(scalar $mol->atoms, 8, "atoms");
37  
38  
39 # subclass test
40  
41 package MolList;
42 1 ▶use base qw(Chemistry::File);
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 ▶sub read_header {
Subroutine read_header: called CC=1 SCAR=0.0
45 1 my ($self) = @_;
46 1 my $fh = $self->fh;
47 1 my $name = <$fh>;
48 1 chomp $name;
49 1 $self->name($name);
50 }
51  
52 1 ▶sub read_footer {
Subroutine read_footer: called CC=1 SCAR=0.0
53 1 my ($self) = @_;
54 1 my $fh = $self->fh;
55 1 my $footer = join '', <$fh>;
56 1 chomp $footer;
57 1 $self->attr('list/footer', $footer);
58 }
59  
60 4 ▶sub slurp_mol {
Subroutine slurp_mol: called CC=2 SCAR=6.9
61 4 my ($self) = @_;
62 4 my $fh = $self->fh;
63 4 my $s = <$fh>;
64 4 chomp $s;
65 4 ▶ return if $s eq '--END--';
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "--END--" 1 3 4
66 3 $s;
67 }
68  
69 3 ▶sub parse_string {
Subroutine parse_string: called CC=1 SCAR=0.0
70 3 my ($self, $s) = @_;
71 3 my $fh = $self->fh;
72 3 my ($name, $price) = split "\t", $s;
73 3 my $mol = Chemistry::Mol->new(name => $name);
74 3 $mol->attr('list/price', $price);
75 3 push @{$self->{mol_list}}, $mol;
76 3 $mol;
77 }
78  
79 package main;
80  
81 1 my $list = MolList->new(file => 't/list.txt');
82 1 my @mols = $list->read;
83  
84 1 is(scalar @mols, 3, "read mollist");
85 1 is($list->name, "This is a list of molecules", "list name");
86 1 is($list->attr('list/footer'),
87 "As you can see, \neverything you need \nis on this list.", "list footer");
88 1 is($mols[1]->name, "ethane", "mol name");
89 1 is($mols[1]->attr('list/price'), '$200', "mol price");
90  
91  
92 # Chemistry::Mol->file
93 1 $file = Chemistry::Mol->file($fname);
94 1 isa_ok($file, "Chemistry::File::Dumper");
95 1 $mol = $file->read(format => 'dumper');
96  
97 1 isa_ok($mol, "Chemistry::Mol", 'Chemistry::Mol->read');
98 1 is(scalar $mol->atoms, 8, "atoms");
99  
« Chemistry-Mok-0.25/mok ↑ Summary Chemistry-Mol-0.35/t/exception.t »