forked from PolyMathOrg/vector-matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPMAdditionalTest.class.st
More file actions
72 lines (63 loc) · 2.1 KB
/
PMAdditionalTest.class.st
File metadata and controls
72 lines (63 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"
here are tests that would be in Math-Tests-DHB-Numerical, if it could construct random matrices
"
Class {
#name : 'PMAdditionalTest',
#superclass : 'TestCase',
#category : 'Math-Matrix-Tests',
#package : 'Math-Matrix-Tests'
}
{ #category : 'tests' }
PMAdditionalTest >> testMatrixInversionSmall [
"it is here since it uses random matrices"
| m c i |
c := PMSymmetricMatrix identity: 5.
3 timesRepeat: [
[
m := PMSymmetricMatrix new: 5 random: 20 generator: (Random seed: 42).
m determinant = 0 ] whileTrue. "singular matrix not allowed"
self assert: (i := m crlInverse) * m closeTo: c.
self assert: i class equals: PMSymmetricMatrix.
self assert: (i := m inversePureLUP) * m closeTo: c.
self assert: i class equals: PMSymmetricMatrix.
self assert: m * (i := m inversePureCRL) closeTo: c.
self assert: i class equals: PMSymmetricMatrix ].
3 timesRepeat: [
[
m := PMMatrix
rows: 5
columns: 5
random: 20
generator: (Random seed: 42).
m determinant = 0 ] whileTrue.
self assert: m * (i := m inverse) closeTo: c.
self assert: i class equals: PMMatrix.
self assert: (i := m inversePureCRL) * m closeTo: c.
self assert: i class equals: PMMatrix ]
]
{ #category : 'tests' }
PMAdditionalTest >> testMatrixSquared [
"this tests squared and is not in Math-Tests-Numerical since it uses random matrices"
| a |
10 timesRepeat: [
a := PMMatrix
rows: 20
columns: 21
random: 10.0
generator: (Random seed: 42).
self assert: a squared equals: a transpose * a ].
self assert: a squared class equals: PMSymmetricMatrix
]
{ #category : 'tests' }
PMAdditionalTest >> testTensorProduct [
"this tests if a tensor product of two vectors is calculated correctly"
| a b expected |
a := #(3 4) asPMVector.
b := #(1 2) asPMVector.
"tensor product of two different vectors (a PMMatrix)"
expected := PMMatrix rows: #((3 6)(4 8)).
self assert: (a tensorProduct: b) equals: expected.
"tensor product of two equal vectors (a PMSymmetricMatrix)"
expected := PMMatrix rows: #((9 12)(12 16)).
self assert: (a tensorProduct: a) equals: expected.
]