1
1
use v6 ;
2
- use Vector;
2
+ use Math:: Vector;
3
3
use Test ;
4
4
5
5
plan * ;
6
6
7
- my $ v1 = Vector. new (1 , 2 , 3 );
8
- my Vector $ v2 = Vector. new (3 , 4 , 0 );
7
+ my $ v1 = Math:: Vector. new (1 , 2 , 3 );
8
+ my Math:: Vector $ v2 = Math:: Vector. new (3 , 4 , 0 );
9
9
my @ v3 = (-1 , 0 , 2 );
10
- my Vector $ v3 = Vector. new (@ v3 );
11
- my Vector $ origin3d = Vector. new (0 , 0 , 0 );
12
- my Vector $ v5 = Vector. new (1 ,2 ,3 ,4 ,5 );
13
- my Vector $ v6 = Vector. new (0 ,0 ,1 ,0 ,0 );
14
- my Vector $ v7 = Vector. new (1 ,0 ,0 ,0 ,0 ,0 ,0 );
15
- my Vector $ v8 = Vector. new (0 ,1 ,0 ,0 ,0 ,0 ,0 );
16
- my Vector $ v9 = Vector. new (1 .. 7 );
17
- my Vector $ v10 = Vector. new (10 ,20 ,1 ,10 ,20 ,10 ,30 );
18
- my Vector $ vcrazy = Vector. new (Vector. new (1 , 2 , 3 ), Vector. new (-1 , 0 , -1 ));
10
+ my Math:: Vector $ v3 = Math:: Vector. new (@ v3 );
11
+ my Math:: Vector $ origin3d = Math:: Vector. new (0 , 0 , 0 );
12
+ my Math:: Vector $ v5 = Math:: Vector. new (1 ,2 ,3 ,4 ,5 );
13
+ my Math:: Vector $ v6 = Math:: Vector. new (0 ,0 ,1 ,0 ,0 );
14
+ my Math:: Vector $ v7 = Math:: Vector. new (1 ,0 ,0 ,0 ,0 ,0 ,0 );
15
+ my Math:: Vector $ v8 = Math:: Vector. new (0 ,1 ,0 ,0 ,0 ,0 ,0 );
16
+ my Math:: Vector $ v9 = Math:: Vector. new (1 .. 7 );
17
+ my Math:: Vector $ v10 = Math:: Vector. new (10 ,20 ,1 ,10 ,20 ,10 ,30 );
18
+ my Math:: Vector $ vcrazy = Math:: Vector. new (Math:: Vector. new (1 , 2 , 3 ), Math:: Vector. new (-1 , 0 , -1 ));
19
19
20
20
my @ vectors = ($ v1 , $ v2 , $ v3 , $ origin3d , $ v5 , $ v6 , $ v7 , $ v8 , $ v9 , $ v10 );
21
21
22
- isa_ok($ v1 , Vector, " Variable is of type Vector" );
23
- isa_ok($ v2 , Vector, " Variable is of type Vector" );
24
- isa_ok($ v3 , Vector, " Variable is of type Vector" );
25
- isa_ok($ v5 , Vector, " Variable is of type Vector" );
26
- isa_ok($ v7 , Vector, " Variable is of type Vector" );
27
- isa_ok($ vcrazy , Vector, " Variable is of type Vector" );
22
+ isa_ok($ v1 , Math:: Vector, " Variable is of type Math:: Vector" );
23
+ isa_ok($ v2 , Math:: Vector, " Variable is of type Math:: Vector" );
24
+ isa_ok($ v3 , Math:: Vector, " Variable is of type Math:: Vector" );
25
+ isa_ok($ v5 , Math:: Vector, " Variable is of type Math:: Vector" );
26
+ isa_ok($ v7 , Math:: Vector, " Variable is of type Math:: Vector" );
27
+ isa_ok($ vcrazy , Math:: Vector, " Variable is of type Math:: Vector" );
28
28
29
29
is (~ $ v1 , " (1, 2, 3)" , " Stringify works" );
30
30
is (~ $ v3 , " (-1, 0, 2)" , " Stringify works" );
@@ -36,11 +36,11 @@ is(~eval($v1.perl), ~$v1, ".perl works");
36
36
is (~ eval($ v9 . perl ), ~ $ v9 , " .perl works" );
37
37
is (~ eval($ vcrazy . perl ), ~ $ vcrazy , " .perl works" );
38
38
39
- is ($ v1 . Dim, 3 , " Dim works for 3D Vector" );
40
- is ($ v5 . Dim, 5 , " Dim works for 5D Vector" );
41
- is ($ v7 . Dim, 7 , " Dim works for 7D Vector" );
39
+ is ($ v1 . Dim, 3 , " Dim works for 3D Math:: Vector" );
40
+ is ($ v5 . Dim, 5 , " Dim works for 5D Math:: Vector" );
41
+ is ($ v7 . Dim, 7 , " Dim works for 7D Math:: Vector" );
42
42
43
- is_approx($ v7 ⋅ $ v8 , 0 , " Perpendicular vectors have 0 dot product" );
43
+ is_approx($ v7 ⋅ $ v8 , 0 , " Perpendicular Math::Vectors have 0 dot product" );
44
44
45
45
46
46
# basic math tests
@@ -51,7 +51,7 @@ is(($v1 + $v2) + $v3, $v1 + ($v2 + $v3), "Addition is associative");
51
51
is ($ v1 + $ origin3d , $ v1 , " Addition with origin leaves original" );
52
52
53
53
# {
54
- # my Vector $a = $v1;
54
+ # my Math:: Vector $a = $v1;
55
55
# $a += $v2;
56
56
# is(~($v1 + $v2), ~$a, "+= works");
57
57
# }
@@ -63,7 +63,7 @@ is($v1 - $origin3d, $v1, "Subtracting the origin leaves original");
63
63
is (-$ origin3d , $ origin3d , " Negating the origin leaves the origin" );
64
64
is (~ (-$ v2 ), " (-3, -4, 0)" , " Negating works" );
65
65
# {
66
- # my Vector $a = $v1;
66
+ # my Math:: Vector $a = $v1;
67
67
# $a -= $v2;
68
68
# is(~($v1 - $v2), ~$a, "+= works");
69
69
# }
@@ -82,22 +82,22 @@ for @vectors -> $v
82
82
83
83
for @ vectors -> $ v
84
84
{
85
- my Vector $ vn = $ v * 4.5 ;
86
- is_approx($ vn . Length, $ v . Length * 4.5 , " Scalar by Vector multiply gets proper length" );
87
- is_approx_vector($ vn . Unitize, $ v . Unitize, " Scalar by Vector multiply gets proper direction" );
88
- is_approx_vector($ vn , 4.5 * $ v , " Scalar by Vector multiply is commutative" );
85
+ my Math:: Vector $ vn = $ v * 4.5 ;
86
+ is_approx($ vn . Length, $ v . Length * 4.5 , " Scalar by Math:: Vector multiply gets proper length" );
87
+ is_approx_vector($ vn . Unitize, $ v . Unitize, " Scalar by Math:: Vector multiply gets proper direction" );
88
+ is_approx_vector($ vn , 4.5 * $ v , " Scalar by Math:: Vector multiply is commutative" );
89
89
}
90
90
91
91
for @ vectors -> $ v
92
92
{
93
- my Vector $ vn = $ v / 4.5 ;
94
- is_approx($ vn . Length, $ v . Length / 4.5 , " Vector by Scalar divide gets proper length" );
95
- is_approx_vector($ vn . Unitize, $ v . Unitize, " Vector by Scalar divide gets proper direction" );
96
- is_approx_vector($ vn , $ v * (1.0 / 4.5 ), " Vector by Scalar divide is equal to multiplication by reciprocal" );
93
+ my Math:: Vector $ vn = $ v / 4.5 ;
94
+ is_approx($ vn . Length, $ v . Length / 4.5 , " Math:: Vector by Scalar divide gets proper length" );
95
+ is_approx_vector($ vn . Unitize, $ v . Unitize, " Math:: Vector by Scalar divide gets proper direction" );
96
+ is_approx_vector($ vn , $ v * (1.0 / 4.5 ), " Math:: Vector by Scalar divide is equal to multiplication by reciprocal" );
97
97
}
98
98
99
99
# dot product tests
100
- is_approx($ v7 dot $ v8 , 0 , " Perpendicular vectors have 0 dot product" );
100
+ is_approx($ v7 dot $ v8 , 0 , " Perpendicular Math::Vectors have 0 dot product" );
101
101
102
102
for ($ v1 , $ v2 , $ v3 ) X ($ v1 , $ v2 , $ v3 ) -> $ x , $ y
103
103
{
@@ -121,8 +121,8 @@ dies_ok( { $v7 dot $v5 }, "You can't do dot products of different dimensions");
121
121
# }
122
122
123
123
# {
124
- # my Vector $a = $v1;
125
- # dies_ok( { $a ⋅= $v2; }, "You can't do dot= on a Vector variable");
124
+ # my Math:: Vector $a = $v1;
125
+ # dies_ok( { $a ⋅= $v2; }, "You can't do dot= on a Math:: Vector variable");
126
126
# }
127
127
128
128
# cross product tests
@@ -160,30 +160,29 @@ dies_ok( { $v5 cross $v6 }, "You can't do 5D cross products");
160
160
# is_approx($v1 × $v2, $a, "×= works");
161
161
# }
162
162
163
- # UnitVector tests
164
- {
165
- my UnitVector $ a = Vector. new (1 , 0 , 0 );
166
- # isa_ok($a, UnitVector, "Variable is of type UnitVector");
167
- isa_ok($ a , Vector, " Variable is of type Vector" );
168
- }
163
+ # Math::UnitVector tests
164
+ # {
165
+ # my Math::UnitVector $a = Math::Vector.new(1, 0, 0);
166
+ # isa_ok($a, Math::Vector, "Variable is of type Math::Vector");
167
+ # }
169
168
170
169
# {
171
- # my UnitVector $a = UnitVector.new(1, 0, 0);
170
+ # my Math:: UnitVector $a = Math:: UnitVector.new(1, 0, 0);
172
171
# my $b = $a;
173
172
# $b += $v2;
174
- # is_approx($a + $v2, $b, "+= works on UnitVector");
173
+ # is_approx($a + $v2, $b, "+= works on Math:: UnitVector");
175
174
# }
176
175
# {
177
- # my UnitVector $a = Vector.new(1, 0, 0);
178
- # dies_ok( { $a += $v2; }, "Catch if += violates the UnitVector constraint");
176
+ # my Math:: UnitVector $a = Math:: Vector.new(1, 0, 0);
177
+ # dies_ok( { $a += $v2; }, "Catch if += violates the Math:: UnitVector constraint");
179
178
# }
180
179
181
180
# test prefix plus
182
- # isa_ok(+$v1, Vector, "Prefix + works on the Vector class");
183
- dies_ok( { $ v1 . Num ; }, " Make sure .Num does not work on 3D vector " );
181
+ # isa_ok(+$v1, Math:: Vector, "Prefix + works on the Math:: Vector class");
182
+ dies_ok( { $ v1 . Num ; }, " Make sure .Num does not work on 3D Math::Vector " );
184
183
185
184
# test extensions
186
- class VectorWithLength is Vector
185
+ class Math:: VectorWithLength is Math:: Vector
187
186
{
188
187
has $ . length ;
189
188
@@ -203,9 +202,9 @@ class VectorWithLength is Vector
203
202
}
204
203
}
205
204
206
- my VectorWithLength $ vl = VectorWithLength. new ($ v7 . coordinates);
207
- isa_ok($ vl , VectorWithLength, " Variable is of type VectorWithLength" );
205
+ my Math:: VectorWithLength $ vl = Math:: VectorWithLength. new ($ v7 . coordinates);
206
+ isa_ok($ vl , Math:: VectorWithLength, " Variable is of type Math:: VectorWithLength" );
208
207
my $ vlc = eval($ vl . perl );
209
- isa_ok($ vlc , VectorWithLength, " eval'd perl'd variable is of type VectorWithLength" );
208
+ isa_ok($ vlc , Math:: VectorWithLength, " eval'd perl'd variable is of type Math:: VectorWithLength" );
210
209
211
210
done_testing;
0 commit comments