math_expansion 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.
@@ -0,0 +1,142 @@
1
+ require "./lib/math_expansion/gcd.rb"
2
+
3
+ module MathExpansion
4
+ class Fraccion
5
+ # Módulos usados
6
+ include Comparable
7
+
8
+ # Métodos principales
9
+ def initialize(x,y)
10
+ raise ArgumentError , 'Argumentos no enteros.' unless x.is_a? Fixnum and y.is_a? Fixnum
11
+ raise ArgumentError , 'Denominador nulo.' unless y != 0
12
+
13
+ @num, @den = x, y
14
+ reducir
15
+
16
+ # En caso de ser negativa, la fracción será -a/b, y no a/(-b)
17
+ if(@num < 0 && @den < 0)
18
+ @num = -@num
19
+ @den = -@den
20
+ elsif(@den < 0)
21
+ @den = -@den
22
+ @num = -@num
23
+ end
24
+ end
25
+
26
+ def num()
27
+ @num
28
+ end
29
+
30
+ def den()
31
+ @den
32
+ end
33
+
34
+ def coerce(other)
35
+ [Fraccion.new(other,1),self]
36
+ end
37
+
38
+ def self.null
39
+ Fraccion.new(0,1)
40
+ end
41
+
42
+ def to_s
43
+ "#{@num}/#{@den}"
44
+ end
45
+
46
+ def reducir
47
+ mcd = MathExpansion::gcd(@num,@den)
48
+ @num = @num / mcd
49
+ @den = @den / mcd
50
+ end
51
+
52
+ def to_f
53
+ @num.to_f/@den.to_f
54
+ end
55
+
56
+ # Operadores unarios
57
+ def abs
58
+ a, b = @num, @den
59
+ if @num < 0
60
+ a = @num * (-1)
61
+ end
62
+ if @den < 0
63
+ b = @den * (-1)
64
+ end
65
+ Fraccion.new(a.to_i,b.to_i)
66
+ end
67
+
68
+ def reciprocal
69
+ aux = @num
70
+ @num = @den
71
+ @den = aux
72
+ Fraccion.new(@num,@den)
73
+ end
74
+
75
+ def -@ # Operación negación
76
+ Fraccion.new(-@num, @den)
77
+ end
78
+
79
+ # Operadores aritméticos
80
+ def +(other) # Operación suma
81
+ if(other.respond_to? :den and other.respond_to? :num)
82
+ Fraccion.new(@num*other.den + @den*other.num, @den*other.den) # a/b + c/d = (a*d + b*c)/(b*d)
83
+ else
84
+ Fraccion.new(@num + @den*other, @den) # a/b + c = (a + b*c)/b
85
+ end
86
+ end
87
+
88
+ def -(other) # Operación resta
89
+ if(other.respond_to? :den and other.respond_to? :num)
90
+ Fraccion.new(@num*other.den - @den*other.num, @den*other.den) # a/b - c/d = (a*d - b*c)/(b*d)
91
+ else
92
+ Fraccion.new(@num - @den*other, @den) # a/b - c = (a - b*c)/b
93
+ end
94
+ end
95
+
96
+ def *(other) # Operación producto
97
+ if(other.respond_to? :den and other.respond_to? :num)
98
+ if(@num*other.num == 0)
99
+ Fraccion.null
100
+ else
101
+ Fraccion.new(@num*other.num, @den*other.den) # a/b * c/d = (a*c)/(b*d)
102
+ end
103
+ else
104
+ Fraccion.new(@num*other, @den) # a/b * c = (a*c)/b
105
+ end
106
+ end
107
+
108
+ def /(other) # Operación división
109
+ if(other.respond_to? :den and other.respond_to? :num)
110
+ if(other.num == 0)
111
+ Fraccion.null
112
+ else
113
+ Fraccion.new(@num*other.den, @den*other.num) # a/b / c/d = (a*d)/(b*c)
114
+ end
115
+ else
116
+ if(other == 0)
117
+ Fraccion.null
118
+ else
119
+ Fraccion.new(@num, @den*other)
120
+ end
121
+ end
122
+ end
123
+
124
+ def %(other) # Operación módulo
125
+ raise ArgumentError, 'Argumento no racional' unless other.is_a? Fraccion
126
+
127
+ Fraccion.new(0,1) # Resto de una división de fracciones = siempre nulo (0/1)
128
+ end
129
+
130
+ # Operadores comparacionales
131
+ def <=> (other)
132
+ #raise ArgumentError, 'Argumento no racional' unless other.is_a? Fraccion
133
+
134
+ # a/b <=> c/d -> (a*d)/(b*d) <=> (c*b)/(d*b) -> a*d <=> c*b
135
+ if(other.respond_to? :den and other.respond_to? :num)
136
+ (@num * other.den) <=> (other.num * @den)
137
+ else
138
+ (@num.to_f / @den.to_f) <=> (other)
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,3 @@
1
+ module MathExpansion
2
+ VERSION = "0.0.1"
3
+ end
data/log.html ADDED
@@ -0,0 +1,389 @@
1
+ <!DOCTYPE html>
2
+ <html lang='en'>
3
+ <head>
4
+ <title>RSpec results</title>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <meta http-equiv="Expires" content="-1" />
7
+ <meta http-equiv="Pragma" content="no-cache" />
8
+ <style type="text/css">
9
+ body {
10
+ margin: 0;
11
+ padding: 0;
12
+ background: #fff;
13
+ font-size: 80%;
14
+ }
15
+ </style>
16
+ <script type="text/javascript">
17
+ // <![CDATA[
18
+
19
+ function addClass(element_id, classname) {
20
+ document.getElementById(element_id).className += (" " + classname);
21
+ }
22
+
23
+ function removeClass(element_id, classname) {
24
+ var elem = document.getElementById(element_id);
25
+ var classlist = elem.className.replace(classname,'');
26
+ elem.className = classlist;
27
+ }
28
+
29
+ function moveProgressBar(percentDone) {
30
+ document.getElementById("rspec-header").style.width = percentDone +"%";
31
+ }
32
+
33
+ function makeRed(element_id) {
34
+ removeClass(element_id, 'passed');
35
+ removeClass(element_id, 'not_implemented');
36
+ addClass(element_id,'failed');
37
+ }
38
+
39
+ function makeYellow(element_id) {
40
+ var elem = document.getElementById(element_id);
41
+ if (elem.className.indexOf("failed") == -1) { // class doesn't includes failed
42
+ if (elem.className.indexOf("not_implemented") == -1) { // class doesn't include not_implemented
43
+ removeClass(element_id, 'passed');
44
+ addClass(element_id,'not_implemented');
45
+ }
46
+ }
47
+ }
48
+
49
+ function apply_filters() {
50
+ var passed_filter = document.getElementById('passed_checkbox').checked;
51
+ var failed_filter = document.getElementById('failed_checkbox').checked;
52
+ var pending_filter = document.getElementById('pending_checkbox').checked;
53
+
54
+ assign_display_style("example passed", passed_filter);
55
+ assign_display_style("example failed", failed_filter);
56
+ assign_display_style("example not_implemented", pending_filter);
57
+
58
+ assign_display_style_for_group("example_group passed", passed_filter);
59
+ assign_display_style_for_group("example_group not_implemented", pending_filter, pending_filter || passed_filter);
60
+ assign_display_style_for_group("example_group failed", failed_filter, failed_filter || pending_filter || passed_filter);
61
+ }
62
+
63
+ function get_display_style(display_flag) {
64
+ var style_mode = 'none';
65
+ if (display_flag == true) {
66
+ style_mode = 'block';
67
+ }
68
+ return style_mode;
69
+ }
70
+
71
+ function assign_display_style(classname, display_flag) {
72
+ var style_mode = get_display_style(display_flag);
73
+ var elems = document.getElementsByClassName(classname)
74
+ for (var i=0; i<elems.length;i++) {
75
+ elems[i].style.display = style_mode;
76
+ }
77
+ }
78
+
79
+ function assign_display_style_for_group(classname, display_flag, subgroup_flag) {
80
+ var display_style_mode = get_display_style(display_flag);
81
+ var subgroup_style_mode = get_display_style(subgroup_flag);
82
+ var elems = document.getElementsByClassName(classname)
83
+ for (var i=0; i<elems.length;i++) {
84
+ var style_mode = display_style_mode;
85
+ if ((display_flag != subgroup_flag) && (elems[i].getElementsByTagName('dt')[0].innerHTML.indexOf(", ") != -1)) {
86
+ elems[i].style.display = subgroup_style_mode;
87
+ } else {
88
+ elems[i].style.display = display_style_mode;
89
+ }
90
+ }
91
+ }
92
+
93
+ // ]]>
94
+ </script>
95
+ <style type="text/css">
96
+ #rspec-header {
97
+ background: #65C400; color: #fff; height: 4em;
98
+ }
99
+
100
+ .rspec-report h1 {
101
+ margin: 0px 10px 0px 10px;
102
+ padding: 10px;
103
+ font-family: "Lucida Grande", Helvetica, sans-serif;
104
+ font-size: 1.8em;
105
+ position: absolute;
106
+ }
107
+
108
+ #label {
109
+ float:left;
110
+ }
111
+
112
+ #display-filters {
113
+ float:left;
114
+ padding: 28px 0 0 40%;
115
+ font-family: "Lucida Grande", Helvetica, sans-serif;
116
+ }
117
+
118
+ #summary {
119
+ float:right;
120
+ padding: 5px 10px;
121
+ font-family: "Lucida Grande", Helvetica, sans-serif;
122
+ text-align: right;
123
+ }
124
+
125
+ #summary p {
126
+ margin: 0 0 0 2px;
127
+ }
128
+
129
+ #summary #totals {
130
+ font-size: 1.2em;
131
+ }
132
+
133
+ .example_group {
134
+ margin: 0 10px 5px;
135
+ background: #fff;
136
+ }
137
+
138
+ dl {
139
+ margin: 0; padding: 0 0 5px;
140
+ font: normal 11px "Lucida Grande", Helvetica, sans-serif;
141
+ }
142
+
143
+ dt {
144
+ padding: 3px;
145
+ background: #65C400;
146
+ color: #fff;
147
+ font-weight: bold;
148
+ }
149
+
150
+ dd {
151
+ margin: 5px 0 5px 5px;
152
+ padding: 3px 3px 3px 18px;
153
+ }
154
+
155
+ dd .duration {
156
+ padding-left: 5px;
157
+ text-align: right;
158
+ right: 0px;
159
+ float:right;
160
+ }
161
+
162
+ dd.example.passed {
163
+ border-left: 5px solid #65C400;
164
+ border-bottom: 1px solid #65C400;
165
+ background: #DBFFB4; color: #3D7700;
166
+ }
167
+
168
+ dd.example.not_implemented {
169
+ border-left: 5px solid #FAF834;
170
+ border-bottom: 1px solid #FAF834;
171
+ background: #FCFB98; color: #131313;
172
+ }
173
+
174
+ dd.example.pending_fixed {
175
+ border-left: 5px solid #0000C2;
176
+ border-bottom: 1px solid #0000C2;
177
+ color: #0000C2; background: #D3FBFF;
178
+ }
179
+
180
+ dd.example.failed {
181
+ border-left: 5px solid #C20000;
182
+ border-bottom: 1px solid #C20000;
183
+ color: #C20000; background: #FFFBD3;
184
+ }
185
+
186
+
187
+ dt.not_implemented {
188
+ color: #000000; background: #FAF834;
189
+ }
190
+
191
+ dt.pending_fixed {
192
+ color: #FFFFFF; background: #C40D0D;
193
+ }
194
+
195
+ dt.failed {
196
+ color: #FFFFFF; background: #C40D0D;
197
+ }
198
+
199
+
200
+ #rspec-header.not_implemented {
201
+ color: #000000; background: #FAF834;
202
+ }
203
+
204
+ #rspec-header.pending_fixed {
205
+ color: #FFFFFF; background: #C40D0D;
206
+ }
207
+
208
+ #rspec-header.failed {
209
+ color: #FFFFFF; background: #C40D0D;
210
+ }
211
+
212
+
213
+ .backtrace {
214
+ color: #000;
215
+ font-size: 12px;
216
+ }
217
+
218
+ a {
219
+ color: #BE5C00;
220
+ }
221
+
222
+ /* Ruby code, style similar to vibrant ink */
223
+ .ruby {
224
+ font-size: 12px;
225
+ font-family: monospace;
226
+ color: white;
227
+ background-color: black;
228
+ padding: 0.1em 0 0.2em 0;
229
+ }
230
+
231
+ .ruby .keyword { color: #FF6600; }
232
+ .ruby .constant { color: #339999; }
233
+ .ruby .attribute { color: white; }
234
+ .ruby .global { color: white; }
235
+ .ruby .module { color: white; }
236
+ .ruby .class { color: white; }
237
+ .ruby .string { color: #66FF00; }
238
+ .ruby .ident { color: white; }
239
+ .ruby .method { color: #FFCC00; }
240
+ .ruby .number { color: white; }
241
+ .ruby .char { color: white; }
242
+ .ruby .comment { color: #9933CC; }
243
+ .ruby .symbol { color: white; }
244
+ .ruby .regex { color: #44B4CC; }
245
+ .ruby .punct { color: white; }
246
+ .ruby .escape { color: white; }
247
+ .ruby .interp { color: white; }
248
+ .ruby .expr { color: white; }
249
+
250
+ .ruby .offending { background-color: gray; }
251
+ .ruby .linenum {
252
+ width: 75px;
253
+ padding: 0.1em 1em 0.2em 0;
254
+ color: #000000;
255
+ background-color: #FFFBD3;
256
+ }
257
+
258
+ </style>
259
+ </head>
260
+ <body>
261
+ <div class="rspec-report">
262
+
263
+ <div id="rspec-header">
264
+ <div id="label">
265
+ <h1>RSpec Code Examples</h1>
266
+ </div>
267
+
268
+ <div id="display-filters">
269
+ <input id="passed_checkbox" name="passed_checkbox" type="checkbox" checked="checked" onchange="apply_filters()" value="1" /> <label for="passed_checkbox">Passed</label>
270
+ <input id="failed_checkbox" name="failed_checkbox" type="checkbox" checked="checked" onchange="apply_filters()" value="2" /> <label for="failed_checkbox">Failed</label>
271
+ <input id="pending_checkbox" name="pending_checkbox" type="checkbox" checked="checked" onchange="apply_filters()" value="3" /> <label for="pending_checkbox">Pending</label>
272
+ </div>
273
+
274
+ <div id="summary">
275
+ <p id="totals">&#160;</p>
276
+ <p id="duration">&#160;</p>
277
+ </div>
278
+ </div>
279
+
280
+
281
+ <div class="results">
282
+ <div id="div_group_1" class="example_group passed">
283
+ <dl style="margin-left: 0px;">
284
+ <dt id="example_group_1" class="passed">MathExpansion::Matriz</dt>
285
+ </dl>
286
+ </div>
287
+ <div id="div_group_2" class="example_group passed">
288
+ <dl style="margin-left: 15px;">
289
+ <dt id="example_group_2" class="passed"> # Almacenamiento de matrices. </dt>
290
+ <script type="text/javascript">moveProgressBar('4.1');</script>
291
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe almacenar el numero de filas.</span><span class='duration'>0.00000s</span></dd>
292
+ <script type="text/javascript">moveProgressBar('8.3');</script>
293
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe almacenar el numero de columnas.</span><span class='duration'>0.00000s</span></dd>
294
+ <script type="text/javascript">moveProgressBar('12.5');</script>
295
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe almacenar un contenido.</span><span class='duration'>0.00000s</span></dd>
296
+ </dl>
297
+ </div>
298
+ <div id="div_group_3" class="example_group passed">
299
+ <dl style="margin-left: 0px;">
300
+ <dt id="example_group_3" class="passed">MathExpansion::Matriz_Densa</dt>
301
+ </dl>
302
+ </div>
303
+ <div id="div_group_4" class="example_group passed">
304
+ <dl style="margin-left: 15px;">
305
+ <dt id="example_group_4" class="passed"> # Almacenamiento de matrices. </dt>
306
+ <script type="text/javascript">moveProgressBar('16.6');</script>
307
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder acceder a los datos almacenados en la matriz </span><span class='duration'>0.00200s</span></dd>
308
+ <script type="text/javascript">moveProgressBar('20.8');</script>
309
+ <dd class="example passed"><span class="passed_spec_name"> # Se deben poder modificar los datos almacenados en la matriz </span><span class='duration'>0.00000s</span></dd>
310
+ <script type="text/javascript">moveProgressBar('25.0');</script>
311
+ <dd class="example passed"><span class="passed_spec_name"> # Se deben poder almacenar todo tipo de datos numericos (flotantes, enteros, etc...) </span><span class='duration'>0.00000s</span></dd>
312
+ </dl>
313
+ </div>
314
+ <div id="div_group_5" class="example_group passed">
315
+ <dl style="margin-left: 15px;">
316
+ <dt id="example_group_5" class="passed"> # Operaciones con matrices densas. </dt>
317
+ <script type="text/javascript">moveProgressBar('29.1');</script>
318
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder sumar dos matrices </span><span class='duration'>0.00000s</span></dd>
319
+ <script type="text/javascript">moveProgressBar('33.3');</script>
320
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder restar dos matrices </span><span class='duration'>0.00100s</span></dd>
321
+ <script type="text/javascript">moveProgressBar('37.5');</script>
322
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder multiplicar dos matrices </span><span class='duration'>0.00000s</span></dd>
323
+ <script type="text/javascript">moveProgressBar('41.6');</script>
324
+ <dd class="example passed"><span class="passed_spec_name"> # Si una m. densa tiene mas de un 60% de nulos, debe ser dispersa.</span><span class='duration'>0.00000s</span></dd>
325
+ <script type="text/javascript">moveProgressBar('45.8');</script>
326
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder operar con Fracciones.</span><span class='duration'>0.00100s</span></dd>
327
+ </dl>
328
+ </div>
329
+ <div id="div_group_6" class="example_group passed">
330
+ <dl style="margin-left: 15px;">
331
+ <dt id="example_group_6" class="passed"> # Operaciones varias. </dt>
332
+ <script type="text/javascript">moveProgressBar('50.0');</script>
333
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder calcular el maximo de una matriz densa (elemento no nulo)</span><span class='duration'>0.00000s</span></dd>
334
+ <script type="text/javascript">moveProgressBar('54.1');</script>
335
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder calcular el minimo de una matriz densa (elemento no nulo)</span><span class='duration'>0.00000s</span></dd>
336
+ </dl>
337
+ </div>
338
+ <div id="div_group_7" class="example_group passed">
339
+ <dl style="margin-left: 0px;">
340
+ <dt id="example_group_7" class="passed">MathExpansion::Matriz_Dispersa</dt>
341
+ </dl>
342
+ </div>
343
+ <div id="div_group_8" class="example_group passed">
344
+ <dl style="margin-left: 15px;">
345
+ <dt id="example_group_8" class="passed"> # Almacenamiento de matrices. </dt>
346
+ <script type="text/javascript">moveProgressBar('58.3');</script>
347
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder crear matrices dispersas vacias o a partir de matrices densas.</span><span class='duration'>0.00000s</span></dd>
348
+ <script type="text/javascript">moveProgressBar('62.5');</script>
349
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder calcular el porcentaje de elementos nulos de la matriz dispersa.</span><span class='duration'>0.00000s</span></dd>
350
+ <script type="text/javascript">moveProgressBar('66.6');</script>
351
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder acceder a los elementos de la matriz dispersa.</span><span class='duration'>0.00000s</span></dd>
352
+ Borrado el elemento 1,0 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
353
+ Borrado el elemento 1,1 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
354
+ Borrado el elemento 2,0 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
355
+ Borrado el elemento 2,1 por sobrepasar el numero de elementos no nulos (Porcentaje actual: 0.6666666666666666
356
+ <script type="text/javascript">moveProgressBar('70.8');</script>
357
+ <dd class="example passed"><span class="passed_spec_name"> # Se deben poder modificar los elementos de la matriz dispersa.</span><span class='duration'>0.00100s</span></dd>
358
+ <script type="text/javascript">moveProgressBar('75.0');</script>
359
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder transformar una matriz dispersa a una cadena de caracteres.</span><span class='duration'>0.00000s</span></dd>
360
+ </dl>
361
+ </div>
362
+ <div id="div_group_9" class="example_group passed">
363
+ <dl style="margin-left: 15px;">
364
+ <dt id="example_group_9" class="passed"> # Operaciones con matrices dispersas. </dt>
365
+ <script type="text/javascript">moveProgressBar('79.1');</script>
366
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder sumar dos matrices </span><span class='duration'>0.00100s</span></dd>
367
+ <script type="text/javascript">moveProgressBar('83.3');</script>
368
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder restar dos matrices </span><span class='duration'>0.00000s</span></dd>
369
+ <script type="text/javascript">moveProgressBar('87.5');</script>
370
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder multiplicar dos matrices </span><span class='duration'>0.00000s</span></dd>
371
+ <script type="text/javascript">moveProgressBar('91.6');</script>
372
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder hacer operaciones con Fracciones. </span><span class='duration'>0.00100s</span></dd>
373
+ </dl>
374
+ </div>
375
+ <div id="div_group_10" class="example_group passed">
376
+ <dl style="margin-left: 15px;">
377
+ <dt id="example_group_10" class="passed"> # Operaciones varias. </dt>
378
+ <script type="text/javascript">moveProgressBar('95.8');</script>
379
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder calcular el maximo de una matriz densa (elemento no nulo)</span><span class='duration'>0.00000s</span></dd>
380
+ <script type="text/javascript">moveProgressBar('100.0');</script>
381
+ <dd class="example passed"><span class="passed_spec_name"> # Se debe poder calcular el minimo de una matriz densa (elemento no nulo)</span><span class='duration'>0.00000s</span></dd>
382
+ </dl>
383
+ </div>
384
+ <script type="text/javascript">document.getElementById('duration').innerHTML = "Finished in <strong>1.24807 seconds</strong>";</script>
385
+ <script type="text/javascript">document.getElementById('totals').innerHTML = "24 examples, 0 failures";</script>
386
+ </div>
387
+ </div>
388
+ </body>
389
+ </html>