math_expansion 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/Rakefile +24 -0
- data/lib/math_expansion.rb +12 -0
- data/lib/math_expansion/gcd.rb +9 -0
- data/lib/math_expansion/matriz.rb +15 -0
- data/lib/math_expansion/matriz_densa.rb +191 -0
- data/lib/math_expansion/matriz_dispersa.rb +250 -0
- data/lib/math_expansion/racional.rb +142 -0
- data/lib/math_expansion/version.rb +3 -0
- data/log.html +389 -0
- data/log.txt +44 -0
- data/math_expansion.gemspec +24 -0
- data/spec/matriz_spec.rb +323 -0
- data/test/tc_mathexpansion.rb +91 -0
- metadata +108 -0
data/log.txt
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
MathExpansion::Matriz
|
|
3
|
+
# Almacenamiento de matrices.
|
|
4
|
+
# Se debe almacenar el numero de filas.
|
|
5
|
+
# Se debe almacenar el numero de columnas.
|
|
6
|
+
# Se debe almacenar un contenido.
|
|
7
|
+
|
|
8
|
+
MathExpansion::Matriz_Densa
|
|
9
|
+
# Almacenamiento de matrices.
|
|
10
|
+
# Se debe poder acceder a los datos almacenados en la matriz
|
|
11
|
+
# Se deben poder modificar los datos almacenados en la matriz
|
|
12
|
+
# Se deben poder almacenar todo tipo de datos numericos (flotantes, enteros, etc...)
|
|
13
|
+
# Operaciones con matrices densas.
|
|
14
|
+
# Se debe poder sumar dos matrices
|
|
15
|
+
# Se debe poder restar dos matrices
|
|
16
|
+
# Se debe poder multiplicar dos matrices
|
|
17
|
+
# Si una m. densa tiene mas de un 60% de nulos, debe ser dispersa.
|
|
18
|
+
# Se debe poder operar con Fracciones.
|
|
19
|
+
# Operaciones varias.
|
|
20
|
+
# Se debe poder calcular el maximo de una matriz densa (elemento no nulo)
|
|
21
|
+
# Se debe poder calcular el minimo de una matriz densa (elemento no nulo)
|
|
22
|
+
|
|
23
|
+
MathExpansion::Matriz_Dispersa
|
|
24
|
+
# Almacenamiento de matrices.
|
|
25
|
+
# Se debe poder crear matrices dispersas vacias o a partir de matrices densas.
|
|
26
|
+
# Se debe poder calcular el porcentaje de elementos nulos de la matriz dispersa.
|
|
27
|
+
# Se debe poder acceder a los elementos de la matriz dispersa.
|
|
28
|
+
Borrado el elemento 1,0 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
|
|
29
|
+
Borrado el elemento 1,1 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
|
|
30
|
+
Borrado el elemento 2,0 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
|
|
31
|
+
Borrado el elemento 2,1 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
|
|
32
|
+
# Se deben poder modificar los elementos de la matriz dispersa.
|
|
33
|
+
# Se debe poder transformar una matriz dispersa a una cadena de caracteres.
|
|
34
|
+
# Operaciones con matrices dispersas.
|
|
35
|
+
# Se debe poder sumar dos matrices
|
|
36
|
+
# Se debe poder restar dos matrices
|
|
37
|
+
# Se debe poder multiplicar dos matrices
|
|
38
|
+
# Se debe poder hacer operaciones con Fracciones.
|
|
39
|
+
# Operaciones varias.
|
|
40
|
+
# Se debe poder calcular el maximo de una matriz densa (elemento no nulo)
|
|
41
|
+
# Se debe poder calcular el minimo de una matriz densa (elemento no nulo)
|
|
42
|
+
|
|
43
|
+
Finished in 0.01 seconds
|
|
44
|
+
24 examples, 0 failures
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'math_expansion/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "math_expansion"
|
|
8
|
+
spec.version = MathExpansion::VERSION
|
|
9
|
+
spec.authors = ["Eliasib Garcia","Daniel Herzog"]
|
|
10
|
+
spec.email = ["alu0100698121@ull.edu.es","alu0100699494"]
|
|
11
|
+
spec.description = %q{Permite la creación y uso de matrices densas y dispersas.}
|
|
12
|
+
spec.summary = %q{Matrices densas y dispersas}
|
|
13
|
+
spec.homepage = "https://github.com/alu0100698121/prct09.git"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_development_dependency "rspec"
|
|
24
|
+
end
|
data/spec/matriz_spec.rb
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
require "./lib/math_expansion.rb"
|
|
2
|
+
|
|
3
|
+
describe MathExpansion::Matriz do
|
|
4
|
+
before :each do
|
|
5
|
+
@m1 = MathExpansion::Matriz.new(5, 5)
|
|
6
|
+
end
|
|
7
|
+
describe " # Almacenamiento de matrices. " do
|
|
8
|
+
it " # Se debe almacenar el numero de filas." do
|
|
9
|
+
@m1.N
|
|
10
|
+
end
|
|
11
|
+
it " # Se debe almacenar el numero de columnas." do
|
|
12
|
+
@m1.M
|
|
13
|
+
end
|
|
14
|
+
it " # Se debe almacenar un contenido." do
|
|
15
|
+
@m1.contenido
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe MathExpansion::Matriz_Densa do
|
|
21
|
+
before :all do
|
|
22
|
+
class Fixnum
|
|
23
|
+
def self.null
|
|
24
|
+
0
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class String
|
|
29
|
+
def self.null
|
|
30
|
+
""
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class Float
|
|
35
|
+
def self.null
|
|
36
|
+
0.0
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Etc
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
before :each do
|
|
44
|
+
@m1 = MathExpansion::Matriz_Densa.new(2,2)
|
|
45
|
+
@m2 = MathExpansion::Matriz_Densa.new(2,2)
|
|
46
|
+
|
|
47
|
+
@m1.set(0,0,1)
|
|
48
|
+
@m1.set(0,1,2)
|
|
49
|
+
@m1.set(1,0,3)
|
|
50
|
+
@m1.set(1,1,4)
|
|
51
|
+
|
|
52
|
+
@m2.set(0,0,5)
|
|
53
|
+
@m2.set(0,1,6)
|
|
54
|
+
@m2.set(1,0,7)
|
|
55
|
+
@m2.set(1,1,8)
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
describe " # Almacenamiento de matrices. " do
|
|
59
|
+
it " # Se debe poder acceder a los datos almacenados en la matriz " do
|
|
60
|
+
@m1.get(0,0).should eq(1)
|
|
61
|
+
@m1.get(0,1).should eq(2)
|
|
62
|
+
end
|
|
63
|
+
it " # Se deben poder modificar los datos almacenados en la matriz " do
|
|
64
|
+
@m1.set(0,0,5)
|
|
65
|
+
@m1.get(0,0).should eq(5)
|
|
66
|
+
|
|
67
|
+
@m1.set(0,1,8)
|
|
68
|
+
@m1.get(0,1).should eq(8)
|
|
69
|
+
end
|
|
70
|
+
it " # Se deben poder almacenar todo tipo de datos numericos (flotantes, enteros, etc...) " do
|
|
71
|
+
@m1.set(0,0,3.0)
|
|
72
|
+
@m1.set(0,1,-6)
|
|
73
|
+
@m1.to_s.should == "3.0\t-6\t\n3\t4\t\n"
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe " # Operaciones con matrices densas. " do
|
|
78
|
+
it " # Se debe poder sumar dos matrices " do
|
|
79
|
+
@m3 = MathExpansion::Matriz_Densa.new(2,2)
|
|
80
|
+
@m3.set(0,0,6)
|
|
81
|
+
@m3.set(0,1,8)
|
|
82
|
+
@m3.set(1,0,10)
|
|
83
|
+
@m3.set(1,1,12)
|
|
84
|
+
|
|
85
|
+
(@m1+@m2).to_s.should eq(@m3.to_s)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it " # Se debe poder restar dos matrices " do
|
|
89
|
+
@m3 = MathExpansion::Matriz_Densa.new(2,2)
|
|
90
|
+
@m3.set(0,0,4)
|
|
91
|
+
@m3.set(0,1,4)
|
|
92
|
+
@m3.set(1,0,4)
|
|
93
|
+
@m3.set(1,1,4)
|
|
94
|
+
|
|
95
|
+
(@m2-@m1).to_s.should eq(@m3.to_s)
|
|
96
|
+
end
|
|
97
|
+
it " # Se debe poder multiplicar dos matrices " do
|
|
98
|
+
@m3 = MathExpansion::Matriz_Densa.new(2,2)
|
|
99
|
+
@m3.set(0,0,19)
|
|
100
|
+
@m3.set(0,1,22)
|
|
101
|
+
@m3.set(1,0,43)
|
|
102
|
+
@m3.set(1,1,50)
|
|
103
|
+
|
|
104
|
+
(@m1*@m2).to_s.should eq(@m3.to_s)
|
|
105
|
+
end
|
|
106
|
+
it " # Si una m. densa tiene mas de un 60% de nulos, debe ser dispersa." do
|
|
107
|
+
@m_neg = MathExpansion::Matriz_Densa.new(2,2)
|
|
108
|
+
@m_neg.set(0,0,-1)
|
|
109
|
+
@m_neg.set(0,1,-2)
|
|
110
|
+
@m_neg.set(1,0,-3)
|
|
111
|
+
@m_neg.set(1,1,-1)
|
|
112
|
+
|
|
113
|
+
@m3 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
114
|
+
@m3.set(1,1,3)
|
|
115
|
+
|
|
116
|
+
(@m1+@m_neg).to_s.should eq(@m3.to_s)
|
|
117
|
+
end
|
|
118
|
+
it " # Se debe poder operar con Fracciones." do
|
|
119
|
+
@mf = MathExpansion::Matriz_Densa.new(2,2)
|
|
120
|
+
@mf.set(0,0,MathExpansion::Fraccion.new(1,3))
|
|
121
|
+
@mf.set(0,1,MathExpansion::Fraccion.new(1,3))
|
|
122
|
+
@mf.set(1,0,MathExpansion::Fraccion.new(1,3))
|
|
123
|
+
@mf.set(1,1,MathExpansion::Fraccion.new(1,3))
|
|
124
|
+
|
|
125
|
+
@mf_res = MathExpansion::Matriz_Densa.new(2,2)
|
|
126
|
+
@mf_res.set(0,0,MathExpansion::Fraccion.new(2,3))
|
|
127
|
+
@mf_res.set(0,1,MathExpansion::Fraccion.new(2,3))
|
|
128
|
+
@mf_res.set(1,0,MathExpansion::Fraccion.new(2,3))
|
|
129
|
+
@mf_res.set(1,1,MathExpansion::Fraccion.new(2,3))
|
|
130
|
+
|
|
131
|
+
(@mf+@mf).to_s.should eq(@mf_res.to_s)
|
|
132
|
+
|
|
133
|
+
@mf1 = MathExpansion::Matriz_Densa.new(2,2)
|
|
134
|
+
@mf1.set(1,0,MathExpansion::Fraccion.new(1,4))
|
|
135
|
+
|
|
136
|
+
@mf2 = MathExpansion::Matriz_Densa.new(2,2)
|
|
137
|
+
@mf2.set(0,0,1)
|
|
138
|
+
|
|
139
|
+
@mf_res = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
140
|
+
@mf_res.set(1,0,MathExpansion::Fraccion.new(1,4))
|
|
141
|
+
|
|
142
|
+
(@mf1 * @mf2).to_s.should == @mf_res.to_s
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
describe " # Operaciones varias. " do
|
|
147
|
+
it " # Se debe poder calcular el maximo de una matriz densa (elemento no nulo)" do
|
|
148
|
+
@m1.max.should == 4
|
|
149
|
+
end
|
|
150
|
+
it " # Se debe poder calcular el minimo de una matriz densa (elemento no nulo)" do
|
|
151
|
+
@m2.min.should == 5
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
describe MathExpansion::Matriz_Dispersa do
|
|
158
|
+
before :all do
|
|
159
|
+
class Fixnum
|
|
160
|
+
def self.null
|
|
161
|
+
0
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
class String
|
|
166
|
+
def self.null
|
|
167
|
+
""
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class Float
|
|
172
|
+
def self.null
|
|
173
|
+
0.0
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Etc
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
before :each do
|
|
181
|
+
@m1 = MathExpansion::Matriz_Densa.new(3,2)
|
|
182
|
+
|
|
183
|
+
@m1.set(0,0,0)
|
|
184
|
+
@m1.set(0,1,0)
|
|
185
|
+
|
|
186
|
+
@m1.set(1,0,1)
|
|
187
|
+
@m1.set(1,1,3)
|
|
188
|
+
|
|
189
|
+
@m1.set(2,0,0)
|
|
190
|
+
@m1.set(2,1,0)
|
|
191
|
+
|
|
192
|
+
@md1 = MathExpansion::Matriz_Dispersa.copy(@m1)
|
|
193
|
+
@md2 = MathExpansion::Matriz_Dispersa.new(3, 2)
|
|
194
|
+
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
describe " # Almacenamiento de matrices. " do
|
|
198
|
+
it " # Se debe poder crear matrices dispersas vacias o a partir de matrices densas." do
|
|
199
|
+
MathExpansion::Matriz_Dispersa.new(5, 5)
|
|
200
|
+
MathExpansion::Matriz_Dispersa.copy(@m1)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it " # Se debe poder calcular el porcentaje de elementos nulos de la matriz dispersa." do
|
|
204
|
+
@md2.null_percent.should == 1.0
|
|
205
|
+
@md1.null_percent.should == 4.0/6.0
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it " # Se debe poder acceder a los elementos de la matriz dispersa." do
|
|
209
|
+
@md2.get(0,0).should == 0
|
|
210
|
+
|
|
211
|
+
@md1.get(1,1).should == 3
|
|
212
|
+
@md1.get(1,0).should == 1
|
|
213
|
+
@md1.get(0,0).should == 0
|
|
214
|
+
|
|
215
|
+
@md1.get(10,10).should == nil
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
it " # Se deben poder modificar los elementos de la matriz dispersa." do
|
|
219
|
+
@md2.set(0,0,1)
|
|
220
|
+
@md2.get(0,0).should == 1
|
|
221
|
+
|
|
222
|
+
@md2.set(0,1,1)
|
|
223
|
+
@md2.set(1,0,1)
|
|
224
|
+
@md2.set(1,1,1)
|
|
225
|
+
@md2.set(2,0,1)
|
|
226
|
+
@md2.set(2,1,1)
|
|
227
|
+
|
|
228
|
+
# Elemento nulo debido a que ha sobrepasado el porcentaje maximo de valores nulos
|
|
229
|
+
@md2.get(2,1).should == 0
|
|
230
|
+
|
|
231
|
+
@md1.set(1,1,4)
|
|
232
|
+
@md1.set(1,0,2)
|
|
233
|
+
@md1.get(1,1).should == 4
|
|
234
|
+
@md1.get(1,0).should == 2
|
|
235
|
+
|
|
236
|
+
@md1.get(0,0).should == 0
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
it " # Se debe poder transformar una matriz dispersa a una cadena de caracteres." do
|
|
240
|
+
@md1.to_s.should == "Fila 0: \nFila 1: 0=>1 1=>3 \nFila 2: \n"
|
|
241
|
+
@md2.to_s.should == "Fila 0: \nFila 1: \nFila 2: \n"
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
describe " # Operaciones con matrices dispersas. " do
|
|
248
|
+
it " # Se debe poder sumar dos matrices " do
|
|
249
|
+
@md3 = MathExpansion::Matriz_Dispersa.new(3,2)
|
|
250
|
+
@md3.set(0,0,0)
|
|
251
|
+
@md3.set(0,1,0)
|
|
252
|
+
@md3.set(1,0,1)
|
|
253
|
+
@md3.set(1,1,3)
|
|
254
|
+
@md3.set(2,0,0)
|
|
255
|
+
@md3.set(2,1,0)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
(@md1+@md2).to_s.should eq(@md3.to_s)
|
|
259
|
+
end
|
|
260
|
+
it " # Se debe poder restar dos matrices " do
|
|
261
|
+
@md3 = MathExpansion::Matriz_Dispersa.new(3,2)
|
|
262
|
+
@md3.set(0,0,0)
|
|
263
|
+
@md3.set(0,1,0)
|
|
264
|
+
@md3.set(1,0,-1)
|
|
265
|
+
@md3.set(1,1,-3)
|
|
266
|
+
@md3.set(2,0,0)
|
|
267
|
+
@md3.set(2,1,0)
|
|
268
|
+
|
|
269
|
+
(@md2-@md1).to_s.should eq(@md3.to_s)
|
|
270
|
+
end
|
|
271
|
+
it " # Se debe poder multiplicar dos matrices " do
|
|
272
|
+
@md4 = MathExpansion::Matriz_Dispersa.new(2,3)
|
|
273
|
+
@md4.set(1,0,-1)
|
|
274
|
+
@md4.set(1,1,-1)
|
|
275
|
+
@md4.set(1,2,0)
|
|
276
|
+
|
|
277
|
+
@md3 = MathExpansion::Matriz_Dispersa.new(3,3)
|
|
278
|
+
@md3.set(0,0,0)
|
|
279
|
+
@md3.set(0,1,0)
|
|
280
|
+
@md3.set(0,2,0)
|
|
281
|
+
@md3.set(1,0,-3)
|
|
282
|
+
@md3.set(1,1,-3)
|
|
283
|
+
@md3.set(1,2,0)
|
|
284
|
+
@md3.set(2,0,0)
|
|
285
|
+
@md3.set(2,1,0)
|
|
286
|
+
@md3.set(2,2,0)
|
|
287
|
+
|
|
288
|
+
(@md1*@md4).to_s.should eq(@md3.to_s)
|
|
289
|
+
end
|
|
290
|
+
it " # Se debe poder hacer operaciones con Fracciones. " do
|
|
291
|
+
@mf1 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
292
|
+
@mf1.set(1,0,MathExpansion::Fraccion.new(1,4))
|
|
293
|
+
|
|
294
|
+
@mf2 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
295
|
+
@mf2.set(1,0,MathExpansion::Fraccion.new(-1,4))
|
|
296
|
+
|
|
297
|
+
@mf_res = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
298
|
+
@mf_res.set(1,0,MathExpansion::Fraccion.new(1,2))
|
|
299
|
+
|
|
300
|
+
(@mf1-@mf2).to_s.should eq(@mf_res.to_s)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
@mf3 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
304
|
+
@mf3.set(1,0,MathExpansion::Fraccion.new(1,4))
|
|
305
|
+
|
|
306
|
+
@mf4 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
307
|
+
@mf4.set(0,0,1)
|
|
308
|
+
|
|
309
|
+
(@mf3 * @mf4).to_s.should == @mf3.to_s
|
|
310
|
+
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
end
|
|
314
|
+
describe " # Operaciones varias. " do
|
|
315
|
+
it " # Se debe poder calcular el maximo de una matriz densa (elemento no nulo)" do
|
|
316
|
+
@md1.set(1,0,4)
|
|
317
|
+
@md1.max.should == 4
|
|
318
|
+
end
|
|
319
|
+
it " # Se debe poder calcular el minimo de una matriz densa (elemento no nulo)" do
|
|
320
|
+
@md1.min.should == 1
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Implementar en este fichero las Pruebas Unitarias de nuestra gema
|
|
2
|
+
|
|
3
|
+
require "./lib/math_expansion.rb"
|
|
4
|
+
require "test/unit"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Fixnum
|
|
8
|
+
def self.null
|
|
9
|
+
0
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class String
|
|
14
|
+
def self.null
|
|
15
|
+
""
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Float
|
|
20
|
+
def self.null
|
|
21
|
+
0.0
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Test_Matriz < Test::Unit::TestCase
|
|
27
|
+
def test_simple
|
|
28
|
+
@m1 = MathExpansion::Matriz_Densa.new(2,2)
|
|
29
|
+
@m2 = MathExpansion::Matriz_Densa.new(2,2)
|
|
30
|
+
@m3 = MathExpansion::Matriz_Densa.new(2,2)
|
|
31
|
+
|
|
32
|
+
@m1.set(0,0,1)
|
|
33
|
+
@m1.set(0,1,2)
|
|
34
|
+
@m1.set(1,0,3)
|
|
35
|
+
@m1.set(1,1,4)
|
|
36
|
+
|
|
37
|
+
@m2.set(0,0,5)
|
|
38
|
+
@m2.set(0,1,6)
|
|
39
|
+
@m2.set(1,0,7)
|
|
40
|
+
@m2.set(1,1,8)
|
|
41
|
+
|
|
42
|
+
@m3.set(0,0,6)
|
|
43
|
+
@m3.set(0,1,8)
|
|
44
|
+
@m3.set(1,0,10)
|
|
45
|
+
@m3.set(1,1,12)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
assert_equal(@m3.to_s,(@m1+@m2).to_s)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_simple2
|
|
52
|
+
@md1 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
53
|
+
@md2 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
54
|
+
@m3 = MathExpansion::Matriz_Dispersa.new(2,2)
|
|
55
|
+
|
|
56
|
+
@md1.set(0,0,0)
|
|
57
|
+
@md1.set(0,1,0)
|
|
58
|
+
@md1.set(1,0,5)
|
|
59
|
+
@md1.set(1,1,0)
|
|
60
|
+
|
|
61
|
+
@md2.set(0,0,0)
|
|
62
|
+
@md2.set(0,1,0)
|
|
63
|
+
@md2.set(1,0,3)
|
|
64
|
+
@md2.set(1,1,0)
|
|
65
|
+
|
|
66
|
+
@m3.set(0,0,0)
|
|
67
|
+
@m3.set(0,1,0)
|
|
68
|
+
@m3.set(1,0,2)
|
|
69
|
+
@m3.set(1,1,0)
|
|
70
|
+
|
|
71
|
+
assert_equal(@m3.to_s,(@md1-@md2).to_s)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_typecheck
|
|
77
|
+
@m1 = MathExpansion::Matriz_Densa.new(1,1)
|
|
78
|
+
@m2 = MathExpansion::Matriz_Densa.new(1,1)
|
|
79
|
+
@m1.set(0,0,5)
|
|
80
|
+
@m2.set(0,0,"hola")
|
|
81
|
+
|
|
82
|
+
assert_raise(TypeError) {@m1+@m2}
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_failure
|
|
86
|
+
@m1 = MathExpansion::Matriz_Densa.new(1,1)
|
|
87
|
+
@m2 = MathExpansion::Matriz_Densa.new(2,2)
|
|
88
|
+
|
|
89
|
+
assert_raise(ArgumentError) {@m1*@m2}
|
|
90
|
+
end
|
|
91
|
+
end
|