lpp_t_04_matrix 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -55,7 +55,12 @@ m2 = MatrizDispersa.new(2, 2, {0 => {0 => 1, 1 => 2}, 1 => {0 => 3, 1 => 4}})
55
55
  Se llama a la clase MatrizDispersa.
56
56
  Los dos primero parametros son el número de filas y el número de columnas.
57
57
  A continuación se le pasa un hash que contiene los elementos no nulos de la matriz del tipo:
58
- [FILA] => {[COLUMNA] => [VALOR], [COLUMNA] => [VALOR], ...}, ...
58
+ [FILA] => {[COLUMNA] => [VALOR], [COLUMNA] => [VALOR], ...}, ...
59
+
60
+ Un ejemplo de como construiremos una fracción es:
61
+ a = Frac.new(1,2)
62
+ Se llama a la clase Frac.
63
+ El primer parámetro que se le pasa es el numerador y el sgundo el denominador.
59
64
 
60
65
  ## Installation
61
66
 
@@ -73,6 +78,24 @@ Or install it yourself as:
73
78
 
74
79
  ## Usage
75
80
 
81
+ require 'lpp_t_04_matrix'
82
+ include LppT04Matrix
83
+
84
+ Para operar con matrices se definen los siguientes métodos:
85
+ m1 = MatrizDensa.new(2,2,[[7,10],[15,22]])
86
+ m2 = MatrizDispersa.new(2, 2, {0 => {0 => 1, 1 => 2}, 1 => {0 => 3, 1 => 4}})
87
+ Suma: Se denomina + y se la pasa un objeto matriz.
88
+ Ejemplo: m1+m2
89
+ Resta: Se denomina - y se la pasa un objeto matriz.
90
+ Ejemplo: m1-m2
91
+ Multiplicación: Se denomina * y se la pasa un objeto matriz.
92
+ Ejemplo: m1*m2
93
+ Máximo: Se denomina maximo devuelve el valor del máximo.
94
+ Ejemplo: m1.maximo
95
+ Mínimo: Se denomina maximo devuelve el valor del Mínimo.
96
+ Ejemplo: m1.minimo
97
+
98
+
76
99
 
77
100
  ## Contributing
78
101
 
data/Rakefile CHANGED
@@ -1,4 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
3
  RSpec::Core::RakeTask.new
4
- task :default => :spec
4
+ task :default => :test
5
+
6
+ task :test => :spec do
7
+ sh "ruby -Ilib -Itest test/tc_lpp_t_04_matrix.rb"
8
+ end
@@ -1,3 +1,3 @@
1
1
  module LppT04Matrix
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,30 +1,30 @@
1
1
  require "lpp_t_04_matrix/version"
2
2
 
3
- module LppT04Matrix
3
+ module LppT04Matrix # Clase Abstracta Matriz
4
4
  class Matriz
5
- attr_accessor :filas, :columnas
5
+ attr_accessor :filas, :columnas # Contructor de la clase Matriz
6
6
  def initialize (filas, columnas)
7
7
  @filas = filas
8
8
  @columnas = columnas
9
9
  end
10
10
  end
11
11
 
12
- class MatrizDensa < Matriz
12
+ class MatrizDensa < Matriz # Clase Matriz Densa hereda de Matriz
13
13
  attr_accessor :elemento
14
- def initialize (filas, columnas, elemento)
14
+ def initialize (filas, columnas, elemento) # Contructor de la clase Matriz
15
15
  super(filas, columnas)
16
16
  @elemento = elemento
17
17
  end
18
18
 
19
- def [](i)
19
+ def [](i) # Metodo de acceso a la matriz
20
20
  @elemento[i]
21
21
  end
22
22
 
23
- def indice(i,j)
23
+ def indice(i,j) #Devuelve el valor del indice i j
24
24
  @elemento[i][j]
25
25
  end
26
26
 
27
- def to_s
27
+ def to_s # Convierte la fraccion a una cadena
28
28
  imprimir = ""
29
29
  @filas.times do |i|
30
30
  @columnas.times do |j|
@@ -35,7 +35,7 @@ module LppT04Matrix
35
35
  imprimir
36
36
  end
37
37
 
38
- def +(other)
38
+ def +(other) #Suma dos Fracciones se le pasa un tipo fraccion.
39
39
  raise ArgumentError, "La longitud de las matrices no coincide." unless @filas == other.filas && @columnas == other.columnas
40
40
  elemento = Array.new
41
41
  @filas.times do |i|
@@ -48,7 +48,7 @@ module LppT04Matrix
48
48
  MatrizDensa.new(@filas, @columnas,elemento)
49
49
  end
50
50
 
51
- def -(other)
51
+ def -(other)# Resta dos Fracciones se le pasa un tipo fraccion.
52
52
  raise ArgumentError, "La longitud de las matrices no coincide." unless @filas == other.filas && @columnas == other.columnas
53
53
  elemento = Array.new
