matriz_sf 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/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in matriz_sf.gemspec
4
+ gemspec
5
+ gem 'rake'
6
+ gem 'rspec'
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ matriz_sf (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.4)
10
+ rake (10.1.0)
11
+ rspec (2.14.1)
12
+ rspec-core (~> 2.14.0)
13
+ rspec-expectations (~> 2.14.0)
14
+ rspec-mocks (~> 2.14.0)
15
+ rspec-core (2.14.7)
16
+ rspec-expectations (2.14.3)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.14.4)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.3)
25
+ matriz_sf!
26
+ rake
27
+ rspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Fabio Mendoza Bello
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,11 @@
1
+ $:.unshift File.dirname(__FILE__) + 'lib'
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+ task :default => :spec
7
+
8
+ desc "Ejecutar las espectativas de la clase Matriz"
9
+ task :local do
10
+ sh "rspec --format documentation -Ilib -Ispec spec/matriz_sf_spec.rb"
11
+ end
@@ -0,0 +1,271 @@
1
+ require "matriz_sf/version"
2
+
3
+ module Matriz_sf
4
+ class Matriz
5
+
6
+ def initialize(f=0,c=0)
7
+ @fil = f
8
+ @col = c
9
+ end
10
+
11
+ attr_accessor :fil,:col
12
+
13
+ ##Declarar metodos abstactos
14
+ def to_s
15
+ raise "Error. metodo no definido."
16
+ end
17
+
18
+ def +(b)
19
+ raise "Error. metodo no definido."
20
+ end
21
+
22
+ def -(b)
23
+ raise "Error. metodo no definido."
24
+ end
25
+
26
+ def *(b)
27
+ raise "Error. metodo no definido."
28
+ end
29
+
30
+ def /(b)
31
+ raise "Error. metodo no definido."
32
+ end
33
+ end
34
+
35
+ class VectorDisperso
36
+ attr_reader :vector
37
+
38
+ def initialize(h = {})
39
+ @vector = Hash.new(0)
40
+ @vector = @vector.merge!(h)
41
+ end
42
+
43
+ def [](j)
44
+ @vector[j]
45
+ end
46
+
47
+ def to_s
48
+ @vector.to_s
49
+ end
50
+ end
51
+
52
+ class MatrizDispersa < Matriz
53
+ attr_reader :matrix
54
+
55
+ def initialize(h = {})
56
+ @matrix = Hash.new({})
57
+ for k in h.keys do
58
+ @matrix[k] = if h[k].is_a? Vectordisperso
59
+ h[k]
60
+ else
61
+ @matrix[k] = Vectordisperso.new(h[k])
62
+ end
63
+ end
64
+ end
65
+
66
+ def [](i)
67
+ @matrix[i]
68
+ end
69
+
70
+ def col(j)
71
+ c = {}
72
+ for r in @matrix.keys do
73
+ c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j
74
+ end
75
+ Vectordisperso.new c
76
+ end
77
+
78
+
79
+ def to_s
80
+ str = @matrix.map {|k,v| "#{k} => #{v.to_s}"}.join(", ")
81
+ str = "{ #{str} }"
82
+ end
83
+
84
+ def max
85
+ maximo=@matrix[0]
86
+ for i in (1..@matrix.length)
87
+ if maximo < @matrix[i]
88
+ maximo=@matrix[i]
89
+ end
90
+ end
91
+ end
92
+
93
+ def min
94
+ minimo=@matrix[0]
95
+ for i in (1..@matrix.length)
96
+ if minimo > @matrix[i]
97
+ minimo=@matrix[i]
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ class MatrizDensa < Matriz
104
+ def initialize (matrix, tam = matrix[0].size)
105
+ super(matrix.size,tam)
106
+ @matrix = matrix
107
+ @fila = matrix.size
108
+ @columna = tam
109
+ end
110
+
111
+ attr_reader :matrix, :fila, :columna
112
+
113
+ def mostrar #Funcion mostrar matriz
114
+ x = y = 0 # inicializamos las variables
115
+ puts "matriz: "
116
+ while x < fila # primer bucle
117
+ while y < columna # segundo bucle
118
+ print("#{matrix[x][y]}") #imprimimos en la posicion en la que se encuentre
119
+ y += 1
120
+ end
121
+ puts
122
+ x += 1
123
+ y = 0
124
+ end
125
+ end
126
+
127
+ def to_s #Funcion mostrar matriz
128
+ cadena = ""
129
+ x = y = 0
130
+ while x < fila # primer bucle
131
+ while y < columna # segundo bucle
132
+ cadena += "#{matrix[x][y]} "
133
+ y += 1
134
+ end
135
+ cadena +="\n"
136
+ x += 1
137
+ y = 0
138
+ end
139
+ cadena
140
+ end
141
+
142
+
143
+ def +(o)
144
+ raise unless (o.is_a? Matriz) and (fila == o.fila) and (columna == o.columna)
145
+ mat = []
146
+ x = y = 0
147
+ while x < fila
148
+ while y < columna
149
+ if y == 0
150
+ mat << [matrix[x][y] + o.matrix[x][y]]
151
+ else
152
+ mat[x] << (matrix[x][y] + o.matrix[x][y])
153
+ end
154
+ y += 1
155
+ end
156
+ x += 1
157
+ y = 0
158
+ end
159
+ Matriz.new(mat)
160
+ end
161
+
162
+ def *(o)
163
+ raise unless (o.is_a? Matriz) and (columna == o.fila)
164
+ mat = Array.new(fila) { Array.new(o.columna) }
165
+ for i in 0...@fila do
166
+ for j in 0...o.columna do
167
+ mat[i][j]=Fraccion.new(0,1);
168
+ for k in 0...o.fila do
169
+ mat[i][j] += matrix[i][k] * o.matrix[k][j]
170
+ end
171
+ end
172
+ end
173
+ Matriz.new(mat)
174
+ end
175
+ end
176
+
177
+ class Fraccion #Clase Fraccion
178
+ include Comparable
179
+ attr_accessor :numerador, :denominador
180
+
181
+ def initialize(num, den)
182
+ if den < 0
183
+ num = -num
184
+ den = -den
185
+ end
186
+ if num.kind_of?(Integer) and den.kind_of?(Integer)
187
+ @numerador = num
188
+ @denominador = den
189
+ else
190
+ @numerador = num.to_i
191
+ @denominador = den.to_i
192
+ end
193
+ max=gcd(@numerador,@denominador)
194
+ @numerador=@numerador/max
195
+ @denominador=@denominador/max
196
+ end
197
+
198
+ def to_s #devuelve fraccion formato a/b
199
+ if @denominador == 1
200
+ @numerador.to_s
201
+ else
202
+ @numerador.to_s+"/"+@denominador.to_s
203
+ end
204
+ end
205
+
206
+ def numRacional #Devuelve formato flotante
207
+ @numerador/@denominador
208
+ end
209
+
210
+ def gcd(u, v) #Devuelve maximo como un divisor
211
+ u, v = u.abs, v.abs
212
+ while v != 0
213
+ u, v = v, u % v
214
+ end
215
+ u
216
+ end
217
+
218
+ def ==(o)
219
+ begin
220
+ return ((@numerador == o.numerador) and (@denominador == o.denominador)) if o.instance_of? Fraccion
221
+ false
222
+ rescue
223
+ false
224
+ end
225
+ end
226
+
227
+ def abs
228
+ Fraccion.new(@numerador.abs, @denominador.abs)
229
+ end
230
+
231
+ def reciprocal
232
+ Fraccion.new(@denominador, @numerador)
233
+ end
234
+
235
+ def -@
236
+ Fraccion.new(-@numerador, @denominador)
237
+ end
238
+
239
+
240
+ def +(o)
241
+ # if o.is_a(FixNum)
242
+ # o=Fraccion.new(o,1)
243
+ # end
244
+ Fraccion.new(@numerador*o.denominador + o.numerador*@denominador, @denominador*o.denominador)
245
+ end
246
+
247
+ def -(o)
248
+ Fraccion.new(@numerador*o.denominador - o.numerador*@denominador, @denominador*o.denominador)
249
+ end
250
+
251
+ def *(o)
252
+ if o.is_a?(Fixnum)
253
+ o=Fraccion.new(o,1)
254
+ end
255
+ Fraccion.new(@numerador*o.numerador,@denominador*o.denominador)
256
+ end
257
+
258
+ def /(o)
259
+ Fraccion.new(@numerador*o.denominador,@denominador*o.numerador)
260
+ end
261
+
262
+ def %(o)
263
+ Fraccion.new(@numerador%@denominador, o.numerador%o.denominador)
264
+ end
265
+
266
+ def <=>(o)
267
+ return nil unless o.instance_of? Fraccion
268
+ (@numerador.to_f / @denominador) <=> (o.numerador.to_f / o.denominador)
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,3 @@
1
+ module MatrizSf
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'matriz_sf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "matriz_sf"
8
+ spec.version = MatrizSf::VERSION
9
+ spec.authors = ["Fabio Mendoza Bello & Sebastian Ospina Berrio"]
10
+ spec.email = ["alu0100463910@ull.edu.es"]
11
+ spec.description = %q{Desarrollada por Fabio Mendoza y Sebastian Ospina}
12
+ spec.summary = %q{Practica 10 de LPP}
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
+ spec.add_development_dependency 'rspec', '~> 2.9'
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ include Matriz_sf
3
+
4
+
5
+
6
+ describe Matriz_sf do
7
+
8
+ describe Matriz do
9
+ before :all do
10
+ MM = Matriz.new
11
+ end
12
+
13
+ describe "Matriz padre" do
14
+ it 'Existe una clase abstracta Matriz?' do
15
+ MM.instance_of?(Matriz) == true
16
+ end
17
+ it 'se puede acceder a los atributos (fila)?' do
18
+ MM.fil.should == 0
19
+ end
20
+
21
+ it 'Existe metodo to_s ?' do
22
+ MM.should respond_to("to_s")
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'matriz_sf.rb'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matriz_sf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fabio Mendoza Bello & Sebastian Ospina Berrio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ description: Desarrollada por Fabio Mendoza y Sebastian Ospina
63
+ email:
64
+ - alu0100463910@ull.edu.es
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/matriz_sf.rb
75
+ - lib/matriz_sf/version.rb
76
+ - matriz_sf-0.0.1.gem
77
+ - matriz_sf.gemspec
78
+ - spec/matriz_sf_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.23
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Practica 10 de LPP
105
+ test_files:
106
+ - spec/matriz_sf_spec.rb
107
+ - spec/spec_helper.rb