matriz 0.1.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/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/Guardfile +8 -0
- data/LICENSE +22 -0
- data/README.md +25 -0
- data/Rakefile +36 -0
- data/Rakefile~ +33 -0
- data/bin/main.rb +256 -0
- data/lib/gcd.rb +13 -0
- data/lib/gcd.rb~ +14 -0
- data/lib/matriz.rb +37 -0
- data/lib/matriz_densa.rb +221 -0
- data/lib/matriz_dispersa.rb +323 -0
- data/lib/racionales.rb +172 -0
- data/lib/racionales.rb~ +172 -0
- data/lib/version.rb +3 -0
- data/lib/version.rb~ +3 -0
- data/matriz.gemspec +25 -0
- data/spec/matriz_spec.rb +265 -0
- data/test/tc_matriz.rb +50 -0
- metadata +140 -0
data/lib/racionales.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require "./lib/gcd.rb"
|
2
|
+
|
3
|
+
class NumerosRacionales
|
4
|
+
attr_reader :a, :b
|
5
|
+
|
6
|
+
def initialize (a, b) # Crea un numero racional con numerador a y denominador b
|
7
|
+
raise ZeroDivisionError, "Denominador igual a cero" if (b==0)
|
8
|
+
if (a<0) and (b<0) #si los dos son negativos => nos queda positivo
|
9
|
+
a,b= -a,-b
|
10
|
+
end
|
11
|
+
simplifica = gcd(a,b)
|
12
|
+
@a,@b = a/simplifica,b/simplifica
|
13
|
+
end
|
14
|
+
|
15
|
+
def num() # Devuelve el valor del numerador
|
16
|
+
@a
|
17
|
+
end
|
18
|
+
|
19
|
+
def denom()# Devuelve el valor del denominador
|
20
|
+
@b
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s # Muestra por pantalla el racional
|
24
|
+
if (@a == 0) #numerador = 0, racional = 0. El denominador lo controlamos en el constructor
|
25
|
+
"0"
|
26
|
+
elsif (@b==1)
|
27
|
+
"#{@a}"
|
28
|
+
else
|
29
|
+
"#{@a}/#{@b}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_f # Pasa a flotante un numero racional
|
34
|
+
tmp=@a.to_f/@b.to_f
|
35
|
+
return tmp
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def simplificar # Simplifica el numero racional
|
40
|
+
simplifica = gcd(@a,@b)
|
41
|
+
NumerosRacionales.new(@a/simplifica,@b/simplifica)
|
42
|
+
end
|
43
|
+
|
44
|
+
def +(other) # Calcula la suma de racionales o racionales con enteros
|
45
|
+
if (other.is_a?(Integer))
|
46
|
+
# other=self.coerce(other)
|
47
|
+
other=NumerosRacionales.new(other,1)
|
48
|
+
end
|
49
|
+
deno = mcm(@b, other.b) #MCM para hallar el denominador
|
50
|
+
num = ((deno/@b) * @a) + ((deno/other.b) * other.a)
|
51
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
52
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
53
|
+
num = num * (-1)
|
54
|
+
deno = deno * (-1)
|
55
|
+
end
|
56
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
57
|
+
end
|
58
|
+
|
59
|
+
def -(other) # Calcula la resta de racionales o racionales con enteros
|
60
|
+
if (other.is_a?(Numeric))
|
61
|
+
other=self.coerce(other)
|
62
|
+
other=other[0]
|
63
|
+
end
|
64
|
+
deno = mcm(@b, other.b) #MCM para hallar el denominador
|
65
|
+
num = ((deno/@b) * @a) - ((deno/other.b) * other.a)
|
66
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
67
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
68
|
+
num = num * (-1)
|
69
|
+
deno = deno * (-1)
|
70
|
+
end
|
71
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
72
|
+
end
|
73
|
+
|
74
|
+
def *(other) # Calcula la multiplicaciones de dos racionales
|
75
|
+
if (other.is_a?(Numeric))
|
76
|
+
other=self.coerce(other)
|
77
|
+
other=other[0]
|
78
|
+
end
|
79
|
+
num = @a*other.a
|
80
|
+
deno = @b*other.b
|
81
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
82
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
83
|
+
num = num * (-1)
|
84
|
+
deno = deno * (-1)
|
85
|
+
end
|
86
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
87
|
+
end
|
88
|
+
|
89
|
+
def /(other) # Calcula la division de dos racionales
|
90
|
+
num = @a*other.b
|
91
|
+
deno = @b*other.a
|
92
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
93
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
94
|
+
num = num * (-1)
|
95
|
+
deno = deno * (-1)
|
96
|
+
end
|
97
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
98
|
+
end
|
99
|
+
|
100
|
+
def %(other) # Halla el modulo de una fraccion
|
101
|
+
tmp = (self/other).abs
|
102
|
+
t = NumerosRacionales.new(1,1)
|
103
|
+
tmp= t-tmp
|
104
|
+
NumerosRacionales.new(tmp.num, tmp.denom)
|
105
|
+
end
|
106
|
+
|
107
|
+
def coerce(other) # Hace una conversion de enteros a racionales
|
108
|
+
if (other.is_a?(Integer))
|
109
|
+
[NumerosRacionales.new(other.to_i,1),self]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def ==(other) # Compara si dos numeros racionales son iguales
|
114
|
+
if (self.to_f == other.to_f)
|
115
|
+
true
|
116
|
+
else
|
117
|
+
false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def <(other) # Compara si un numero racional es menor que otro
|
122
|
+
if (self.to_f < other.to_f)
|
123
|
+
true
|
124
|
+
else
|
125
|
+
false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def <=(other) # Compara si un numero racional es menor o igual que otro
|
130
|
+
if (self.to_f <= other.to_f)
|
131
|
+
true
|
132
|
+
else
|
133
|
+
false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def >(other) # Compara si un numero racional es mayor que otro
|
138
|
+
if (self.to_f > other.to_f)
|
139
|
+
true
|
140
|
+
else
|
141
|
+
false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def >=(other) # Compara si un numero racional es mayor o igual que otro
|
146
|
+
if (self.to_f >= other.to_f)
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def <=>(other) # Compara si un numero racional distinto otro
|
154
|
+
self.to_f <=> other.to_f
|
155
|
+
end
|
156
|
+
|
157
|
+
def abs # Calcula el valor absoluto de un racional
|
158
|
+
n, d = @a.abs, @b.abs
|
159
|
+
NumerosRacionales.new(n,d)
|
160
|
+
end
|
161
|
+
|
162
|
+
def reciprocal # Calcula el inverso de un racional
|
163
|
+
inv = NumerosRacionales.new(1,1)
|
164
|
+
tmp = inv/self
|
165
|
+
NumerosRacionales.new(tmp.num,tmp.denom)
|
166
|
+
end
|
167
|
+
|
168
|
+
def -@ # Calcula el opuesto de un racional
|
169
|
+
NumerosRacionales.new(-self.num,self.denom)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
data/lib/racionales.rb~
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require "./lib/gcd.rb"
|
2
|
+
|
3
|
+
class NumerosRacionales
|
4
|
+
attr_reader :a, :b
|
5
|
+
|
6
|
+
def initialize (a, b)
|
7
|
+
raise ZeroDivisionError, "Denominador igual a cero" if (b==0)
|
8
|
+
if (a<0) and (b<0) #si los dos son negativos => nos queda positivo
|
9
|
+
a,b= -a,-b
|
10
|
+
end
|
11
|
+
simplifica = gcd(a,b)
|
12
|
+
@a,@b = a/simplifica,b/simplifica
|
13
|
+
end
|
14
|
+
|
15
|
+
def num()
|
16
|
+
@a
|
17
|
+
end
|
18
|
+
|
19
|
+
def denom()
|
20
|
+
@b
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
if (@a == 0) #numerador = 0, racional = 0. El denominador lo controlamos en el constructor
|
25
|
+
"0"
|
26
|
+
elsif (@b==1)
|
27
|
+
"#{@a}"
|
28
|
+
else
|
29
|
+
"#{@a}/#{@b}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_f
|
34
|
+
tmp=@a.to_f/@b.to_f
|
35
|
+
return tmp
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def simplificar
|
40
|
+
simplifica = gcd(@a,@b)
|
41
|
+
NumerosRacionales.new(@a/simplifica,@b/simplifica)
|
42
|
+
end
|
43
|
+
|
44
|
+
def +(other) #para sumar dos nums racionales...
|
45
|
+
if (other.is_a?(Integer))
|
46
|
+
# other=self.coerce(other)
|
47
|
+
other=NumerosRacionales.new(other,1)
|
48
|
+
end
|
49
|
+
deno = mcm(@b, other.b) #MCM para hallar el denominador
|
50
|
+
num = ((deno/@b) * @a) + ((deno/other.b) * other.a)
|
51
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
52
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
53
|
+
num = num * (-1)
|
54
|
+
deno = deno * (-1)
|
55
|
+
end
|
56
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
57
|
+
end
|
58
|
+
|
59
|
+
def -(other) #para restar dos nums racionales...
|
60
|
+
if (other.is_a?(Numeric))
|
61
|
+
other=self.coerce(other)
|
62
|
+
other=other[0]
|
63
|
+
end
|
64
|
+
deno = mcm(@b, other.b) #MCM para hallar el denominador
|
65
|
+
num = ((deno/@b) * @a) - ((deno/other.b) * other.a)
|
66
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
67
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
68
|
+
num = num * (-1)
|
69
|
+
deno = deno * (-1)
|
70
|
+
end
|
71
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
72
|
+
end
|
73
|
+
|
74
|
+
def *(other) #multiplicacion: multiplicamos numerador con numerador y denominador con denominador
|
75
|
+
if (other.is_a?(Numeric))
|
76
|
+
other=self.coerce(other)
|
77
|
+
other=other[0]
|
78
|
+
end
|
79
|
+
num = @a*other.a
|
80
|
+
deno = @b*other.b
|
81
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
82
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
83
|
+
num = num * (-1)
|
84
|
+
deno = deno * (-1)
|
85
|
+
end
|
86
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
87
|
+
end
|
88
|
+
|
89
|
+
def /(other) #división: multiplicamos en cruz: numerador de uno x denominador del otro y viceversa
|
90
|
+
num = @a*other.b
|
91
|
+
deno = @b*other.a
|
92
|
+
simplifica = gcd(num,deno) #averiguamos el valor para obtener el racional irreducible
|
93
|
+
if ((num < 0) and (deno < 0)) or ((num > 0) and (deno < 0)) #corregimos el signo
|
94
|
+
num = num * (-1)
|
95
|
+
deno = deno * (-1)
|
96
|
+
end
|
97
|
+
NumerosRacionales.new(num/simplifica,deno/simplifica)
|
98
|
+
end
|
99
|
+
|
100
|
+
def %(other)
|
101
|
+
tmp = (self/other).abs
|
102
|
+
t = NumerosRacionales.new(1,1)
|
103
|
+
tmp= t-tmp
|
104
|
+
NumerosRacionales.new(tmp.num, tmp.denom)
|
105
|
+
end
|
106
|
+
|
107
|
+
def coerce(other)
|
108
|
+
if (other.is_a?(Integer))
|
109
|
+
[NumerosRacionales.new(other.to_i,1),self]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def ==(other)
|
114
|
+
if (self.to_f == other.to_f)
|
115
|
+
true
|
116
|
+
else
|
117
|
+
false
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def <(other)
|
122
|
+
if (self.to_f < other.to_f)
|
123
|
+
true
|
124
|
+
else
|
125
|
+
false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def <=(other)
|
130
|
+
if (self.to_f <= other.to_f)
|
131
|
+
true
|
132
|
+
else
|
133
|
+
false
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def >(other)
|
138
|
+
if (self.to_f > other.to_f)
|
139
|
+
true
|
140
|
+
else
|
141
|
+
false
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def >=(other)
|
146
|
+
if (self.to_f >= other.to_f)
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def <=>(other)
|
154
|
+
self.to_f <=> other.to_f
|
155
|
+
end
|
156
|
+
|
157
|
+
def abs
|
158
|
+
n, d = @a.abs, @b.abs
|
159
|
+
NumerosRacionales.new(n,d)
|
160
|
+
end
|
161
|
+
|
162
|
+
def reciprocal
|
163
|
+
inv = NumerosRacionales.new(1,1)
|
164
|
+
tmp = inv/self
|
165
|
+
NumerosRacionales.new(tmp.num,tmp.denom)
|
166
|
+
end
|
167
|
+
|
168
|
+
def -@
|
169
|
+
NumerosRacionales.new(-self.num,self.denom)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
data/lib/version.rb
ADDED
data/lib/version.rb~
ADDED
data/matriz.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "./lib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "matriz"
|
7
|
+
s.version = Matriz::VERSION
|
8
|
+
s.authors = ["Mª Belen Armas Torres | Aaron Socas Gaspar"]
|
9
|
+
s.email = ["alu0100696677@ull.edu.es | alu0100207385@ull.edu.es"]
|
10
|
+
s.homepage = "https://github.com/alu0100207385/pract10.git"
|
11
|
+
s.summary = %q{Creación de matrices}
|
12
|
+
s.description = %q{Permite representar y realizar operaciones con matrices densas y dispersas}
|
13
|
+
|
14
|
+
s.rubyforge_project = "matrices"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "guard-rspec"
|
24
|
+
s.add_development_dependency "guard-bundler"
|
25
|
+
end
|
data/spec/matriz_spec.rb
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
# require "./lib/matriz.rb"
|
2
|
+
require "./lib/matriz_densa.rb"
|
3
|
+
require "./lib/matriz_dispersa.rb"
|
4
|
+
|
5
|
+
|
6
|
+
describe Matriz do
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
@m1 = Matriz_densa.new(2,2)
|
10
|
+
@m1.llenar([[1,2],[2,3]])
|
11
|
+
@m2 = Matriz_densa.new(2,2)
|
12
|
+
@m2.llenar([[-1,1],[2,-5]])
|
13
|
+
@m3 = Matriz_densa.new(2,2)
|
14
|
+
@m3.llenar([[NumerosRacionales.new(1, 1),NumerosRacionales.new(1, 1)],[NumerosRacionales.new(1, 1),NumerosRacionales.new(1, 1)]])
|
15
|
+
@m4 = Matriz_densa.new(2,2)
|
16
|
+
@m4.llenar([[NumerosRacionales.new(1, 2),NumerosRacionales.new(3, 5)],[NumerosRacionales.new(11, 40),NumerosRacionales.new(49, 150)]])
|
17
|
+
|
18
|
+
@m5 = Matriz_dispersa.new(2,2)
|
19
|
+
@m5.llenar([[0,1]],[-1])
|
20
|
+
@m6 = Matriz_dispersa.new(2,2)
|
21
|
+
@m6.llenar([[1,0]],[5])
|
22
|
+
@m7 = Matriz_dispersa.new(2,2)
|
23
|
+
@m7.llenar([[1,1]],[NumerosRacionales.new(1, 2)])
|
24
|
+
@m8 = Matriz_dispersa.new(2,2)
|
25
|
+
@m8.llenar([[0,0]],[NumerosRacionales.new(5, 3)])
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "# Definicion de argumentos: " do
|
29
|
+
it " - Las dimensiones son correctas" do
|
30
|
+
lambda {@m9.new(-1,1).should raise_error(TypeError)}
|
31
|
+
lambda {@m9.new(1,-1).should raise_error(TypeError)}
|
32
|
+
@m1.fil.should eq(2)
|
33
|
+
@m1.col.should eq(2)
|
34
|
+
@m5.fil.should eq(2)
|
35
|
+
@m5.col.should eq(2)
|
36
|
+
end
|
37
|
+
it "- Contenido de la matriz densa" do
|
38
|
+
@m9 = Matriz_densa.new(2,2)
|
39
|
+
@m9.llenar([[1,2],[2,3]])
|
40
|
+
(@m1 == @m9).should eq(true)
|
41
|
+
end
|
42
|
+
it "- Contenido de la matriz dispersa" do
|
43
|
+
@m9 = Matriz_dispersa.new(2,2)
|
44
|
+
@m9.llenar([[0,1]],[-1])
|
45
|
+
aux= (@m5 == @m9)
|
46
|
+
aux.should eq(true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "# Otras operaciones" do
|
51
|
+
it "- Traspuesta de una matriz densa" do
|
52
|
+
(@m2==@m2.t).should eq (false)
|
53
|
+
end
|
54
|
+
it "- Traspuesta de una matriz dispersa" do
|
55
|
+
(@m5==@m5.t).should eq (false)
|
56
|
+
end
|
57
|
+
it "- Comparador de igualdad entre densas" do
|
58
|
+
(@m1==@m1).should eq(true)
|
59
|
+
end
|
60
|
+
it "- Comparador de igualdad entre dispersas" do
|
61
|
+
(@m5==@m5).should eq(true)
|
62
|
+
end
|
63
|
+
it "- Comparador de igualdad entre densas y dispersas" do
|
64
|
+
@m9 = Matriz_densa.new(2,2)
|
65
|
+
@m9.llenar([[0,-1],[0,0]])
|
66
|
+
(@m5==@m9).should eq(true)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "# Operaciones de matrices: "do
|
71
|
+
|
72
|
+
#SUMAS ENTRE MATRICES
|
73
|
+
it "- Se pueden sumar matrices densas de enteros" do
|
74
|
+
@m9 = Matriz_densa.new(2,2)
|
75
|
+
@m9.llenar([[0,3],[4,-2]])
|
76
|
+
((@m1+@m2) == @m9).should eq(true)
|
77
|
+
end
|
78
|
+
it "- Se pueden sumar matrices densas de racionales" do
|
79
|
+
@m9 = Matriz_densa.new(2,2)
|
80
|
+
@m9.llenar([[NumerosRacionales.new(3, 2),NumerosRacionales.new(8, 5)],[NumerosRacionales.new(51, 40),NumerosRacionales.new(199, 150)]])
|
81
|
+
((@m3+@m4) == @m9).should eq(true)
|
82
|
+
end
|
83
|
+
it "- Se pueden sumar matrices dispersas de enteros" do
|
84
|
+
@m9 = Matriz_dispersa.new(2,2)
|
85
|
+
@m9.llenar([[0,1],[1,0]],[-1,5])
|
86
|
+
((@m5+@m6) == @m9).should eq(true)
|
87
|
+
end
|
88
|
+
it "- Se pueden sumar matrices dispersas de racionales" do
|
89
|
+
@m9 = Matriz_dispersa.new(2,2)
|
90
|
+
@m9.llenar([[0,0],[1,1]],[NumerosRacionales.new(5, 3),NumerosRacionales.new(1, 2)])
|
91
|
+
((@m7+@m8) == @m9).should eq(true)
|
92
|
+
end
|
93
|
+
it "- Se pueden sumar matrices de enteros entre las distintas clases" do
|
94
|
+
@m9 = Matriz_densa.new(2,2)
|
95
|
+
@m9.llenar([[-1,1],[7,-5]])
|
96
|
+
((@m2+@m6) == @m9).should eq(true)
|
97
|
+
end
|
98
|
+
it "- Se pueden sumar matrices de racionales entre las distintas clases" do
|
99
|
+
@m9 = Matriz_densa.new(2,2)
|
100
|
+
@m9.llenar([[NumerosRacionales.new(8, 3),NumerosRacionales.new(1, 1)],[NumerosRacionales.new(1, 1),NumerosRacionales.new(1, 1)]])
|
101
|
+
((@m3+@m8) == @m9).should eq(true)
|
102
|
+
end
|
103
|
+
it "- Se pueden sumar matrices de enteros con racionales entre las distintas clases" do
|
104
|
+
@m9 = Matriz_densa.new(2,2)
|
105
|
+
@m9.llenar([[NumerosRacionales.new(2, 3),NumerosRacionales.new(1, 1)],[NumerosRacionales.new(2, 1),NumerosRacionales.new(-5, 1)]])
|
106
|
+
((@m2+@m8) == @m9).should eq(true)
|
107
|
+
end
|
108
|
+
|
109
|
+
#RESTAS ENTRE MATRICES
|
110
|
+
it "- Se pueden restar matrices densas de enteros" do
|
111
|
+
@m9 = Matriz_densa.new(2,2)
|
112
|
+
@m9.llenar([[2,1],[0,8]])
|
113
|
+
((@m1-@m2) == @m9).should eq(true)
|
114
|
+
end
|
115
|
+
it "- Se pueden restar matrices densas de racionales" do
|
116
|
+
@m9 = Matriz_densa.new(2,2)
|
117
|
+
@m9.llenar([[NumerosRacionales.new(1, 2),NumerosRacionales.new(2, 5)],[NumerosRacionales.new(29, 40),NumerosRacionales.new(101, 150)]])
|
118
|
+
((@m3-@m4) == @m9).should eq(true)
|
119
|
+
end
|
120
|
+
it "- Se pueden restar matrices dispersas de enteros" do
|
121
|
+
@m9 = Matriz_dispersa.new(2,2)
|
122
|
+
@m9.llenar([[0,1],[1,0]],[-1,-5])
|
123
|
+
((@m5-@m6) == @m9).should eq(true)
|
124
|
+
end
|
125
|
+
it "- Se pueden restar matrices dispersas de racionales" do
|
126
|
+
@m9 = Matriz_dispersa.new(2,2)
|
127
|
+
@m9.llenar([[0,0],[1,1]],[NumerosRacionales.new(-5, 3),NumerosRacionales.new(1, 2)])
|
128
|
+
((@m7-@m8) == @m9).should eq(true)
|
129
|
+
end
|
130
|
+
it "- Se pueden restar matrices de enteros entre las distintas clases" do
|
131
|
+
@m9 = Matriz_densa.new(2,2)
|
132
|
+
@m9.llenar([[-1,1],[-3,-5]])
|
133
|
+
((@m2-@m6) == @m9).should eq(true)
|
134
|
+
end
|
135
|
+
it "- Se pueden restar matrices de racionales entre las distintas clases" do
|
136
|
+
@m9 = Matriz_densa.new(2,2)
|
137
|
+
@m9.llenar([[NumerosRacionales.new(-2, 3),NumerosRacionales.new(1, 1)],[NumerosRacionales.new(1, 1),NumerosRacionales.new(1, 1)]])
|
138
|
+
((@m3-@m8) == @m9).should eq(true)
|
139
|
+
end
|
140
|
+
it "- Se pueden restar matrices de enteros con racionales entre las distintas clases" do
|
141
|
+
@m9 = Matriz_densa.new(2,2)
|
142
|
+
@m9.llenar([[NumerosRacionales.new(-8, 3),NumerosRacionales.new(1, 1)],[NumerosRacionales.new(2, 1),NumerosRacionales.new(-5, 1)]])
|
143
|
+
((@m2-@m8) == @m9).should eq(true)
|
144
|
+
end
|
145
|
+
|
146
|
+
#PRODUCTO ESCALAR DE MATRICES
|
147
|
+
it "- Producto escalar de densas con enteros" do
|
148
|
+
@m9=Matriz_densa.new(2,2)
|
149
|
+
@m9.llenar([[-2,2],[4,-10]])
|
150
|
+
((@m2*2)==@m9).should eq(true)
|
151
|
+
end
|
152
|
+
it "- Producto escalar de densas con racionales" do
|
153
|
+
@m9=Matriz_densa.new(2,2)
|
154
|
+
@m9.llenar([[NumerosRacionales.new(4, 1),NumerosRacionales.new(4, 1)],[NumerosRacionales.new(4, 1),NumerosRacionales.new(4, 1)]])
|
155
|
+
((@m3*4)==@m9).should eq(true)
|
156
|
+
end
|
157
|
+
it "- Producto escalar de dispersas con enteros" do
|
158
|
+
@m9=Matriz_dispersa.new(2,2)
|
159
|
+
@m9.llenar([[0,1]],[-2])
|
160
|
+
((@m5*2)==@m9).should eq(true)
|
161
|
+
end
|
162
|
+
it "- Producto escalar de dispersas con racionales" do
|
163
|
+
@m9=Matriz_dispersa.new(2,2)
|
164
|
+
@m9.llenar([[0,0]],[NumerosRacionales.new(20,3)])
|
165
|
+
((@m8*4)==@m9).should eq(true)
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
#PRODUCTOS ENTRE MATRICES
|
170
|
+
it "- Producto de matrices densas con enteros" do
|
171
|
+
@m9=Matriz_densa.new(2,2)
|
172
|
+
@m9.llenar([[3,-9],[4,-13]])
|
173
|
+
((@m1*@m2)==@m9).should eq(true)
|
174
|
+
end
|
175
|
+
it "- Producto de matrices densas con racionales" do
|
176
|
+
@m9=Matriz_densa.new(2,2)
|
177
|
+
@m9.llenar([[NumerosRacionales.new(31,40),NumerosRacionales.new(139,150)],[NumerosRacionales.new(31,40),NumerosRacionales.new(139,150)]])
|
178
|
+
((@m3*@m4)==@m9).should eq(true)
|
179
|
+
end
|
180
|
+
it "- Producto de matrices dispersas con enteros" do
|
181
|
+
@m9=Matriz_dispersa.new(2,2)
|
182
|
+
@m9.llenar([[0,0]],[-5])
|
183
|
+
((@m5*@m6)==@m9).should eq(true)
|
184
|
+
end
|
185
|
+
it "- Producto de matrices dispersas con racionales" do
|
186
|
+
@m9=Matriz_dispersa.new(2,2)
|
187
|
+
((@m7*@m8)==@m9).should eq(true)
|
188
|
+
end
|
189
|
+
it "- Producto de matriz densa de enteros por matriz dispersa de enteros" do
|
190
|
+
@m9=Matriz_densa.new(2,2)
|
191
|
+
@m9.llenar([[0,-1],[0,-2]])
|
192
|
+
((@m1*@m5)==@m9).should eq(true)
|
193
|
+
end
|
194
|
+
it "- Producto de matriz densa de enteros por matriz dispersa de racionales" do
|
195
|
+
@m9=Matriz_densa.new(2,2)
|
196
|
+
@m9.llenar([[0,1],[0,NumerosRacionales.new(3,2)]])
|
197
|
+
((@m1*@m7)==@m9).should eq(true)
|
198
|
+
end
|
199
|
+
it "- Producto de matriz densa de racionales por matriz dispersa de enteros" do
|
200
|
+
@m9=Matriz_densa.new(2,2)
|
201
|
+
@m9.llenar([[3,0],[NumerosRacionales.new(49,30),0]])
|
202
|
+
((@m4*@m6)==@m9).should eq(true)
|
203
|
+
end
|
204
|
+
it "- Producto de matriz densa de racionales por matriz dispersa de enteros" do
|
205
|
+
@m9=Matriz_densa.new(2,2)
|
206
|
+
@m9.llenar([[3,0],[NumerosRacionales.new(49,30),0]])
|
207
|
+
((@m4*@m6)==@m9).should eq(true)
|
208
|
+
end
|
209
|
+
it "- Producto de matriz densa de racionales por matriz dispersa de racionales" do
|
210
|
+
@m9=Matriz_densa.new(2,2)
|
211
|
+
@m9.llenar([[0,NumerosRacionales.new(3,10)],[0,NumerosRacionales.new(49,300)]])
|
212
|
+
((@m4*@m7)==@m9).should eq(true)
|
213
|
+
end
|
214
|
+
it "- Producto de matriz dispersa de enteros por matriz densa de enteros" do
|
215
|
+
@m9=Matriz_dispersa.new(2,2)
|
216
|
+
@m9.llenar([[1,0],[1,1]],[-5,5])
|
217
|
+
((@m6*@m2)==@m9).should eq(true)
|
218
|
+
end
|
219
|
+
it "- Producto de matriz dispersa de enteros por matriz densa de racionales" do
|
220
|
+
@m9=Matriz_dispersa.new(2,2)
|
221
|
+
@m9.llenar([[1,0],[1,1]],[NumerosRacionales.new(5,2),NumerosRacionales.new(3,1)])
|
222
|
+
((@m6*@m4)==@m9).should eq(true)
|
223
|
+
end
|
224
|
+
it "- Producto de matriz dispersa de racionales por matriz densa de enteros" do
|
225
|
+
@m9=Matriz_dispersa.new(2,2)
|
226
|
+
@m9.llenar([[0,0],[0,1]],[NumerosRacionales.new(5,3),NumerosRacionales.new(10,3)])
|
227
|
+
((@m8*@m1)==@m9).should eq(true)
|
228
|
+
end
|
229
|
+
it "- Producto de matriz dispersa de racionales por matriz densa de racionales" do
|
230
|
+
@m9=Matriz_dispersa.new(2,2)
|
231
|
+
@m9.llenar([[0,0],[0,1]],[NumerosRacionales.new(5,6),NumerosRacionales.new(1,1)])
|
232
|
+
((@m8*@m4)==@m9).should eq(true)
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
#CALCULO DE LOS ELEMENTOS MAX Y MIN
|
237
|
+
it "- Maximo de densas con enteros" do
|
238
|
+
(@m2.max==2).should eq(true)
|
239
|
+
end
|
240
|
+
it "- Maximo de densas con racionales" do
|
241
|
+
(@m3.max==NumerosRacionales.new(1,1)).should eq(true)
|
242
|
+
end
|
243
|
+
it "- Minimo de densas con enteros" do
|
244
|
+
(@m2.min==-5).should eq(true)
|
245
|
+
end
|
246
|
+
it "- Minimo de densas con racionales" do
|
247
|
+
(@m3.min==NumerosRacionales.new(1,1)).should eq(true)
|
248
|
+
end
|
249
|
+
|
250
|
+
it "- Maximo de dispersas con enteros" do
|
251
|
+
(@m5.max==0).should eq(true)
|
252
|
+
end
|
253
|
+
it "- Maximo de dispersas con racionales" do
|
254
|
+
(@m8.max==NumerosRacionales.new(5,3)).should eq(true)
|
255
|
+
end
|
256
|
+
it "- Minimo de dispersas con enteros" do
|
257
|
+
(@m5.min==-1).should eq(true)
|
258
|
+
end
|
259
|
+
it "- Minimo de dispersas con racionales" do
|
260
|
+
(@m8.min==NumerosRacionales.new(0,1)).should eq(true)
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|