modai_prct12 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +9 -0
  5. data/Guardfile +346 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +31 -0
  8. data/Rakefile +6 -0
  9. data/documentacion/classes/MatrizAbstracta.html +144 -0
  10. data/documentacion/classes/MatrizAbstracta.src/M000032.html +21 -0
  11. data/documentacion/classes/MatrizDSL.html +212 -0
  12. data/documentacion/classes/MatrizDSL.src/M000028.html +36 -0
  13. data/documentacion/classes/MatrizDSL.src/M000029.html +20 -0
  14. data/documentacion/classes/MatrizDSL.src/M000030.html +27 -0
  15. data/documentacion/classes/MatrizDSL.src/M000031.html +40 -0
  16. data/documentacion/classes/MatrizDensa.html +345 -0
  17. data/documentacion/classes/MatrizDensa.src/M000016.html +18 -0
  18. data/documentacion/classes/MatrizDensa.src/M000017.html +37 -0
  19. data/documentacion/classes/MatrizDensa.src/M000018.html +27 -0
  20. data/documentacion/classes/MatrizDensa.src/M000019.html +44 -0
  21. data/documentacion/classes/MatrizDensa.src/M000020.html +41 -0
  22. data/documentacion/classes/MatrizDensa.src/M000021.html +29 -0
  23. data/documentacion/classes/MatrizDensa.src/M000022.html +37 -0
  24. data/documentacion/classes/MatrizDensa.src/M000023.html +28 -0
  25. data/documentacion/classes/MatrizDensa.src/M000024.html +28 -0
  26. data/documentacion/classes/MatrizDensa.src/M000025.html +35 -0
  27. data/documentacion/classes/MatrizDensa.src/M000026.html +18 -0
  28. data/documentacion/classes/MatrizDensa.src/M000027.html +37 -0
  29. data/documentacion/classes/MatrizDispersa.html +314 -0
  30. data/documentacion/classes/MatrizDispersa.src/M000033.html +22 -0
  31. data/documentacion/classes/MatrizDispersa.src/M000034.html +49 -0
  32. data/documentacion/classes/MatrizDispersa.src/M000035.html +33 -0
  33. data/documentacion/classes/MatrizDispersa.src/M000036.html +64 -0
  34. data/documentacion/classes/MatrizDispersa.src/M000037.html +66 -0
  35. data/documentacion/classes/MatrizDispersa.src/M000038.html +53 -0
  36. data/documentacion/classes/MatrizDispersa.src/M000039.html +31 -0
  37. data/documentacion/classes/MatrizDispersa.src/M000040.html +31 -0
  38. data/documentacion/classes/MatrizDispersa.src/M000041.html +35 -0
  39. data/documentacion/classes/MatrizDispersa.src/M000042.html +18 -0
  40. data/documentacion/classes/ModaiPrct12.html +147 -0
  41. data/documentacion/classes/Racional.html +380 -0
  42. data/documentacion/classes/Racional.src/M000002.html +24 -0
  43. data/documentacion/classes/Racional.src/M000003.html +18 -0
  44. data/documentacion/classes/Racional.src/M000004.html +22 -0
  45. data/documentacion/classes/Racional.src/M000005.html +18 -0
  46. data/documentacion/classes/Racional.src/M000006.html +18 -0
  47. data/documentacion/classes/Racional.src/M000007.html +18 -0
  48. data/documentacion/classes/Racional.src/M000008.html +18 -0
  49. data/documentacion/classes/Racional.src/M000009.html +23 -0
  50. data/documentacion/classes/Racional.src/M000010.html +23 -0
  51. data/documentacion/classes/Racional.src/M000011.html +23 -0
  52. data/documentacion/classes/Racional.src/M000012.html +23 -0
  53. data/documentacion/classes/Racional.src/M000013.html +23 -0
  54. data/documentacion/classes/Racional.src/M000014.html +19 -0
  55. data/documentacion/classes/Racional.src/M000015.html +18 -0
  56. data/documentacion/created.rid +1 -0
  57. data/documentacion/files/lib/modai_prct12/gcd_rb.html +132 -0
  58. data/documentacion/files/lib/modai_prct12/gcd_rb.src/M000001.html +22 -0
  59. data/documentacion/files/lib/modai_prct12/matrizAbstracta_rb.html +108 -0
  60. data/documentacion/files/lib/modai_prct12/matrizDSL_rb.html +105 -0
  61. data/documentacion/files/lib/modai_prct12/matrizDensa_rb.html +105 -0
  62. data/documentacion/files/lib/modai_prct12/matrizDispersa_rb.html +106 -0
  63. data/documentacion/files/lib/modai_prct12/racional_rb.html +114 -0
  64. data/documentacion/files/lib/modai_prct12/version_rb.html +101 -0
  65. data/documentacion/files/lib/modai_prct12_rb.html +112 -0
  66. data/documentacion/files/spec/modai_prct12_spec_rb.html +116 -0
  67. data/documentacion/files/spec/spec_helper_rb.html +114 -0
  68. data/documentacion/fr_class_index.html +32 -0
  69. data/documentacion/fr_file_index.html +36 -0
  70. data/documentacion/fr_method_index.html +68 -0
  71. data/documentacion/index.html +24 -0
  72. data/documentacion/rdoc-style.css +208 -0
  73. data/lib/modai_prct12.rb +26 -0
  74. data/lib/modai_prct12/gcd.rb +9 -0
  75. data/lib/modai_prct12/matrizAbstracta.rb +30 -0
  76. data/lib/modai_prct12/matrizDSL.rb +120 -0
  77. data/lib/modai_prct12/matrizDensa.rb +232 -0
  78. data/lib/modai_prct12/matrizDispersa.rb +280 -0
  79. data/lib/modai_prct12/racional.rb +121 -0
  80. data/lib/modai_prct12/version.rb +3 -0
  81. data/modai_prct12.gemspec +23 -0
  82. data/spec/modai_prct12_spec.rb +251 -0
  83. data/spec/spec_helper.rb +17 -0
  84. metadata +157 -0
