matrizdispersascp 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.
@@ -0,0 +1,141 @@
1
+ # Etsii ull grado informática
2
+ # Lenguajes y Paradigmas de la programacion
3
+ # Pedro Javier Núñez Rodríguez
4
+ # Constanza Leon Baritussio
5
+ # Fichero de expectativas para las clases MatrizDensa y MatrizDispersa
6
+
7
+ require 'spec_helper'
8
+ require 'matrizdispersascp'
9
+ include Matrizdispersascp
10
+
11
+ describe "Pruebas Matrices" do
12
+ #############################################################################
13
+ describe "Matrices densas" do # Expectativas para la clase matrices densas
14
+ #############################################################################
15
+ @matrizA
16
+ @matrizB
17
+ before :each do
18
+
19
+ # Matrices densas
20
+ @matrizA = MatrizDensa.new([[1, 1], [2, 2]])
21
+ @matrizB = MatrizDensa.new([[1, 1], [2, 2]])
22
+
23
+ end
24
+
25
+ describe "Metodos para la comprobacion de la inicialización y asignacion de valores" do
26
+
27
+ it "Se inicializa correctamente la matriz " do # Comprobamos que todas las casillas estan a cero cuando se crea el objeto
28
+ @matrizA.matriz[0][0].should == 1
29
+ @matrizA.matriz[1][0].should == 2
30
+ end
31
+
32
+ it "Asignamos valores a posiciones de la matriz" do
33
+ @matrizA[1,1] = 4
34
+ @matrizA[0,1] = 2
35
+ @matrizA.matriz[1][1].should == 4
36
+ @matrizA.matriz[0][1].should == 2
37
+ end
38
+ end
39
+
40
+ describe "Metodos para el cambio de formato a string y a flotante" do
41
+
42
+ it "La matriz se muestra en formato string" do
43
+ @matrizA.to_s.should == "{{1,1}{2,2}}"
44
+ end
45
+
46
+ it "La matriz se muestra en formato flotante" do
47
+ @matrizA.to_f.should == "{{1.0,1.0}{2.0,2.0}}"
48
+ end
49
+ end
50
+
51
+ describe "Metodo para la negacion" do
52
+
53
+ it "La matriz negada con el simbolo -" do
54
+ @matrizC = -@matrizA
55
+ @matrizC.to_s.should == "{{-1,-1}{-2,-2}}"
56
+ end
57
+ end
58
+
59
+ describe "Metodos para la comprobacion de operaciones entre matrices" do
60
+
61
+ it "Se suman las matrices" do
62
+ @matrizC = (@matrizA + @matrizB)
63
+ @matrizC.to_s.should == "{{2,2}{4,4}}"
64
+ end
65
+
66
+ it "Se restan las matrices" do
67
+ @matrizC = (@matrizA - @matrizB)
68
+ @matrizC.to_s.should == "{{0,0}{0,0}}"
69
+ end
70
+
71
+ it "Se multiplican las mastrices" do
72
+ @matrizC = (@matrizA * @matrizB)
73
+ @matrizC.to_s.should == "{{3,3}{6,6}}"
74
+ end
75
+ end
76
+
77
+ describe "Metodos para calcular maximos y minimos" do
78
+
79
+ it "Maximo de una matriz" do
80
+ @matrizA.max.should == 2.0
81
+ end
82
+
83
+ it "Minimo de una matriz" do
84
+ @matrizA.min.should == 1.0
85
+ end
86
+ end
87
+ end
88
+
89
+ ###############################################################################
90
+ describe "Matrices dispersas" do # Expectativas para la clase matrices dispersas
91
+ ###############################################################################
92
+ @matrizA
93
+ @matrizB
94
+ before :each do
95
+
96
+ # Matrices dispersas
97
+ mat1 = [nil, {1 =>3}]
98
+ mat2 = [nil, {1 =>4}]
99
+ @matrizA = MatrizDispersa.new(mat1)
100
+ @matrizB = MatrizDispersa.new(mat2)
101
+ end
102
+
103
+ describe "Metodos para el cambio de formato a string y a flotante" do
104
+
105
+ it "La matriz se muestra en formato string" do
106
+ @matrizA.to_s.should == "{{0, 0}}{0, 3}}"
107
+ @matrizB.to_s.should == "{{0, 0}}{0, 4}}"
108
+ end
109
+
110
+ it "La matriz se muestra en formato flotante" do
111
+ @matrizA.to_f.should.to_s == MatrizDispersa.new([nil,{1 =>3.0}]).to_f.to_s
112
+ end
113
+
114
+ end
115
+
116
+ describe "Metodo para la comprobacion de operaciones aritmeticas" do
117
+ it "se suman dos matrices dispersas" do
118
+ (@matrizA + @matrizA).to_s.should == "{{0, 0}}{0, 6}}"
119
+
120
+ end
121
+
122
+ it "Se restan dos matrices dispersas" do
123
+ (@matrizA - @matrizB).to_s.should == "{{0, 0}}{0, -1}}"
124
+ end
125
+ end
126
+
127
+ describe "Metodo para la comprobacion de maximos y minimos" do
128
+ it "se suman dos matrices dispersas" do
129
+ (@matrizA + @matrizA).to_s.should == "{{0, 0}}{0, 6}}"
130
+
131
+ end
132
+
133
+ it "Se restan dos matrices dispersas" do
134
+ (@matrizA - @matrizB).to_s.should == "{{0, 0}}{0, -1}}"
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+
141
+
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matrizdispersascp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - constanza leon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-19 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,10 +41,7 @@ dependencies:
41
41
  description: Esqueleto de una gema
