vector_test.pl

filter: Statementstmt 100% 109 / 109 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 112 / 112 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Math/synopsis.pl ↑ Summary
1 #!/usr/bin/perl
2 #
3 # Testing the Math::VectorReal module
4 #
5 # location of my libraries (I normally set this via PERL5LIB)
6 #use lib '/home/anthony/lib/perl5'; # location of my libraries
7 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use lib "$FindBin::Bin/blib/lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Math::VectorReal qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 #$Math::VectorReal::TRACE = 1; # Tracing of overload operators on/off
12  
13 1 print "Stringify output testing (MatrixReal default)\n";
14 1 print 'O->stringify => ', O->stringify;
15 1 print "\n";
16  
17 1 print "Changing default vector to string format\n";
18 1 print '$Math::VectorReal::FORMAT = "[ %g %g %g ]";', "\n";
19 1 $Math::VectorReal::FORMAT = "[ %g %g %g ]";
20 1 print "\n";
21  
22 1 print "Axis functions, assign to constants\n";
23 1 print ' $o = O => ', $o=O, "\n";
24 1 print ' $x = X => ', $x=X, "\n";
25 1 print ' $y = Y => ', $y=Y, "\n";
26 1 print ' $z = Z => ', $z=Z, "\n";
27 1 print "\n";
28  
29 1 print "String conversion operation testing\n";
30 1 print "Note: this include some automatic stringify concat ('.') operations\n";
31 1 print ' "$o" => ', "$o", "\n";
32 1 print '""$x =>', " $x", "\n";
33 1 print ' $y"" => ', "$y\n";
34 1 print ' $z => ', $z, "\n";
35 1 print 'vector(1,2,3) => ', vector(1,2,3), "\n";
36 1 print "\n";
37  
38 1 print "Addition\n";
39 1 $a = $x + Y;
40 1 print '$a = $x + Y => ', $a, "\n";
41 1 $a += $y ;
42 1 print '$a += $y => ', $a, "\n";
43 1 print "\n";
44  
45 1 print "Clone and Addition Tests\n";
46 1 $b = $y;
47 1 print '$b = $y => ', $b, "\n";
48 1 $b += Z;
49 1 print '$b += Z => ', $b, "\n";
50 1 print ' $y => ', $y, "\n";
51 1 print "\n";
52  
53 1 print "Subtraction\n";
54 1 $b -= $z ;
55 1 print '$b -= $z => ', $b, "\n";
56 1 $b = $b - Z ;
57 1 print '$b = $b - Z => ', $b, "\n";
58 1 print "\n";
59  
60  
61 1 print "Scalar Multiply\n";
62 1 $a = $z * 2;
63 1 print '$a = $z * 2 => ', $a, "\n";
64 1 $a = 2 * Z;
65 1 print '$a = 2 * Z => ', $a, "\n";
66 1 $a *= 2.5;
67 1 print '$a *= 2.5 => ', $a, "\n";
68 1 print "\n";
69  
70 1 print "Scalar Divide\n";
71 1 $a = $b / 2;
72 1 print '$a = $b / 2 => ', $a, "\n";
73 1 $a /= 3e14;
74 1 print '$a /= 3e14 => ', $a, "\n";
75 1 print "\n";
76  
77  
78 1 print "Unary - and more subtraction\n";
79 1 $b = -$b;
80 1 print '$b = -$b => ', $b, "\n";
81 1 $b -= Z;
82 1 print '$b -= Z => ', $b, "\n";
83 1 $b -= $z - -$y;
84 1 print '$b -= $z - -$y => ', $b, "\n";
85 1 $b = $o - $b;
86 1 print '$b = $o - $b => ', $b, "\n";
87 1 print "\n";
88  
89  
90 1 print "Cross Product\n";
91 1 $a = $b x X;
92 1 print '$a = $b x X => ', $a, "\n";
93 1 $a = $b x $y;
94 1 print '$a = $b x $y => ', $a, "\n";
95 1 $a = $b x $z;
96 1 print '$a = $b x $z => ', $a, "\n";
97 1 print "\n";
98  
99  
100 1 print "Dot Product / String Concatenation\n";
101 1 $a = Z . $b;
102 1 print '$a = Z . $b => ', $a, "\n";
103 1 $a = $b . -$y;
104 1 print '$a = $b . -$y => ', $a, "\n";
105 1 $s = $b . "!";
106 1 print '$s = $b . "!" => ', $s, "\n";
107 1 $s = "!" . $b;
108 1 print '$s = "!" . $b => ', $s, "\n";
109 1 $a .= $b;
110 1 print '$a .= $b => ', $a, "\n";
111 1 print "\n";
112  
113 1 print "Special Functions (length, norm, plane)\n";
114 1 print '$b->length => ', $b->length, "\n";
115 1 print '$b->norm => ', $b->norm, "\n";
116 1 @a = plane(X,Y,Z);
117 1 print '@a = plane(X,Y,Z) => ', "\n @a\n";
118 1 print "check output from plane() function\n";
119 1 $a = X+Y+Z;
120 1 print 'normal => ', $a->norm, "\n";
121 1 print 'distance => ', ($a/3)->length, "\n";
122 1 print "\n";
123  
124 1 print "Are defined constants still OK\n";
125 1 print '$o => ', $o, "\n";
126 1 print '$x => ', $x, "\n";
127 1 print '$y => ', $y, "\n";
128 1 print '$z => ', $z, "\n";
129 1 print "\n";
130  
« blib/lib/Math/synopsis.pl ↑ Summary