t50_matriz_dispersa_densa 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.
- data/Documentacion/Fraccion.html +816 -0
- data/Documentacion/Gemfile.html +109 -0
- data/Documentacion/LICENSE_txt.html +126 -0
- data/Documentacion/Matriz.html +405 -0
- data/Documentacion/Matriz_Dispersa.html +159 -0
- data/Documentacion/Matriz_densa.html +479 -0
- data/Documentacion/Object.html +212 -0
- data/Documentacion/Rakefile.html +114 -0
- data/Documentacion/SparseMatrix.html +775 -0
- data/Documentacion/SparseVector.html +307 -0
- data/Documentacion/T50MatrizDispersaDensa.html +167 -0
- data/Documentacion/TestMatrix.html +467 -0
- data/Documentacion/bin/t50_matriz_dispersa_densa.html +54 -0
- data/Documentacion/created.rid +13 -0
- data/Documentacion/images/brick.png +0 -0
- data/Documentacion/images/brick_link.png +0 -0
- data/Documentacion/images/bug.png +0 -0
- data/Documentacion/images/bullet_black.png +0 -0
- data/Documentacion/images/bullet_toggle_minus.png +0 -0
- data/Documentacion/images/bullet_toggle_plus.png +0 -0
- data/Documentacion/images/date.png +0 -0
- data/Documentacion/images/find.png +0 -0
- data/Documentacion/images/loadingAnimation.gif +0 -0
- data/Documentacion/images/macFFBgHack.png +0 -0
- data/Documentacion/images/package.png +0 -0
- data/Documentacion/images/page_green.png +0 -0
- data/Documentacion/images/page_white_text.png +0 -0
- data/Documentacion/images/page_white_width.png +0 -0
- data/Documentacion/images/plugin.png +0 -0
- data/Documentacion/images/ruby.png +0 -0
- data/Documentacion/images/tag_green.png +0 -0
- data/Documentacion/images/wrench.png +0 -0
- data/Documentacion/images/wrench_orange.png +0 -0
- data/Documentacion/images/zoom.png +0 -0
- data/Documentacion/index.html +172 -0
- data/Documentacion/js/darkfish.js +118 -0
- data/Documentacion/js/jquery.js +32 -0
- data/Documentacion/js/quicksearch.js +114 -0
- data/Documentacion/js/thickbox-compressed.js +10 -0
- data/Documentacion/lib/Fraccion_rb.html +54 -0
- data/Documentacion/lib/gcd_rb.html +52 -0
- data/Documentacion/lib/matriz_densa_rb.html +54 -0
- data/Documentacion/lib/matriz_dispersa_rb.html +58 -0
- data/Documentacion/lib/matriz_rb.html +58 -0
- data/Documentacion/lib/t50_matriz_dispersa_densa/version_rb.html +52 -0
- data/Documentacion/lib/t50_matriz_dispersa_densa_rb.html +72 -0
- data/Documentacion/rdoc.css +763 -0
- data/Documentacion/test/tc_matrix_rb.html +62 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +10 -0
- data/bin/t50_matriz_dispersa_densa +3 -0
- data/lib/Fraccion.rb +128 -0
- data/lib/gcd.rb +7 -0
- data/lib/matriz.rb +71 -0
- data/lib/matriz.rb~ +136 -0
- data/lib/matriz_densa.rb +128 -0
- data/lib/matriz_densa.rb~ +148 -0
- data/lib/matriz_dispersa.rb +276 -0
- data/lib/matriz_dispersa.rb~ +275 -0
- data/lib/t50_matriz_dispersa_densa.rb +27 -0
- data/lib/t50_matriz_dispersa_densa.rb~ +7 -0
- data/lib/t50_matriz_dispersa_densa/version.rb +3 -0
- data/t50_matriz_dispersa_densa.gemspec +19 -0
- data/test/tc_matrix.rb +57 -0
- data/test/tc_matrix.rb~ +57 -0
- metadata +115 -0
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
require 'Fraccion.rb'
|
|
2
|
+
require 'matriz.rb'
|
|
3
|
+
require "matrix"
|
|
4
|
+
|
|
5
|
+
class SparseVector
|
|
6
|
+
attr_reader :vector
|
|
7
|
+
|
|
8
|
+
def initialize(h = {})
|
|
9
|
+
@vector = Hash.new(0)
|
|
10
|
+
@vector = @vector.merge!(h)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def [](i)
|
|
14
|
+
@vector[i]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_s
|
|
18
|
+
@vector.to_s
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#Clase que se encarga de crear el hash
|
|
23
|
+
|
|
24
|
+
class SparseMatrix < Matriz
|
|
25
|
+
|
|
26
|
+
attr_reader :matrix
|
|
27
|
+
|
|
28
|
+
# Inicializador propio de la clase
|
|
29
|
+
def initialize(h = {})
|
|
30
|
+
@matrix = Hash.new({})
|
|
31
|
+
for k in h.keys do
|
|
32
|
+
@matrix[k] = if h[k].is_a? SparseVector
|
|
33
|
+
h[k]
|
|
34
|
+
else
|
|
35
|
+
@matrix[k] = SparseVector.new(h[k])
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Obtener un valor de la matriz dada una posicion
|
|
41
|
+
def [](i)
|
|
42
|
+
@matrix[i]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def col(j)
|
|
46
|
+
c = {}
|
|
47
|
+
for r in @matrix.keys do
|
|
48
|
+
c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j
|
|
49
|
+
end
|
|
50
|
+
SparseVector.new c
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def comprobar
|
|
54
|
+
contar = 0
|
|
55
|
+
contartotal = 0
|
|
56
|
+
result = 0
|
|
57
|
+
for r in @matrix.keys do
|
|
58
|
+
for j in @matrix[r].vector.keys do
|
|
59
|
+
contartotal = contartotal + 1
|
|
60
|
+
if @matrix[r].vector[j] == 0
|
|
61
|
+
contar = contar + 1
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
result = (contar * 100) / contartotal
|
|
66
|
+
if result < 60
|
|
67
|
+
"La matriz no es dispersa"
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def mostrar
|
|
72
|
+
for r in @matrix.keys do
|
|
73
|
+
for j in @matrix[r].vector.keys do
|
|
74
|
+
print "#{@matrix[r].vector[j]} "
|
|
75
|
+
end
|
|
76
|
+
puts
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Operacion de la suma en la matriz dispersa. Realiza la operacion entre dos matrices dispersa y una dispersa con una densa
|
|
81
|
+
|
|
82
|
+
def +(other)
|
|
83
|
+
case other
|
|
84
|
+
when Matriz_Dispersa
|
|
85
|
+
raise ArgumentError, "Las matrices no son iguales en longitud." unless @matrix.size == other.matrix.size && @matrix[1].vector.size == other.matrix[1].vector.size
|
|
86
|
+
resul = Array.new
|
|
87
|
+
@matrix.keys.times do |r|
|
|
88
|
+
r = r + 1
|
|
89
|
+
#for r in @matrix.keys do
|
|
90
|
+
resul_f = Array.new
|
|
91
|
+
1.upto(@matrix[r].vector.keys) do |j|
|
|
92
|
+
#for j in @matrix[r].vector.keys do
|
|
93
|
+
#print " #{@matrix[r].vector[j] + other.matrix[r].vector[j]} "
|
|
94
|
+
resul_f << @matrix[r].vector[j] + other.matrix[r].vector[j]
|
|
95
|
+
end
|
|
96
|
+
#puts
|
|
97
|
+
resul << resul_f
|
|
98
|
+
end
|
|
99
|
+
return resul
|
|
100
|
+
when Matriz_densa
|
|
101
|
+
raise ArgumentError, "Las matrices no son iguales en longitud." unless @matrix.size == other.f && @matrix[1].vector.size == other.c
|
|
102
|
+
resul = Array.new
|
|
103
|
+
1.upto(other.f) do |r|
|
|
104
|
+
#for r in 1..other.f do
|
|
105
|
+
resul_f = Array.new
|
|
106
|
+
1.upto(other.c) do |j|
|
|
107
|
+
#for j in 1..other.c do
|
|
108
|
+
#print " #{@matrix[r].vector[j] + other.m[r - 1][j - 1]}"
|
|
109
|
+
resul_f << @matrix[r].vector[j] + other.m[r - 1][j - 1]
|
|
110
|
+
end
|
|
111
|
+
#puts
|
|
112
|
+
resul << resul_f
|
|
113
|
+
end
|
|
114
|
+
return resul
|
|
115
|
+
else
|
|
116
|
+
raise TypeError.new("No se puede pasar #{other.inspect} a Matriz")
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Operacion de la resta en la matriz dispersa. Realiza la operacion entre dos matrices dispersa y una dispersa con una densa
|
|
121
|
+
def -(other)
|
|
122
|
+
case other
|
|
123
|
+
when Matriz_Dispersa
|
|
124
|
+
raise ArgumentError, "Las matrices no son iguales en longitud." unless @matrix.size == other.matrix.size && @matrix[1].vector.size == other.matrix[1].vector.size
|
|
125
|
+
resul = Array.new
|
|
126
|
+
#for r in @matrix.keys do
|
|
127
|
+
1.upto(@matrix.keys) do |r|
|
|
128
|
+
resul_f = Array.new
|
|
129
|
+
#for j in @matrix[r].vector.keys do
|
|
130
|
+
1.upto(@matrix[r].vector.keys) do |j|
|
|
131
|
+
#print " #{@matrix[r].vector[j] - other.matrix[r].vector[j]} "
|
|
132
|
+
resul_f << @matrix[r].vector[j] - other.matrix[r].vector[j]
|
|
133
|
+
end
|
|
134
|
+
#puts
|
|
135
|
+
resul << resul_f
|
|
136
|
+
end
|
|
137
|
+
return resul
|
|
138
|
+
when Matriz_densa
|
|
139
|
+
raise ArgumentError, "Las matrices no son iguales en longitud." unless @matrix.size == other.f && @matrix[1].vector.size == other.c
|
|
140
|
+
resul = Array.new
|
|
141
|
+
#for r in 1..other.f do
|
|
142
|
+
1.upto(other.f) do |r|
|
|
143
|
+
resul_f = Array.new
|
|
144
|
+
#for j in 1..other.c do
|
|
145
|
+
1.upto(other.c) do |j|
|
|
146
|
+
#print " #{@matrix[r].vector[j] - other.m[r - 1][j - 1]}"
|
|
147
|
+
resul_f << @matrix[r].vector[j] - other.m[r - 1][j - 1]
|
|
148
|
+
end
|
|
149
|
+
#puts
|
|
150
|
+
resul << resul_f
|
|
151
|
+
end
|
|
152
|
+
return resul
|
|
153
|
+
else
|
|
154
|
+
raise TypeError.new("No se puede pasar #{other.inspect} a Matriz")
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Operacion de la multiplicacion en la matriz dispersa. Realiza la operacion entre dos matrices dispersa y una dispersa con una densa
|
|
160
|
+
def *(other)
|
|
161
|
+
|
|
162
|
+
case other
|
|
163
|
+
when Matriz_Dispersa
|
|
164
|
+
raise ArgumentError, "Las columnas de una matriz no coinciden con las filas de la otra." unless @matrix[1].vector.size == other.matrix.size
|
|
165
|
+
sumatotal = 0
|
|
166
|
+
mul = Array.new
|
|
167
|
+
|
|
168
|
+
#for i in @matrix.keys do
|
|
169
|
+
1.upto(@matrix.keys) do |i|
|
|
170
|
+
mul_f = Array.new
|
|
171
|
+
#for j in @matrix[i].vector.keys do
|
|
172
|
+
1.upto(@matrix[i].vector.keys) do |j|
|
|
173
|
+
#for k in @matrix[i].vector.keys do
|
|
174
|
+
1.upto(@matrix[i].vector.keys) do |k|
|
|
175
|
+
suma = @matrix[i].vector[k] * other.matrix[k].vector[j]
|
|
176
|
+
sumatotal = sumatotal + suma;
|
|
177
|
+
end
|
|
178
|
+
mul_f << sumatotal
|
|
179
|
+
sumatotal = 0
|
|
180
|
+
end
|
|
181
|
+
mul << mul_f
|
|
182
|
+
end
|
|
183
|
+
=begin
|
|
184
|
+
for r in @matrix.keys do
|
|
185
|
+
for j in @matrix[r].vector.keys do
|
|
186
|
+
print " #{mul[r][j]} "
|
|
187
|
+
end
|
|
188
|
+
puts
|
|
189
|
+
end
|
|
190
|
+
=end
|
|
191
|
+
return mul
|
|
192
|
+
when Matriz_densa
|
|
193
|
+
raise ArgumentError, "Las columnas de una matriz no coinciden con las filas de la otra." unless @matrix[1].vector.size == other.f
|
|
194
|
+
sumatotal = 0
|
|
195
|
+
mul = Array.new
|
|
196
|
+
|
|
197
|
+
#for i in @matrix.keys do
|
|
198
|
+
1.upto(@matrix.size) do |i|
|
|
199
|
+
mul_f = Array.new
|
|
200
|
+
#for j in @matrix[i].vector.keys do
|
|
201
|
+
1.upto(@matrix[i].vector.size) do |j|
|
|
202
|
+
#for k in @matrix[i].vector.keys do
|
|
203
|
+
1.upto(@matrix[i].vector.size) do |k|
|
|
204
|
+
suma = @matrix[i].vector[k] * other.m[k - 1][j - 1]
|
|
205
|
+
sumatotal = sumatotal + suma;
|
|
206
|
+
end
|
|
207
|
+
mul_f << sumatotal
|
|
208
|
+
sumatotal = 0
|
|
209
|
+
end
|
|
210
|
+
mul << mul_f
|
|
211
|
+
end
|
|
212
|
+
=begin
|
|
213
|
+
for r in @matrix.keys do
|
|
214
|
+
for j in @matrix[r].vector.keys do
|
|
215
|
+
print " #{mul[r][j]} "
|
|
216
|
+
end
|
|
217
|
+
puts
|
|
218
|
+
end
|
|
219
|
+
=end
|
|
220
|
+
return mul
|
|
221
|
+
else
|
|
222
|
+
raise TypeError.new("No se puede pasar #{other.inspect} a Matriz")
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
def max
|
|
227
|
+
|
|
228
|
+
maximo = @matrix[1].vector[1]
|
|
229
|
+
|
|
230
|
+
#for i in @matrix.keys do
|
|
231
|
+
@matrix.size.times do |i|
|
|
232
|
+
i = i + 1
|
|
233
|
+
#for j in @matrix[i].vector.keys do
|
|
234
|
+
#@matrix[i].vector.keys do |j|
|
|
235
|
+
1.upto(@matrix[i].vector.size) do |j|
|
|
236
|
+
if @matrix[i].vector[j] > maximo
|
|
237
|
+
maximo = @matrix[i].vector[j]
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
return maximo
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def [](i,j)
|
|
245
|
+
|
|
246
|
+
return @matrix[i].vector[j]
|
|
247
|
+
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def min
|
|
251
|
+
|
|
252
|
+
minimo = @matrix[1].vector[1]
|
|
253
|
+
|
|
254
|
+
#for i in @matrix.keys do
|
|
255
|
+
1.upto(@matrix.size) do |i|
|
|
256
|
+
#for j in @matrix[i].vector.keys do
|
|
257
|
+
@matrix[i].vector.size.times do |j|
|
|
258
|
+
j = j + 1
|
|
259
|
+
if @matrix[i].vector[j] < minimo
|
|
260
|
+
minimo = @matrix[i].vector[j]
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
return minimo
|
|
265
|
+
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def coerce(other)
|
|
269
|
+
[other,self]
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
class Matriz_Dispersa < SparseMatrix
|
|
274
|
+
|
|
275
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
=begin rdoc
|
|
2
|
+
:main: t50_matriz_dispersa_densa.rb
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
= T50MatrizDispersaDensa
|
|
6
|
+
|
|
7
|
+
Autor:: Javier Clemente Rodriguez Gomez & Juan Lucas Gonzalez Hidalgo
|
|
8
|
+
Asignatura:: Lenguajes y paradigmas de la programacion.
|
|
9
|
+
Universidad de la Laguna
|
|
10
|
+
|
|
11
|
+
== Diseño
|
|
12
|
+
|
|
13
|
+
Se ha creado una clase matriz que solo tendra el inicializador y algunos métodos para operaciones con matrices básticas.
|
|
14
|
+
Se ha creado una clase Fraccion para poder representar estos en una matriz.
|
|
15
|
+
Se creo la clase Matriz_Dispersa y Matriz_densa que heredan de matriz y sirven para poder realizar operaciones con ese tipo concreto de matrices.
|
|
16
|
+
|
|
17
|
+
=end
|
|
18
|
+
|
|
19
|
+
require "t50_matriz_dispersa_densa/version"
|
|
20
|
+
require "matriz.rb"
|
|
21
|
+
require "matriz_dispersa.rb"
|
|
22
|
+
require "matriz_densa.rb"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
module T50MatrizDispersaDensa
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 't50_matriz_dispersa_densa/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = "t50_matriz_dispersa_densa"
|
|
8
|
+
gem.version = T50MatrizDispersaDensa::VERSION
|
|
9
|
+
gem.authors = ["Javier C"]
|
|
10
|
+
gem.email = ["alu0100505023@ull.edu.es"]
|
|
11
|
+
gem.description = %q{"Operaciones con matrices"}
|
|
12
|
+
gem.summary = %q{"Operaciones con matrices densas y dispersas"}
|
|
13
|
+
gem.homepage = ""
|
|
14
|
+
|
|
15
|
+
gem.files = `git ls-files`.split($/)
|
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
18
|
+
gem.require_paths = ["lib"]
|
|
19
|
+
end
|
data/test/tc_matrix.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "Fraccion.rb"
|
|
2
|
+
require 'gcd.rb'
|
|
3
|
+
require 'matriz_dispersa.rb'
|
|
4
|
+
require 'matriz_densa.rb'
|
|
5
|
+
require "test/unit"
|
|
6
|
+
|
|
7
|
+
class TestMatrix < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
#Se especifican los hash a usar en las pruebas
|
|
11
|
+
@h = Matriz_Dispersa.new 1 => {1 => 33, 2 => 44}, 2 => {1 => 66, 2 => 77}
|
|
12
|
+
@h2 = Matriz_Dispersa.new 1 => {1 => 1, 2 => 2}, 2 => {1 => 1, 2 => 2}
|
|
13
|
+
|
|
14
|
+
#Se especifican los hash a usar en las pruebas con fracciones
|
|
15
|
+
@h3 = Matriz_Dispersa.new 1 => {1 => Fraccion.new(33,2), 2 => Fraccion.new(44,3)}, 2 => {1 => Fraccion.new(66,5), 2 => Fraccion.new(77,12)}
|
|
16
|
+
@h4 = Matriz_Dispersa.new 1 => {1 => 1, 2 => 2}, 2 => {1 => 1, 2 => 2}
|
|
17
|
+
@h5 = Matriz_Dispersa.new 1 => {1 => Fraccion.new(1,1), 2 => Fraccion.new(2,1)}, 2 => {1 => Fraccion.new(1,1), 2 => Fraccion.new(2,1)}
|
|
18
|
+
@h6 = Matriz_densa.new(2,2,[[4,3],[5,8]])
|
|
19
|
+
|
|
20
|
+
@h9 = Matriz_densa.new(2,2,[[4,5],[2,3]])
|
|
21
|
+
@h10 = Matriz_Dispersa.new 1 => {1 => 0, 2 => 0}, 2 => {1 => 0, 2 => Fraccion.new(1,2)}
|
|
22
|
+
@h11 = Matriz_densa.new(2,2,[[4,5],[2,Fraccion.new(7,2)]])
|
|
23
|
+
@h12 = Matriz_densa.new(2,2,[[-4,-5],[-2,Fraccion.new(-5,2)]])
|
|
24
|
+
@h13 = Matriz_densa.new(2,2,[[0,0],[Fraccion.new(1,1),Fraccion.new(3,2)]])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_suma_densa_dispersa
|
|
28
|
+
assert_equal(@h11.m, @h9+@h10, "Resultado Incorrecto" )
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_resta_densa_dispersa
|
|
32
|
+
assert_equal(@h12.m, @h9-@h10, "Resultado Incorrecto" )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_multi_densa_dispersa
|
|
36
|
+
assert_equal(@h13.m, @h9*@h10, "Resultado Incorrecto" )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_max_dispersa
|
|
40
|
+
assert_equal(Fraccion.new(77,12), @h3.max, "Resultado Incorrecto" )
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_min_dispersa #mirar
|
|
44
|
+
assert_equal(Fraccion.new(66,5), @h3.min, "Resultado Incorrecto" )
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_max_densa
|
|
48
|
+
assert_equal(8, @h6.max, "Resultado Incorrecto" )
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_min_densa
|
|
52
|
+
assert_equal(3, @h6.min, "Resultado Incorrecto" )
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
data/test/tc_matrix.rb~
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "../lib/Fraccion.rb"
|
|
2
|
+
require 'lib/gcd.rb'
|
|
3
|
+
require 'lib/matriz_dispersa.rb'
|
|
4
|
+
require 'lib/matriz_densa.rb'
|
|
5
|
+
require "test/unit"
|
|
6
|
+
|
|
7
|
+
class TestMatrix < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
#Se especifican los hash a usar en las pruebas
|
|
11
|
+
@h = Matriz_Dispersa.new 1 => {1 => 33, 2 => 44}, 2 => {1 => 66, 2 => 77}
|
|
12
|
+
@h2 = Matriz_Dispersa.new 1 => {1 => 1, 2 => 2}, 2 => {1 => 1, 2 => 2}
|
|
13
|
+
|
|
14
|
+
#Se especifican los hash a usar en las pruebas con fracciones
|
|
15
|
+
@h3 = Matriz_Dispersa.new 1 => {1 => Fraccion.new(33,2), 2 => Fraccion.new(44,3)}, 2 => {1 => Fraccion.new(66,5), 2 => Fraccion.new(77,12)}
|
|
16
|
+
@h4 = Matriz_Dispersa.new 1 => {1 => 1, 2 => 2}, 2 => {1 => 1, 2 => 2}
|
|
17
|
+
@h5 = Matriz_Dispersa.new 1 => {1 => Fraccion.new(1,1), 2 => Fraccion.new(2,1)}, 2 => {1 => Fraccion.new(1,1), 2 => Fraccion.new(2,1)}
|
|
18
|
+
@h6 = Matriz_densa.new(2,2,[[4,3],[5,8]])
|
|
19
|
+
|
|
20
|
+
@h9 = Matriz_densa.new(2,2,[[4,5],[2,3]])
|
|
21
|
+
@h10 = Matriz_Dispersa.new 1 => {1 => 0, 2 => 0}, 2 => {1 => 0, 2 => Fraccion.new(1,2)}
|
|
22
|
+
@h11 = Matriz_densa.new(2,2,[[4,5],[2,Fraccion.new(7,2)]])
|
|
23
|
+
@h12 = Matriz_densa.new(2,2,[[-4,-5],[-2,Fraccion.new(-5,2)]])
|
|
24
|
+
@h13 = Matriz_densa.new(2,2,[[0,0],[Fraccion.new(1,1),Fraccion.new(3,2)]])
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_suma_densa_dispersa
|
|
28
|
+
assert_equal(@h11.m, @h9+@h10, "Resultado Incorrecto" )
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_resta_densa_dispersa
|
|
32
|
+
assert_equal(@h12.m, @h9-@h10, "Resultado Incorrecto" )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_multi_densa_dispersa
|
|
36
|
+
assert_equal(@h13.m, @h9*@h10, "Resultado Incorrecto" )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_max_dispersa
|
|
40
|
+
assert_equal(Fraccion.new(77,12), @h3.max, "Resultado Incorrecto" )
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_min_dispersa #mirar
|
|
44
|
+
assert_equal(Fraccion.new(66,5), @h3.min, "Resultado Incorrecto" )
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_max_densa
|
|
48
|
+
assert_equal(8, @h6.max, "Resultado Incorrecto" )
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_min_densa
|
|
52
|
+
assert_equal(3, @h6.min, "Resultado Incorrecto" )
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|