@@ -0,0 +1,280 @@
1
+ #= La clase de Matriz dispersa,
2
+ #== Una matriz se considerará dispersa si tiene más de un 60% de ceros.
3
+ class MatrizDispersa < MatrizAbstracta
4
+
5
+ #== Inicialización
6
+ def initialize(matriz)
7
+
8
+ @matriz = matriz
9
+ @filas = matriz.size
10
+ @columnas = matriz.size
11
+
12
+ end
13
+
14
+ attr_reader :matriz, :filas, :columnas
15
+
16
+ #== Convertimos a string
17
+ def to_s
18
+
19
+ fil = 0
20
+ print "["
21
+ while fil < filas
22
+
23
+ col = 0
24
+ while col < columnas
25
+
26
+ # Hay datos en la fila
27
+ if matriz[fil] != nil
28
+
29
+ if matriz[fil].has_key?(col)
30
+ print "#{matriz[fil][col].to_s}"
31
+ else
32
+ print "0"
33
+ end
34
+ else
35
+ print "0"
36
+ end
37
+
38
+ if (col + 1) < columnas then print ", " end
39
+ col += 1
40
+
41
+ end
42
+
43
+
44
+ if (fil + 1) < filas then print ", " end
45
+ fil += 1
46
+
47
+ end
48
+ print "]"
49
+
50
+ end
51
+
52
+ #== Matriz en punto flotante
53
+ def to_f
54
+
55
+ flotante = Array.new(matriz.size - 1)
56
+ for i in 0...matriz.size
57
+ #=== Hay datos en la fila
58
+ if matriz[i] != nil
59
+
60
+ flotante[i] = Hash.new()
61
+ matriz[i].each do |key, value|
62
+ flotante[i][key] = matriz[i][key].to_f
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ MatrizDispersa.new(flotante)
69
+
70
+ end
71
+
72
+ #== Suma de matrices
73
+ def +(o)
74
+
75
+ suma = Array.new(matriz.size - 1)
76
+
77
+ i = 0
78
+ (matriz.size - 1).times do
79
+
80
+ #=== creamos el hash
81
+ if (matriz[i] != nil or o.matriz[i] != nil)
82
+
83
+ suma[i] = Hash.new()
84
+
85
+ case true
86
+
87
+ #=== Los dos tienen hash
88
+ when (matriz[i] != nil and o.matriz[i] != nil)
89
+
90
+ #=== cogemos matriz como base para la suma
91
+ suma[i] = matriz[i]
92
+
93
+ o.matriz[i].each do |key, value|
94
+
95
+ if suma[i].has_key?(key)
96
+ suma[i][key] = suma[i][key] + o.matriz[i][key]
97
+ else
98
+ suma[i][key] = o.matriz[i][key]
99
+ end
100
+
101
+ end
102
+
103
+ #=== matriz tiene hash
104
+ when matriz[i] != nil
105
+ suma[i] = matriz[i]
106
+
107
+ #=== .. o hash
108
+ when o.matriz[i] != nil
109
+ suma[i] = o.matriz[i]
110
+
111
+
112
+ end
113
+
114
+ end
115
+
116
+ i += 1
117
+
118
+ end
119
+ MatrizDispersa.new(suma)
120
+
121
+ end
122
+
123
+ #== Resta de matrices
124
+ def -(o)
125
+
126
+ resta = Array.new(matriz.size - 1)
127
+
128
+ i = 0
129
+ (matriz.size - 1).times do
130
+
131
+ #=== creamos el hash
132
+ if (matriz[i] != nil or o.matriz[i] != nil)
133
+
134
+ resta[i] = Hash.new()
135
+
136
+ case true
137
+
138
+ #=== Los dos tienen hash
139
+ when (matriz[i] != nil and o.matriz[i] != nil)
140
+
141
+ #=== cogemos matriz como base para la resta
142
+ resta[i] = matriz[i]
143
+
144
+ o.matriz[i].each do |key, value|
145
+
146
+ if resta[i].has_key?(key)
147
+ resta[i][key] = resta[i][key] - o.matriz[i][key]
148
+ else
149
+ resta[i][key] = o.matriz[i][key] * -1
150
+ end
151
+
152
+ end
153
+
154
+ #=== matriz tiene hash
155
+ when matriz[i] != nil
156
+ resta[i] = matriz[i]
157
+
158
+ #===... o hash
159
+ when o.matriz[i] != nil
160
+ resta[i] = o.matriz[i]
161
+ resta[i].each do |key, value|
162
+ resta[i][key] = resta[i][key] * -1
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+
169
+ i += 1
170
+
171
+ end
172
+ MatrizDispersa.new(resta)
173
+
174
+ end
175
+
176
+
177
+ #== Producto de matrices
178
+ def *(o)
179
+
180
+ prod = Array.new(matriz.size - 1)
181
+
182
+ i = 0
183
+ (0...(matriz.size)).inject {
184
+
185
+ #=== creamos el hash si hay filas en el multiplicador
186
+ if (o.matriz[i] != nil)
187
+
188
+ prod[i] = Hash.new()
189
+ #=== cogemos o como base para el producto
190
+ prod[i] = o.matriz[i]
191
+
192
+ for j in 0...matriz.size
193
+
194
+ if o.matriz[i].has_key?(j)
195
+
196
+ if matriz[j].has_key?(i)
197
+ prod[i][j] = prod[i][j] + (prod[i][j] * matriz[j][i])
198
+ else
199
+ prod[i].delete(j)
200
+ end
201
+
202
+ else
203
+ prod[i].delete(j)
204
+ end
205
+
206
+ end
207
+
208
+ end
209
+
210
+ i += 1
211
+
212
+ }
213
+ MatrizDispersa.new(prod)
214
+
215
+ end
216
+
217
+ #== Máximo de matriz
218
+ def max
219
+
220
+ maximo = 0.to_f
221
+ for i in 0...matriz.size
222
+ #=== Hay datos en la fila
223
+ if matriz[i] != nil
224
+ matriz[i].each do |key, value|
225
+ if matriz[i][key].to_f > maximo
226
+ maximo = matriz[i][key].to_f
227
+ end
228
+ end
229
+ end
230
+ end
231
+ maximo
232
+
233
+ end
234
+
235
+ #== Minimo de matriz
236
+ def min
237
+
238
+ minimo = 0.to_f
239
+ for i in 0...matriz.size
240
+ #=== Hay datos en la fila
241
+ if matriz[i] != nil
242
+ matriz[i].each do |key, value|
243
+ if matriz[i][key].to_f < minimo
244
+ minimo = matriz[i][key].to_f
245
+ end
246
+ end
247
+ end
248
+ end
249
+ minimo
250
+
251
+ end
252
+
253
+ #== Pasamos de Dispersa a Densa
254
+ def to_densa
255
+
256
+ densa = Array.new(matriz.size - 1)
257
+ for i in 0...matriz.size
258
+ densa[i] = Array.new(matriz[i].size - 1)
259
+ for j in 0...matriz[i].size
260
+ densa[i][j] = 0.to_f
261
+ if matriz[i] != nil
262
+ matriz[i].each do |key, value|
263
+ if key = j
264
+ densa[i][j] = matriz[i][key].to_f
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end
270
+
271
+ MatrizDensa.new(densa)
272
+
273
+ end
274
+
275
+ #== El metodo coerce para onvierte el valor especificado en el tipo especificado.
276
+ def coerce(other)
277
+ return self, other.to_densa
278
+ end
279
+
280
+ end
@@ -0,0 +1,121 @@
1
+ # racional.rb
2
+ require "./lib/modai_prct12/gcd.rb"
3
+
4
+ #=Implemente una clase Ruby para representar los números racionales.
5
+ #===Un número racional es un número con un numerador y un denominador de la forma. a/b
6
+ class Racional
7
+
8
+ include Comparable
9
+
10
+ #== Se inicializa la fracción en su forma reducida haciendo uso de gcd
11
+ def initialize(num, denom)
12
+
13
+ raise TypeError, "El denominador debe ser mayor que cero" unless (denom != 0)
14
+
15
+ div = gcd(num, denom)
16
+ @num = num/div
17
+ @denom = denom/div
18
+
19
+ end
20
+
21
+ #== Gets y Sets de @num y @denom
22
+ attr_reader :num, :denom
23
+
24
+ #== mostar por la consola la fraccion de la forma: a/b
25
+ def to_s
26
+ "#{num}/#{denom}"
27
+ end
28
+
29
+ #== comparar que dos fracciones son iguales
30
+ def ==(o)
31
+ if o.instance_of? Racional
32
+ @num == o.num && @denom == o.denom
33
+ else
34
+ false
35
+ end
36
+ end
37
+
38
+ #== Mostar la fraccion en formato flotante
39
+ def to_f
40
+ num.to_f/denom
41
+ end
42
+
43
+ #== Calcular el valor absoluto de una fraccion con el metodo abs
44
+ def abs
45
+ Racional.new(num.abs, denom.abs)
46
+ end
47
+
48
+ #== calcular el reciproco de una fraccion con el metodo reciprocal
49
+ def reciprocal
50
+ Racional.new(denom, num)
51
+ end
52
+
53
+ #== Calcular el opuesto de una fraccion con -
54
+ def -@
55
+ Racional.new(-denom, num)
56
+ end
57
+
58
+ #== suma dos fracciones con + y dar el resultado de forma reducida
59
+ def +(o)
60
+
61
+ if o.is_a? Integer
62
+ o = Racional.new(o,1)
63
+ end
64
+ Racional.new(num*o.denom + o.num*denom, denom*o.denom)
65
+
66
+ end
67
+
68
+ #== resta dos fracciones con - y dar el resultado de forma reducida
69
+ def -(o)
70
+
71
+ if o.is_a? Integer
72
+ o = Racional.new(o,1)
73
+ end
74
+ Racional.new(num*o.denom - o.num*denom, denom*o.denom)
75
+
76
+ end
77
+
78
+ #== multiplica dos fracciones con * y dar el resultado de forma reducida
79
+ def *(o)
80
+
81
+ if o.is_a? Integer
82
+ o = Racional.new(o,1)
83
+ end
84
+ Racional.new(num*o.num,denom*o.denom)
85
+
86
+ end
87
+
88
+ #== Divide dos fracciones con / y dar el resultado de forma reducida
89
+ def /(o)
90
+
91
+ if o.is_a? Integer
92
+ o = Racional.new(o,1)
93
+ end
94
+ Racional.new(num*o.denom,denom*o.num)
95
+
96
+ end
97
+
98
+ #== Calcula el resto dos fracciones con % y dar el resultado de forma reducida
99
+ def %(o)
100
+
101
+ if o.is_a? Integer
102
+ o = Racional.new(o,1)
103
+ end
104
+ Racional.new(num%denom, o.num%o.denom)
105
+
106
+ end
107
+
108
+ #== GERRA DE LAS GALAXIAS : un metodo que proporciona la comparación de mayor, mayor igual, menor, menor igual
109
+ def <=>(o)
110
+ return nil unless o.instance_of? Racional
111
+ (num.to_f / denom) <=> (o.num.to_f / o.denom)
112
+ end
113
+
114
+ #== El metodo coerce para onvierte el valor especificado en el tipo especificado.
115
+ def coerce(other)
116
+ return Racional.new(other,1), self
117
+ end
118
+
119
+ end
120
+
121
+
@@ -0,0 +1,3 @@
1
+ module ModaiPrct12
2
+ VERSION = "0.0.22"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'modai_prct12/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "modai_prct12"
8
+ spec.version = ModaiPrct12::VERSION
9
+ spec.authors = ["Dailos Herrera Bencomo y Mohammed Mahrach"]
10
+ spec.email = ["alu0100036862@etsii.ull.es"]
11
+ spec.description = %q{Simply generates modai_prct12 ipsum text.}
12
+ spec.summary = %q{modai_prct12 ipsum generator}
13
+ spec.homepage = ""
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
+ end
@@ -0,0 +1,251 @@
1
+ require 'spec_helper'
2
+ require 'modai_prct12'
3
+ include ModaiPrct12
4
+
5
+ describe ModaiPrct12 do
6
+
7
+ before :each do
8
+
9
+ #== Matrices DENSAS
10
+ matA = [[1,2],[3,4]]
11
+ matB = [[221,2],[3,4]]
12
+
13
+ matA_R = [[Racional.new(1,1),Racional.new(4,2)],[Racional.new(9,3),Racional.new(16,4)]]
14
+ matB_R = [[Racional.new(442,2),Racional.new(4,2)],[Racional.new(9,3),Racional.new(16,4)]]
15
+
16
+ @matrizA = MatrizDensa.new(matA)
17
+ @matrizB = MatrizDensa.new(matB)
18
+
19
+ @matrizA_R = MatrizDensa.new(matA_R)
20
+ @matrizB_R = MatrizDensa.new(matB_R)
21
+
22
+ #== Matrices DISPERSAS
23
+ matC = [nil, {1 => 4}] # [[0,0],[0,4]]
24
+ matD = [{0 => 5}, nil] # [[5,0],[0,0]]
25
+ matE = [{0 => 1}, {1 => 2}, {2 => 3}, {3 => 4}] # [[1,0,0,0],[0,2,0,0],[0,0,3,0],[0,0,0,4]]
26
+ matF = [{1 => 5, 3 => 4}, {1 => 2}, {0 => 3}, {2 => 1}] # [[0,5,0,4],[0,2,0,0],[3,0,0,0],[0,0,1,0]]
27
+
28
+ matC_R = [nil, {1 => Racional.new(4,1)}] # [[Racional.new(0,1),Racional.new(0,1)],[Racional.new(0,1),Racional.new(4,1)]]
29
+ matD_R = [{0 => Racional.new(5,1)}, nil] # [[Racional.new(5,1),Racional.new(0,1)],[Racional.new(0,1),Racional.new(0,1)]]
30
+
31
+ @matrizC = MatrizDispersa.new(matC)
32
+ @matrizD = MatrizDispersa.new(matD)
33
+ @matrizE = MatrizDispersa.new(matE)
34
+ @matrizF = MatrizDispersa.new(matF)
35
+
36
+ @matrizC_R = MatrizDispersa.new(matC_R)
37
+ @matrizD_R = MatrizDispersa.new(matD_R)
38
+
39
+ #== Matrices creadas en horas de practicas
40
+ matA_P_DEN = [[3.4],[5.6]]
41
+ matB_P_DIS = [nil,{1 => 1}]
42
+ matB_R_DIS = [nil,{1 => Racional.new(1,2)}]
43
+
44
+ @matrizA_P_DEN = MatrizDensa.new(matA_P_DEN)
45
+ @matrizB_P_DIS = MatrizDispersa.new(matB_P_DIS)
46
+ @matrizB_R_DIS = MatrizDispersa.new(matB_R_DIS)
47
+
48
+ #== Matriz creada en hora de practica PRACT11
49
+ matPRACT = [[1,2,9],[7,8,4]]
50
+ @matrizPRACT = MatrizDensa.new(matPRACT)
51
+
52
+ end
53
+
54
+ context 'comprobar los accessors (DENSA)' do
55
+
56
+ it "Se debe invocar al metodo matriz() para obtener la matriz (DENSA)" do
57
+ @matrizA.respond_to?("matriz").should == true
58
+ end
59
+
60
+ it "Se debe invocar al metodo filas() para obtener el numero de filas (DENSA)" do
61
+ @matrizA.respond_to?("filas").should == true
62
+ end
63
+
64
+ it "Se debe invocar al metodo columnas() para obtener el numero de columnas (DENSA)" do
65
+ @matrizA.respond_to?("columnas").should == true
66
+ end
67
+
68
+ it "Se debe invocar al metodo matriz() para obtener la matriz de racionales (DENSA)" do
69
+ @matrizA_R.respond_to?("matriz").should == true
70
+ end
71
+
72
+ it "Se debe invocar al metodo filas() para obtener el numero de filas de matriz de racionales (DENSA)" do
73
+ @matrizA_R.respond_to?("filas").should == true
74
+ end
75
+
76
+ it "Se debe invocar al metodo columnas() para obtener el numero de columnas de matriz de racionales (DENSA)" do
77
+ @matrizA_R.respond_to?("columnas").should == true
78
+ end
79
+
80
+ end
81
+
82
+ context 'Comprobar metodos de conversion (DENSA)' do
83
+
84
+ it "Se debe mostrar la matriz (DENSA)" do
85
+ @matrizA.to_s.should == MatrizDensa.new([[1,2],[3,4]]).to_s
86
+ end
87
+
88
+ it "Se debe convertir a punto flotantes (DENSA)" do
89
+ @matrizA.to_f.to_s.should == MatrizDensa.new([[1.0,2.0],[3.0,4.0]]).to_s
90
+ end
91
+
92
+ it "Se debe mostrar la matriz de racionales (DENSA)" do
93
+ @matrizA_R.to_s.should == MatrizDensa.new([[Racional.new(1,1),Racional.new(4,2)],[Racional.new(9,3),Racional.new(16,4)]]).to_s
94
+ end
95
+
96
+ end
97
+
98
+ context 'Comprobar las operaciones entre matrices (DENSA)' do
99
+
100
+ it "Se debe poder sumar dos matrices (DENSA)" do
101
+ (@matrizA + @matrizB).to_s.should == MatrizDensa.new([[222,4], [6,8]]).to_s
102
+ end
103
+
104
+ it "Se debe poder restar dos matrices (DENSA)" do
105
+ (@matrizA - @matrizB).to_s.should == MatrizDensa.new([[-220,0], [0,0]]).to_s
106
+ end
107
+
108
+ it "Se debe poder multiplicar dos matrices (DENSA)" do
109
+ (@matrizA * @matrizB).to_s.should == MatrizDensa.new([[227,10], [675,22]]).to_s
110
+ end
111
+
112
+ it "Se debe poder sumar dos matrices de racionales (DENSA)" do
113
+ (@matrizA_R + @matrizB_R).to_s.should == MatrizDensa.new([[Racional.new(222,1),Racional.new(4,1)],[Racional.new(6,1),Racional.new(8,1)]]).to_s
114
+ end
115
+
116
+ it "Se debe poder restar dos matrices de racionales (DENSA)" do
117
+ (@matrizA_R - @matrizB_R).to_s.should == MatrizDensa.new([[Racional.new(-220,1),Racional.new(0,1)],[Racional.new(0,1),Racional.new(0,1)]]).to_s
118
+ end
119
+
120
+ end
121
+
122
+ context 'Comprobar las operaciones de la propia matriz (DENSA)' do
123
+
124
+ it "Se debe mostrar el max de la matriz (DENSA)" do
125
+ @matrizA.max == 4.0
126
+ end
127
+
128
+ it "Se debe mostrar el min de la matriz (DENSA)" do
129
+ @matrizA.min == 1.0
130
+ end
131
+
132
+ it "Se debe mostrar el max de la matriz de racionales (DENSA)" do
133
+ @matrizA_R.max == Racional.new(1,1)
134
+ end
135
+
136
+ it "Se debe mostrar el min de la matriz de racionales (DENSA)" do
137
+ @matrizA_R.min == Racional.new(16,4)
138
+ end
139
+
140
+ end
141
+
142
+ context 'comprobar los accessors (DISPERSA)' do
143
+
144
+ it "Se debe invocar al metodo matriz() para obtener la matriz (DISPERSA)" do
145
+ @matrizC.respond_to?("matriz").should == true
146
+ end
147
+
148
+ it "Se debe invocar al metodo filas() para obtener el numero de filas (DISPERSA)" do
149
+ @matrizC.respond_to?("filas").should == true
150
+ end
151
+
152
+ it "Se debe invocar al metodo columnas() para obtener el numero de columnas (DISPERSA)" do
153
+ @matrizC.respond_to?("columnas").should == true
154
+ end
155
+
156
+ it "Se debe invocar al metodo matriz() para obtener la matriz de racionales (DISPERSA)" do
157
+ @matrizC_R.respond_to?("matriz").should == true
158
+ end
159
+
160
+ it "Se debe invocar al metodo filas() para obtener el numero de filas de matriz de racionales (DISPERSA)" do
161
+ @matrizC_R.respond_to?("filas").should == true
162
+ end
163
+
164
+ it "Se debe invocar al metodo columnas() para obtener el numero de columnas de matriz de racionales (DISPERSA)" do
165
+ @matrizC_R.respond_to?("columnas").should == true
166
+ end
167
+
168
+ end
169
+
170
+ context 'Comprobar metodos de conversion (DISPERSA)' do
171
+
172
+ it "Se debe mostrar la matriz (DISPERSA)" do
173
+ @matrizC.to_s.should == MatrizDispersa.new([nil, {1 => 4}]).to_s
174
+ end
175
+
176
+ it "Se debe convertir a punto flotantes (DISPERSA)" do
177
+ @matrizC.to_f.to_s.should == MatrizDispersa.new([nil, {1 => 4.0}]).to_s
178
+ end
179
+
180
+ it "Se debe mostrar la matriz de racionales (DISPERSA)" do
181
+ @matrizC_R.to_s.should == MatrizDispersa.new([nil, {1 => Racional.new(4,1)}]).to_s
182
+ end
183
+
184
+ end
185
+
186
+ context 'Comprobar las operaciones entre matrices (DISPERSA)' do
187
+
188
+
189
+ it "Se debe poder sumar dos matrices (DISPERSA)" do
190
+ (@matrizC + @matrizC).to_s.should == MatrizDispersa.new([{0 => 5}, {1 => 4}]).to_s
191
+ end
192
+
193
+ it "Se debe poder restar dos matrices (DISPERSA)" do
194
+ (@matrizC - @matrizC).to_s.should == MatrizDispersa.new([{0 => -5}, {1 => 4}]).to_s
195
+ end
196
+
197
+ it "Se debe poder multiplicar dos matrices (DISPERSA)" do
198
+ (@matrizE * @matrizF).to_s.should == MatrizDispersa.new([{1 => 5, 3 => 4}, {1 => 4}, {0 => 9}, {2 => 4}]).to_s
199
+ end
200
+
201
+ it "Se debe poder sumar dos matrices de racionales (DISPERSA)" do
202
+ (@matrizC_R + @matrizC_R).to_s.should == MatrizDispersa.new([{0 => Racional.new(5,1)}, {1 => Racional.new(4,1)}]).to_s
203
+ end
204
+
205
+ it "Se debe poder restar dos matrices de racionales (DISPERSA)" do
206
+ (@matrizC_R - @matrizC_R).to_s.should == MatrizDispersa.new([{0 => Racional.new(-5,1)}, {1 => Racional.new(4,1)}]).to_s
207
+ end
208
+
209
+ end
210
+
211
+ context 'Comprobar las operaciones de la propia matriz (DISPERSA)' do
212
+
213
+ it "Se debe mostrar el max de la matriz (DISPERSA)" do
214
+ @matrizC.max == 4
215
+ end
216
+
217
+ it "Se debe mostrar el min de la matriz (DISPERSA)" do
218
+ @matrizC.min == 0
219
+ end
220
+
221
+ it "Se debe mostrar el max de la matriz de racionales (DISPERSA)" do
222
+ @matrizC_R.max == Racional.new(4,1)
223
+ end
224
+
225
+ it "Se debe mostrar el min de la matriz de racionales (DISPERSA)" do
226
+ @matrizC_R.min == Racional.new(0,1)
227
+ end
228
+
229
+ end
230
+
231
+ context 'Comprobar modificacion en la hora de practica' do
232
+
233
+ it "Se debe sumar matriz DENSA con DISPERSA" do
234
+ (@matrizA_P_DEN + @matrizB_P_DIS).to_s.should == MatrizDensa.new([[3,4], [5,7]]).to_s
235
+ end
236
+
237
+ it "Se debe sumar matriz DENSA con DISPERSA con racionales" do
238
+ (@matrizA_P_DEN / @matrizB_R_DIS).to_s.should == MatrizDensa.new([[3,4], [5,Racional.new(13,2)]]).to_s
239
+ end
240
+
241
+ end
242
+
243
+ context 'Comprobar modificacion en la hora de practica PRACT11' do
244
+
245
+ it "Se debe devolver la posicion i,j del primer elemento que sea su cuadrado > 6" do
246
+ (@matrizPRACT).encontrar{ |e| ( e * e) > 6 }.should == "[[0,2][1,0][1,1][1,2]]"
247
+ end
248
+
249
+ end
250
+
251
+ end