42
42
  email:
43
43
  - alu0100673647@ull.edu.es
44
- executables:
45
- - matrizdispersa.rb
46
- - matrizdispersa.rb~
47
- - matrizdispersascp
44
+ executables: []
48
45
  extensions: []
49
46
  extra_rdoc_files: []
50
47
  files:
@@ -55,18 +52,19 @@ files:
55
52
  - LICENSE.txt
56
53
  - README.md
57
54
  - Rakefile
58
- - bin/matrizdispersa.rb
59
- - bin/matrizdispersa.rb~
60
- - bin/matrizdispersascp
61
55
  - lib/fraccion.rb
62
56
  - lib/matriz.rb
63
57
  - lib/matriz.rb~
64
- - lib/matrizdispersa.rb
65
58
  - lib/matrizdispersa.rb~
66
59
  - lib/matrizdispersascp.rb
60
+ - lib/matrizdispersascp.rb~
67
61
  - lib/matrizdispersascp/version.rb
68
62
  - lib/mcd.rb
69
63
  - matrizdispersascp.gemspec
64
+ - spec/matricesdispersascp_spec.rb
65
+ - spec/matrizdispersascp_spec.rb
66
+ - spec/matrizdispersascp_spec.rb~
67
+ - spec/spec_helper.rb
70
68
  homepage: https://github.com/Alu0100673647/prct09
71
69
  licenses:
72
70
  - MIT
@@ -91,5 +89,9 @@ rubygems_version: 2.0.3
91
89
  signing_key:
92
90
  specification_version: 4
93
91
  summary: Esqueleto de una gema
94
- test_files: []
92
+ test_files:
93
+ - spec/matricesdispersascp_spec.rb
94
+ - spec/matrizdispersascp_spec.rb
95
+ - spec/matrizdispersascp_spec.rb~
96
+ - spec/spec_helper.rb
95
97
  has_rdoc:
@@ -1,46 +0,0 @@
1
- require 'Matrix'
2
-
3
- class SparseVector
4
- attr_reader :vector
5
-
6
- def initialize(h = {})
7
- @vector = Hash.new(0)
8
- @vector = @vector.merge!(h)
9
- end
10
-
11
- def [](i)
12
- @vector[i]
13
- end
14
-
15
- def to_s
16
- @vector.to_s
17
- end
18
- end
19
-
20
- class SparseMatrix
21
-
22
- attr_reader :matrix
23
-
24
- def initialize(h = {})
25
- @matrix = Hash.new({})
26
- for k in h.keys do
27
- @matrix[k] = if h[k].is_a? SparseVector
28
- h[k]
29
- else
30
- @matrix[k] = SparseVector.new(h[k])
31
- end
32
- end
33
- end
34
-
35
- def [](i)
36
- @matrix[i]
37
- end
38
-
39
- def col(j)
40
- c = {}
41
- for r in @matrix.keys do
42
- c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j
43
- end
44
- SparseVector.new c
45
- end
46
- end
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'matrizdispersascp'
@@ -1,46 +0,0 @@
1
- require './matriz.rb'
2
-
3
- class Vectordisperso
4
- attr_reader :vector
5
-
6
- def initialize(h = {})
7
- @vector = Hash.new(0)
8
- @vector = @vector.merge!(h)
9
- end
10
-
11
- def [](i)
12
- @vector[i]
13
- end
14
-
15
- def to_s
16
- @vector.to_s
17
- end
18
- end
19
-
20
- class Matrixdispersa
21
-
22
- attr_reader :matrix
23
-
24
- def initialize(h = {})
25
- @matrix = Hash.new({})
26
- for k in h.keys do
27
- @matrix[k] = if h[k].is_a? Vectordisperso
28
- h[k]
29
- else
30
- @matrix[k] = Vectordisperso.new(h[k])
31
- end
32
- end
33
- end
34
-
35
- def [](i)
36
- @matrix[i]
37
- end
38
-
39
- def col(j)
40
- c = {}
41
- for r in @matrix.keys do
42
- c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j
43
- end
44
- Vectordisperso.new c
45
- end
46
- end