lppexam 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.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +22 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +91 -0
- data/Guardfile +38 -0
- data/Guardfile.example +39 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +46 -0
- data/docs/prct10.pdf +0 -0
- data/docs/prct11.pdf +0 -0
- data/docs/prct5.pdf +0 -0
- data/docs/prct6.pdf +0 -0
- data/docs/prct7.pdf +0 -0
- data/docs/prct8.pdf +0 -0
- data/docs/prct9.pdf +0 -0
- data/exam.gemspec +30 -0
- data/lib/List.rb +175 -0
- data/lib/Quiz.rb +112 -0
- data/lib/exam/version.rb +5 -0
- data/lib/exam.rb +126 -0
- data/lib/quiz_dsl.rb +84 -0
- data/spec/exam_spec.rb +139 -0
- data/spec/list_exam_spec.rb +80 -0
- data/spec/quiz_dsl_spec.rb +131 -0
- data/spec/quiz_spec.rb +117 -0
- data/spec/spec_helper.rb +10 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6a96f690c53163d60d74691fa399c695dc5de16
|
4
|
+
data.tar.gz: c81e813f9ccd4610558d6411d08f90b94efc1fb9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe6d4b4095635ded18c1da8ae3eb631a6ef1a259ea023207631def1894ec167fdc4dcbb5c12b7bae0b27485419b3c96028c489fa071f3e091667f86379f62b0b
|
7
|
+
data.tar.gz: 9d72311e22fbf2dfe20e0f6550855e8f3adb433d75c66714e74b28da64c910efd775f3a57adbc0e8e5692141952cba2edbdd387eebdb0f4f6d29a86b21d2169f
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Evitar almacenar los ficheros temporales
|
2
|
+
*~
|
3
|
+
*swp
|
4
|
+
# Evitar almacenar los ficheros con extension .o
|
5
|
+
*.o
|
6
|
+
# Evitar almacenar los ficheros con extension .class
|
7
|
+
*.class
|
8
|
+
# Bundle
|
9
|
+
/.bundle/
|
10
|
+
/.yardoc
|
11
|
+
/Gemfile.lock
|
12
|
+
/_yardoc/
|
13
|
+
/coverage/
|
14
|
+
/doc/
|
15
|
+
/pkg/
|
16
|
+
/spec/reports/
|
17
|
+
/tmp/
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lppexam (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
celluloid (0.16.0)
|
10
|
+
timers (~> 4.0.0)
|
11
|
+
coderay (1.1.0)
|
12
|
+
coveralls (0.7.1)
|
13
|
+
multi_json (~> 1.3)
|
14
|
+
rest-client
|
15
|
+
simplecov (>= 0.7)
|
16
|
+
term-ansicolor
|
17
|
+
thor
|
18
|
+
diff-lcs (1.2.5)
|
19
|
+
docile (1.1.5)
|
20
|
+
ffi (1.9.6)
|
21
|
+
formatador (0.2.5)
|
22
|
+
guard (2.7.1)
|
23
|
+
formatador (>= 0.2.4)
|
24
|
+
listen (~> 2.7)
|
25
|
+
lumberjack (~> 1.0)
|
26
|
+
pry (>= 0.9.12)
|
27
|
+
thor (>= 0.18.1)
|
28
|
+
guard-bundler (2.0.0)
|
29
|
+
bundler (~> 1.0)
|
30
|
+
guard (~> 2.2)
|
31
|
+
guard-rspec (4.3.1)
|
32
|
+
guard (~> 2.1)
|
33
|
+
rspec (>= 2.14, < 4.0)
|
34
|
+
hitimes (1.2.2)
|
35
|
+
listen (2.7.11)
|
36
|
+
celluloid (>= 0.15.2)
|
37
|
+
rb-fsevent (>= 0.9.3)
|
38
|
+
rb-inotify (>= 0.9)
|
39
|
+
lumberjack (1.0.9)
|
40
|
+
method_source (0.8.2)
|
41
|
+
mime-types (2.4.3)
|
42
|
+
multi_json (1.10.1)
|
43
|
+
netrc (0.8.0)
|
44
|
+
pry (0.10.1)
|
45
|
+
coderay (~> 1.1.0)
|
46
|
+
method_source (~> 0.8.1)
|
47
|
+
slop (~> 3.4)
|
48
|
+
rake (10.3.2)
|
49
|
+
rb-fsevent (0.9.4)
|
50
|
+
rb-inotify (0.9.5)
|
51
|
+
ffi (>= 0.5.0)
|
52
|
+
rest-client (1.7.2)
|
53
|
+
mime-types (>= 1.16, < 3.0)
|
54
|
+
netrc (~> 0.7)
|
55
|
+
rspec (3.1.0)
|
56
|
+
rspec-core (~> 3.1.0)
|
57
|
+
rspec-expectations (~> 3.1.0)
|
58
|
+
rspec-mocks (~> 3.1.0)
|
59
|
+
rspec-core (3.1.7)
|
60
|
+
rspec-support (~> 3.1.0)
|
61
|
+
rspec-expectations (3.1.2)
|
62
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
63
|
+
rspec-support (~> 3.1.0)
|
64
|
+
rspec-mocks (3.1.3)
|
65
|
+
rspec-support (~> 3.1.0)
|
66
|
+
rspec-support (3.1.2)
|
67
|
+
simplecov (0.9.1)
|
68
|
+
docile (~> 1.1.0)
|
69
|
+
multi_json (~> 1.0)
|
70
|
+
simplecov-html (~> 0.8.0)
|
71
|
+
simplecov-html (0.8.0)
|
72
|
+
slop (3.6.0)
|
73
|
+
term-ansicolor (1.3.0)
|
74
|
+
tins (~> 1.0)
|
75
|
+
thor (0.19.1)
|
76
|
+
timers (4.0.1)
|
77
|
+
hitimes
|
78
|
+
tins (1.3.3)
|
79
|
+
|
80
|
+
PLATFORMS
|
81
|
+
ruby
|
82
|
+
|
83
|
+
DEPENDENCIES
|
84
|
+
bundler (~> 1.7)
|
85
|
+
coveralls
|
86
|
+
guard
|
87
|
+
guard-bundler
|
88
|
+
guard-rspec
|
89
|
+
lppexam!
|
90
|
+
rake (~> 10.0)
|
91
|
+
rspec
|
data/Guardfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :bundler do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if your Gemfile contains the `gemspec' command.
|
7
|
+
# watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
11
|
+
# rspec may be run, below are examples of the most common uses.
|
12
|
+
# * bundler: 'bundle exec rspec'
|
13
|
+
# * bundler binstubs: 'bin/rspec'
|
14
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
15
|
+
# installed the spring binstubs per the docs)
|
16
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
17
|
+
# * 'just' rspec: 'rspec'
|
18
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
19
|
+
watch(%r{^spec/.+_spec\.rb$})
|
20
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
21
|
+
watch('spec/spec_helper.rb') { "spec" }
|
22
|
+
|
23
|
+
# Rails example
|
24
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
25
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
26
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
27
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
28
|
+
watch('config/routes.rb') { "spec/routing" }
|
29
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
30
|
+
watch('spec/rails_helper.rb') { "spec" }
|
31
|
+
|
32
|
+
# Capybara features specs
|
33
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
34
|
+
|
35
|
+
# Turnip features and steps
|
36
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
37
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
38
|
+
end
|
data/Guardfile.example
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :bundler do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if your Gemfile contains the `gemspec' command.
|
7
|
+
# watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
11
|
+
# rspec may be run, below are examples of the most common uses.
|
12
|
+
# * bundler: 'bundle exec rspec'
|
13
|
+
# * bundler binstubs: 'bin/rspec'
|
14
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
15
|
+
# installed the spring binstubs per the docs)
|
16
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
17
|
+
# * 'just' rspec: 'rspec'
|
18
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
19
|
+
watch(%r{^spec/.+_spec\.rb$})
|
20
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
21
|
+
watch('spec/spec_helper.rb') { "spec" }
|
22
|
+
|
23
|
+
# Rails example
|
24
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
25
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
26
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
27
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
28
|
+
watch('config/routes.rb') { "spec/routing" }
|
29
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
30
|
+
watch('spec/rails_helper.rb') { "spec" }
|
31
|
+
|
32
|
+
# Capybara features specs
|
33
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
34
|
+
|
35
|
+
# Turnip features and steps
|
36
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
37
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
38
|
+
end
|
39
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Raul Perez
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
[](https://coveralls.io/r/rperezh/prct08?branch=prct11)
|
2
|
+
[](https://travis-ci.org/rperezh/prct08)
|
3
|
+
|
4
|
+
# Exam
|
5
|
+
|
6
|
+
1. Práctica de Laboratorio #05. Desarrollo Dirigido por Pruebas (TDD).
|
7
|
+
2. Práctica de Laboratorio #06. Programación Orientada a Objetos.
|
8
|
+
3. Práctica de Laboratorio #07. Programación Orientada a Objetos. Herencia.
|
9
|
+
4. Práctica de Laboratorio #08. Programación Orientada a Objetos. Módulos.
|
10
|
+
5. Práctica de Laboratorio #09. Programación Orientada a Objetos. Singletons.
|
11
|
+
6. Práctica de Laboratorio #10. Programación Funcional. Funciones de orden superior. Archivo
|
12
|
+
7. Práctica de Laboratorio #11. Lenguajes de Dominio Específico (DSL - Domain Specific Languages).
|
13
|
+
|
14
|
+
* Raul Perez Hernandez (https://bitbucket.org/rperezh)
|
15
|
+
* Dailos Sabina Rodríguez (https://bitbucket.org/alu0100353259)
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'exam'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install exam
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
TODO: Write usage instructions here
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( https://github.com/[my-github-username]/exam/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
task :default => :spec
|
4
|
+
|
5
|
+
desc 'Run RSpec code examples exam'
|
6
|
+
task :spec do
|
7
|
+
sh 'rspec spec/exam_spec.rb'
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Run Ruby files from lib folder'
|
11
|
+
task :bin do
|
12
|
+
sh 'ruby -I. lib/exam.rb'
|
13
|
+
sh 'ruby -I. lib/List.rb'
|
14
|
+
sh 'ruby -I. lib/Quiz.rb'
|
15
|
+
sh 'ruby -I. lib/quiz_dsl.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Run test with --format documentation'
|
19
|
+
task :test do
|
20
|
+
sh 'rspec spec/exam_spec.rb --format documentation'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Run test with format: html'
|
24
|
+
task :thtml do
|
25
|
+
sh 'rspec spec/exam_spec.rb --format html'
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Run RSpec exam list'
|
29
|
+
task :list do
|
30
|
+
sh 'rspec spec/list_exam_spec.rb'
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Run RSpec Quiz'
|
34
|
+
task :quiz do
|
35
|
+
sh 'rspec spec/quiz_spec.rb'
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Genera la documentacion de la GEM'
|
39
|
+
task :rdoc do
|
40
|
+
sh 'rdoc --exclude Gemfile --exclude Guardfile --exclude Rakefile --exclude rspec_*'
|
41
|
+
end
|
42
|
+
|
43
|
+
desc 'Run RSpec Quiz DSL'
|
44
|
+
task :dsl do
|
45
|
+
sh 'rspec spec/quiz_dsl_spec.rb'
|
46
|
+
end
|
data/docs/prct10.pdf
ADDED
Binary file
|
data/docs/prct11.pdf
ADDED
Binary file
|
data/docs/prct5.pdf
ADDED
Binary file
|
data/docs/prct6.pdf
ADDED
Binary file
|
data/docs/prct7.pdf
ADDED
Binary file
|
data/docs/prct8.pdf
ADDED
Binary file
|
data/docs/prct9.pdf
ADDED
Binary file
|
data/exam.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'exam/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lppexam"
|
8
|
+
spec.version = Exam::VERSION
|
9
|
+
spec.authors = ["Raul Perez"]
|
10
|
+
spec.email = ["rperezh@ull.edu.es"]
|
11
|
+
spec.summary = "Desarrollo Dirigido por Pruebas (TDD)" # %q{TODO: Write a short summary. Required.}
|
12
|
+
spec.description = "" # %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
# Uso de la herramienta Guard
|
25
|
+
spec.add_development_dependency "guard"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
spec.add_development_dependency "guard-bundler"
|
28
|
+
# Uso de la herramienta Coverall
|
29
|
+
spec.add_development_dependency "coveralls"
|
30
|
+
end
|
data/lib/List.rb
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# = List.rb
|
2
|
+
#
|
3
|
+
# Autor:: Dailos Sabina Rodriguez
|
4
|
+
# Autor:: Raul Perez Hernandez
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# === Clase Node
|
8
|
+
# Definición de la clase Node que permite almacenar y representar un nodo con un elemento anterior y otor posterior por pantalla mediante los siguientes metodos
|
9
|
+
# * metodo initialize
|
10
|
+
# * metodo to_s
|
11
|
+
# * metodo dev_value
|
12
|
+
# * metodo dev_sig
|
13
|
+
# * metodo dev_ant
|
14
|
+
# * metodo mod_sig
|
15
|
+
# * metodo mod_ant
|
16
|
+
#
|
17
|
+
|
18
|
+
Node = Struct.new(:value, :sig, :ant) do
|
19
|
+
# Metodo para inicializar la clase
|
20
|
+
def initialize (value, sig, ant)
|
21
|
+
@value = value
|
22
|
+
@sig = sig
|
23
|
+
@ant = ant
|
24
|
+
end
|
25
|
+
|
26
|
+
# Metodo para mostrar por pantalla un nodo
|
27
|
+
def to_s
|
28
|
+
if @sig == nil && @ant == nil
|
29
|
+
"#{@value} "
|
30
|
+
else
|
31
|
+
"#{@value} <-> "
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Funcion para obtener el valor de un nodo
|
36
|
+
def dev_value
|
37
|
+
return @value
|
38
|
+
end
|
39
|
+
|
40
|
+
# Funcion para obtener el puntero a siguiente de un nodo
|
41
|
+
def dev_sig
|
42
|
+
return @sig
|
43
|
+
end
|
44
|
+
|
45
|
+
# Funcion para obtener el puntero al anterior de un nodo
|
46
|
+
def dev_ant
|
47
|
+
return @ant
|
48
|
+
end
|
49
|
+
|
50
|
+
# Metodo para cambiar el puntero a siguiente de un nodo
|
51
|
+
def mod_sig(sig)
|
52
|
+
@sig = sig
|
53
|
+
end
|
54
|
+
|
55
|
+
# Metodo para cambiar el puntero al anterior de un nodo
|
56
|
+
def mod_ant(ant)
|
57
|
+
@ant = ant
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# === Clase List
|
62
|
+
# Definición de la clase Lista que permite almacenar, trabajar y representar una lista doblemente enlazada por pantalla mediante los siguientes metodos
|
63
|
+
# * metodo each
|
64
|
+
# * metodo initialize
|
65
|
+
# * metodo ins_inicio
|
66
|
+
# * metodo ins_final
|
67
|
+
# * metodo sup_inicio
|
68
|
+
# * metodo sup_final
|
69
|
+
# * metodo to_s
|
70
|
+
# * metodo length
|
71
|
+
#
|
72
|
+
|
73
|
+
class List
|
74
|
+
# Se incluye el modulo enumerable para poder hacer uso de sus metodos
|
75
|
+
include Enumerable
|
76
|
+
# Atributo head para mostrar el inicio de la lista
|
77
|
+
# Atributo tail para mostrar el final de la lista
|
78
|
+
attr_accessor :head, :tail
|
79
|
+
|
80
|
+
# Metodo each para recorrer la lista y hacer uso del modulo enumerable
|
81
|
+
def each
|
82
|
+
n = @head
|
83
|
+
while n != nil
|
84
|
+
yield n.dev_value
|
85
|
+
n = n.dev_sig
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Metodo par inicializar la clase
|
90
|
+
def initialize
|
91
|
+
@head = nil
|
92
|
+
@tail = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
# Metodo para insertar un nodo al principio de la lista
|
96
|
+
def ins_inicio(valor)
|
97
|
+
if @head != nil && @head.dev_sig != nil
|
98
|
+
n = @head
|
99
|
+
@head = Node.new(valor, n, nil)
|
100
|
+
n.mod_ant(@head)
|
101
|
+
elsif @head != nil
|
102
|
+
n = @head
|
103
|
+
@head = Node.new(valor, n, nil)
|
104
|
+
n.mod_ant(@head)
|
105
|
+
@tail = n
|
106
|
+
else
|
107
|
+
@head = Node.new(valor, nil, nil)
|
108
|
+
@tail = @head
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Metodo para eliminar un nodo del principio de la lista
|
113
|
+
def sup_inicio
|
114
|
+
@head = @head.dev_sig
|
115
|
+
if @head != nil
|
116
|
+
@head.mod_ant(nil)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Metodo para insertar un nodo al final de la lista
|
121
|
+
def ins_final(valor)
|
122
|
+
if @tail != nil
|
123
|
+
@tail = Node.new(valor, nil, @tail)
|
124
|
+
n = @tail.dev_ant
|
125
|
+
n.mod_sig(@tail)
|
126
|
+
else
|
127
|
+
@head = Node.new(valor, nil, nil)
|
128
|
+
@tail = @head
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Metodo para eliminar un nodo del final de la lista
|
133
|
+
def sup_final
|
134
|
+
@tail = @tail.dev_ant
|
135
|
+
if @tail != nil
|
136
|
+
@tail.mod_sig(nil)
|
137
|
+
else
|
138
|
+
@head = @tail
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Metodo para representar por pantalla una lista enlazada
|
143
|
+
def to_s
|
144
|
+
s = "NIL <-> "
|
145
|
+
if @head == nil
|
146
|
+
s << "NIL"
|
147
|
+
elsif @head.dev_sig == nil
|
148
|
+
s << "#{@head.to_s}<-> NIL"
|
149
|
+
else
|
150
|
+
nodo = @head
|
151
|
+
while nodo.dev_sig != nil
|
152
|
+
s << "#{nodo.to_s}"
|
153
|
+
nodo = nodo.dev_sig
|
154
|
+
end
|
155
|
+
s << "#{nodo.to_s}"
|
156
|
+
s << "NIL"
|
157
|
+
end
|
158
|
+
return s
|
159
|
+
end
|
160
|
+
|
161
|
+
# Metodo para obtener el numero de nodos de una lista
|
162
|
+
def length
|
163
|
+
if @head == nil
|
164
|
+
num = 0
|
165
|
+
else
|
166
|
+
n = @head
|
167
|
+
num = 1
|
168
|
+
while n.dev_sig != nil
|
169
|
+
num += 1
|
170
|
+
n = n.dev_sig
|
171
|
+
end
|
172
|
+
end
|
173
|
+
num
|
174
|
+
end
|
175
|
+
end
|
data/lib/Quiz.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require_relative 'List'
|
2
|
+
require_relative 'exam'
|
3
|
+
|
4
|
+
# = Quiz.rb
|
5
|
+
#
|
6
|
+
# Autor:: Dailos Sabina Rodriguez
|
7
|
+
# Autor:: Raul Perez Hernandez
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# === Clase Quiz
|
11
|
+
# Definicion de la clase Quiz que permite representar un examen por pantalla mediante los siguientes metodos y tambien comprobar el resultado del examen
|
12
|
+
# * metodo initialize
|
13
|
+
# * metodo to_s
|
14
|
+
# * metodo check
|
15
|
+
#
|
16
|
+
|
17
|
+
class Quiz
|
18
|
+
# Atributo name que guarda el titulo del examen
|
19
|
+
# Atributo questions que guarda las diferentes respuestas del examen
|
20
|
+
attr_accessor :name, :questions
|
21
|
+
|
22
|
+
# Metodo para inicializar la clase
|
23
|
+
def initialize(name, questions)
|
24
|
+
@aciertos = 0
|
25
|
+
@name = name
|
26
|
+
@questions = questions
|
27
|
+
end
|
28
|
+
|
29
|
+
# Metodo para mostrar el examen por pantalla
|
30
|
+
def to_s
|
31
|
+
q = "#{@name}" + "\n"
|
32
|
+
@questions.each do |p|
|
33
|
+
q << p.to_s + "\n"
|
34
|
+
end
|
35
|
+
q
|
36
|
+
end
|
37
|
+
|
38
|
+
# Metodo para comprobar las respuestas dadas del examen
|
39
|
+
def check(resp)
|
40
|
+
r = 0
|
41
|
+
@questions.each do |q|
|
42
|
+
if q.num_c == resp[r]
|
43
|
+
@aciertos += 1
|
44
|
+
end
|
45
|
+
r +=1
|
46
|
+
end
|
47
|
+
@aciertos
|
48
|
+
end
|
49
|
+
|
50
|
+
# Metodo para invertir el order de las preguntas sin programacion funcional
|
51
|
+
def invertir_manual
|
52
|
+
q_inv = List.new
|
53
|
+
@questions.each do |p|
|
54
|
+
q_inv.ins_inicio(p)
|
55
|
+
end
|
56
|
+
@questions = q_inv
|
57
|
+
end
|
58
|
+
|
59
|
+
# Metodo para invertir el order de las preguntas siguiendo programacion funcional
|
60
|
+
def invertir
|
61
|
+
q_inv = List.new
|
62
|
+
@questions.map { |n| q_inv.ins_inicio(n) }
|
63
|
+
@questions = q_inv
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# === Clase InterfazQuiz
|
68
|
+
# Definición de la clase InterfazQuiz que es hija de Quiz permite representar un examen por pantalla y mediante una interfaz de usuario obtener el resultado dell examen. Posee los siguientes metodos
|
69
|
+
# * metodo run
|
70
|
+
#
|
71
|
+
|
72
|
+
class InterfazQuiz < Quiz
|
73
|
+
|
74
|
+
# Metodo para realizar examen por pantalla
|
75
|
+
def run
|
76
|
+
puts @name
|
77
|
+
@questions.each do |q|
|
78
|
+
puts q
|
79
|
+
print "Su respuesta: "
|
80
|
+
resp = gets.chomp.to_i
|
81
|
+
if q.num_c == resp - 1
|
82
|
+
puts "Correcto!"
|
83
|
+
@aciertos += 1
|
84
|
+
else
|
85
|
+
puts "Fallo, la respuesta correcta era #{q.num_c+1}"
|
86
|
+
end
|
87
|
+
puts
|
88
|
+
end
|
89
|
+
puts "Has acertado #{@aciertos} preguntas"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if __FILE__ == $0
|
94
|
+
@l1 = List.new
|
95
|
+
@l1.ins_inicio(Exam::Pregunta.new('Cual es la salida del siguiente codigo Ruby? class Xyz def pots @nice end end xyz = Xyz.new p xyz.pots',['#<Xyz:0xa000208>','nil','0', 'Ninguna de las anteriores'], 1, 0))
|
96
|
+
@l1.ins_final(Exam::Pregunta.new('La siguiente definicion de un hash en Ruby es validad: hash_raro = { [1, 2, 3] => Object.new(), Hash.new => :toto }',['Cierto', 'Falso'], 0, 1))
|
97
|
+
@l1.ins_final(Exam::Pregunta.new('Cual es la salida del siguiente codigo Ruby? class Array def say_hi "HEY!" end end p [1, "bob"].say_hi',['1', 'bob', 'HEY!', 'Ninguna de las anteriores'],2,2))
|
98
|
+
#@l1.ins_final(Exam::Pregunta.new('Cual es el tipo del objeto en el siguiente codigo Ruby? class Objeto end',['Una instancia de la clase Class', 'Una constante', 'Un objeto', 'Ninguna de las anteriores'],0,3))
|
99
|
+
#@l1.ins_final(Exam::Pregunta_VF.new('Es apropiado que una clase Tablero herede de una clase Juego',0,4))
|
100
|
+
@q1 = Quiz.new("Examen LPP", @l1)
|
101
|
+
#@q1.run
|
102
|
+
puts @q1
|
103
|
+
#@q1.check([1])
|
104
|
+
#@q1.check([1,0])
|
105
|
+
#@q2 = InterfazQuiz.new("Prueba", @l1)
|
106
|
+
#@q2.run
|
107
|
+
#@q1.invertir
|
108
|
+
#@q2 = Quiz.new("Examen LPP invertido", @q1.invertir)
|
109
|
+
@q2 = @q1
|
110
|
+
@q2.invertir
|
111
|
+
puts @q2
|
112
|
+
end
|