54
54
  @filas.times do |i|
@@ -61,7 +61,7 @@ module LppT04Matrix
61
61
  MatrizDensa.new(@filas, @columnas,elemento)
62
62
  end
63
63
 
64
- def *(other)
64
+ def *(other) # Multiplica dos Fracciones se le pasa un tipo fraccion.
65
65
  raise ArgumentError, "La longitud de las matrices no coincide." unless @columnas == other.filas
66
66
  elemento = Array.new
67
67
  acumulado = 0
@@ -80,7 +80,7 @@ module LppT04Matrix
80
80
  MatrizDensa.new(@filas, other.columnas, elemento)
81
81
  end
82
82
 
83
- def traspuesta
83
+ def traspuesta # Devuelve la trasuesta de una Matriz
84
84
  elemento = Array.new
85
85
  @columnas.times do |i|
86
86
  elemento_fila = Array.new
@@ -91,7 +91,7 @@ module LppT04Matrix
91
91
  end
92
92
  MatrizDensa.new(@columnas, @filas, elemento)
93
93
  end
94
- def maximo
94
+ def maximo # Devuelve el valor maximo
95
95
  aux = @elemento[0][0]
96
96
  @columnas.times do |i|
97
97
  @filas.times do |j|
@@ -100,7 +100,7 @@ module LppT04Matrix
100
100
  end
101
101
  aux
102
102
  end
103
- def minimo
103
+ def minimo # Devuelve el valor minimo.
104
104
  aux = @elemento[0][0]
105
105
  @columnas.times do |i|
106
106
  @filas.times do |j|
@@ -112,17 +112,17 @@ module LppT04Matrix
112
112
  end
113
113
 
114
114
 
115
- class MatrizDispersa < Matriz
115
+ class MatrizDispersa < Matriz # Clase Matriz Dispersa hereda de Matriz
116
116
  attr_accessor :elemento
117
117
  def initialize (filas, columnas, elemento)
118
118
  super(filas, columnas)
119
119
  @elemento = elemento
120
120
  end
121
121
 
122
- def [](i)
122
+ def [](i) # Metodo de acceso a la matriz
123
123
  @elemento[i]
124
124
  end
125
- def indice(i,j)
125
+ def indice(i,j) #Devuelve el valor del indice i j
126
126
  elemento = @elemento.fetch(i,0)
127
127
  if elemento!= 0
128
128
  elemento.fetch(j,0)
@@ -131,11 +131,11 @@ module LppT04Matrix
131
131
  end
132
132
  end
133
133
 
134
- def to_s
134
+ def to_s # Convierte la fraccion a una cadena
135
135
  @elemento
136
136
  end
137
137
 
138
- def +(other)
138
+ def +(other) #Suma dos Fracciones se le pasa un tipo fraccion.
139
139
  raise ArgumentError, "La longitud de las matrices no coincide." unless @filas == other.filas && @columnas == other.columnas
140
140
  case other
141
141
  when MatrizDensa
@@ -148,7 +148,7 @@ module LppT04Matrix
148
148
  end
149
149
  end
150
150
 
151
- def -(other)
151
+ def -(other) # Resta dos Fracciones se le pasa un tipo fraccion.
152
152
  raise ArgumentError, "La longitud de las matrices no coincide." unless @filas == other.filas && @columnas == other.columnas
153
153
  case other
154
154
  when MatrizDensa
@@ -161,7 +161,7 @@ module LppT04Matrix
161
161
  end
162
162
  end
163
163
 
164
- def *(other)
164
+ def *(other) # Multiplica dos Fracciones se le pasa un tipo fraccion.
165
165
  raise ArgumentError, "La longitud de las matrices no coincide." unless @columnas == other.filas
166
166
  case other
167
167
  when MatrizDensa
@@ -194,7 +194,7 @@ module LppT04Matrix
194
194
  end
195
195
  end
196
196
 
197
- def traspuesta
197
+ def traspuesta # Devuelve la trasuesta de una Matriz
198
198
  elemento = Hash.new(Hash.new())
199
199
  @elemento.each {
200
200
  |key, value| value.each {
@@ -206,7 +206,7 @@ module LppT04Matrix
206
206
  elemento
207
207
  MatrizDispersa.new(@filas, @columnas, elemento)
208
208
  end
209
- def maximo
209
+ def maximo # Devuelve el valor maximo
210
210
  aux = @elemento.keys
211
211
  aux1 = aux[0]
212
212
  aux2 = @elemento[aux1].values
@@ -219,7 +219,7 @@ module LppT04Matrix
219
219
  }
220
220
  mayor
221
221
  end
222
- def minimo
222
+ def minimo # Devuelve el valor minimo.
223
223
  aux = @elemento.keys
224
224
  aux1 = aux[0]
225
225
  aux2 = @elemento[aux1].values
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lpp_t_04_matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-19 00:00:00.000000000 Z
12
+ date: 2013-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler