Chemistry-Mol-0.35/t/Atom.t

filter: Statementstmt 100% 99 / 99 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 98.2% 109 / 111 CC 1 SCAR 0.0
CC
1
Cov
98%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Chemistry-File-VRML-0.10/t/vrml.t ↑ Summary Chemistry-Mol-0.35/t/Bond.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 #use Test::More "no_plan";
5 1 ▶use Test::More tests => 49;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use_ok('Chemistry::Atom');
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use_ok('Chemistry::Mol');
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use_ok('Math::VectorReal');
Subroutine BEGIN: called CC=1 SCAR=0.0
11 };
12  
13 1 my ($atom, $atom2, $atom3);
14  
15 # constructor
16 1 $atom = Chemistry::Atom->new;
17 1 isa_ok( $atom, 'Chemistry::Atom', 'blank atom' );
18 1 isa_ok( $atom, 'Chemistry::Obj', 'blank atom' );
19  
20 # symbol
21 1 $atom = Chemistry::Atom->new(symbol => 'C');
22 1 is( $atom->symbol, 'C', 'symbol -> symbol' );
23 1 is( $atom->Z, 6, 'symbol -> Z' );
24  
25 # Z
26 1 $atom->Z(8);
27 1 is( $atom->Z, 8, 'Z -> Z' );
28 1 is( $atom->symbol, 'O', 'Z -> symbol' );
29  
30 # mass
31 1 ok( abs($atom->mass-16.00)<0.01, 'default mass');
32 1 $atom->mass(18.012);
33 1 is( $atom->mass, 18.012, 'arbitrary mass' );
34  
35 # aromatic
36 1 ok( ! $atom->aromatic, 'aromatic default' );
37 1 $atom->aromatic(1);
38 1 ok( $atom->aromatic, 'aromatic' );
39  
40 # default hydrogens
41 1 ok( ! $atom->hydrogens, 'hydrogens default' );
42 1 ok( ! $atom->total_hydrogens, 'total_hydrogens default' );
43 1 ok( ! $atom->implicit_hydrogens, 'implicit_hydrogens default' );
44  
45 # set hydrogens
46 1 $atom->hydrogens(1);
47 1 is( $atom->hydrogens, 1, 'hydrogens' );
48 1 is( $atom->implicit_hydrogens, 1, 'implicit_hydrogens' );
49 1 is( $atom->total_hydrogens, 1, 'total_hydrogens' );
50  
51 # set implicit_hydrogens
52 1 $atom->implicit_hydrogens(2);
53 1 is( $atom->hydrogens, 2, 'hydrogens' );
54 1 is( $atom->implicit_hydrogens, 2, 'implicit_hydrogens' );
55 1 is( $atom->total_hydrogens, 2, 'total_hydrogens' );
56 1 is( $atom->explicit_valence, 0, 'explicit_valence' );
57 1 is( $atom->valence, 2, 'valence' );
58  
59 # sprout_hydrogens
60 1 my $mol = Chemistry::Mol->new;
61 1 $mol->add_atom($atom);
62  
63 1 $atom->sprout_hydrogens;
64 1 is( $atom->hydrogens, 0, 'hydrogens' );
65 1 is( $atom->implicit_hydrogens, 0, 'implicit_hydrogens' );
66 1 is( $atom->total_hydrogens, 2, 'total_hydrogens' );
67 1 is( $atom->explicit_valence, 2, 'explicit_valence' );
68 1 is( $atom->valence, 2, 'valence' );
69  
70 # collapse_hydrogens
71 1 $atom->collapse_hydrogens;
72 1 is( $atom->hydrogens, 2, 'hydrogens' );
73 1 is( $atom->implicit_hydrogens, 2, 'implicit_hydrogens' );
74 1 is( $atom->total_hydrogens, 2, 'total_hydrogens' );
75 1 is( $atom->explicit_valence, 0, 'explicit_valence' );
76 1 is( $atom->valence, 2, 'valence' );
77  
78 # coords
79 1 $atom2 = Chemistry::Atom->new(coords => [3,0,4]);
80 1 is( $atom->distance($atom2), 5, 'distance(coords(arrayref))' );
81 1 my $v1 = $atom2->coords;
82 1 isa_ok( $v1, 'Math::VectorReal');
83 1 my $v = vector(0,10,0);
84 1 $atom2->coords($v);
85 1 is( $atom->distance($atom2), 10, 'distance(coords(vector))' );
86 1 $atom2->coords(3,0,0);
87 1 is( $atom->distance($atom2), 3, 'distance(coords(list))' );
88  
89 # x3, y3, z3 accessors
90 1 $atom2->coords($v1);
91 1 my $x = $atom2->x3;
92 1 is($x, 3, 'x3');
93 1 my $y = $atom2->y3;
94 1 is($y, 0, 'y3');
95 1 my $z = $atom2->z3;
96 1 is($z, 4, 'z3');
97  
98 # distance
99 1 is( $atom->distance($v1), 5, 'distance(vector)' );
100  
101 # sprintf
102 1 is( $atom->sprintf("%s"), 'O', 'sprintf - %s' );
103 1 is( $atom->sprintf("%Z"), 8, 'sprintf - %Z' );
104 1 is( $atom2->sprintf("%x,%y,%z"), '3,0,4', 'sprintf - %x,%y,%z' );
105  
106 # mass_number
107 1 $atom = Chemistry::Atom->new(Z => 1);
108 1 ok( abs($atom->mass-1.008)<0.001, '1H mass');
109 1 $atom->mass_number(2);
110 1 is( $atom->mass_number, 2, '2H mass number' );
111  
112 1 my $got_m2H = $atom->mass;
113 1 ▶my $m_2H = $INC{'Chemistry/Isotope.pm'} ? 2.014 : 2;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'Chemistry/Isotope.pm'} ? : 1 0 1
114 1 ▶ok( abs($got_m2H - $m_2H)<0.001, '2H mass' )
Branch: 1 branch
BranchTrueFalseTotal
&ok(abs $got_m2H - $m_2H < "0.001", "2H mass") or diag(sprintf("expected %s, got %s", $m_2H, $atom->mass)) 1 0 1
115 or diag(sprintf "expected %s, got %s", $m_2H, $atom->mass);
116 1 $atom->mass_number(10);
117 1 is( $atom->mass, 10, '10H mass' );
118  
« Chemistry-File-VRML-0.10/t/vrml.t ↑ Summary Chemistry-Mol-0.35/t/Bond.t »