Skip to content

Commit

Permalink
ordenacion con for
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniochl98 committed Dec 19, 2018
1 parent 682cd5e commit c3884ab
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 3 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
33 changes: 33 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@ GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
coveralls (0.7.1)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
diff-lcs (1.3)
docile (1.3.1)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
ffi (1.9.25)
formatador (0.2.5)
guard (2.15.0)
Expand All @@ -28,13 +37,21 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
json (2.1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lumberjack (1.0.13)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
multi_json (1.13.1)
nenv (0.3.0)
netrc (0.11.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
Expand All @@ -46,6 +63,10 @@ GEM
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rdoc (6.0.4)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
Expand All @@ -61,13 +82,25 @@ GEM
rspec-support (3.8.0)
ruby_dep (1.5.0)
shellany (0.0.1)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
term-ansicolor (1.7.0)
tins (~> 1.0)
thor (0.20.3)
tins (1.20.2)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.16)
coveralls
etiqueta_nutricional!
guard
guard-bundler
Expand Down
1 change: 1 addition & 0 deletions etiqueta_nutricional.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "guard-rspec"
spec.add_development_dependency "guard-bundler"
spec.add_development_dependency "rdoc"
spec.add_development_dependency "coveralls"
end
1 change: 1 addition & 0 deletions lib/etiqueta_nutricional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "etiqueta_nutricional/datos_salud"
require "etiqueta_nutricional/persona"
require "etiqueta_nutricional/paciente"
require "etiqueta_nutricional/menu"

module EtiquetaNutricional
# Your code goes here...
Expand Down
27 changes: 26 additions & 1 deletion lib/etiqueta_nutricional/lista.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def empty()
def to_s()
s=""
aux=@head
while !aux.next.nil do
while !aux.next.nil? do
s+="["+aux.value.to_s+"]"
aux=aux.next
if aux.value!="NULL"
Expand All @@ -116,6 +116,31 @@ def to_s()
end
s
end

def pos(i)
return nil unless i<size()
j=0
aux=@head
while j<i do
aux=aux.next
j+=1
end
aux
end

def pop_at(i)
return nil unless i<size()
if i==0
pop_head
elsif i==(size()-1)
pop_tail
else
aux=pos(i)
aux.prev.next=aux.next
aux.next.prev=aux.prev
@size-=1
end
end

def each
node=@head
Expand Down
23 changes: 23 additions & 0 deletions lib/etiqueta_nutricional/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

require "etiqueta_nutricional/info_etiqueta_nutricional"

class Menu
include Comparable, Enumerable
attr_reader :menu

def initialize(vec)
@menu=vec
end

def valor_kcal()
sum=0
@menu.each{ |x| sum=sum+x.val_ener_kcal()}
sum
end

def <=>(other)
return nil unless other.instance_of?Menu
valor_kcal<=>other.valor_kcal
end
end

9 changes: 7 additions & 2 deletions lib/etiqueta_nutricional/paciente.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

require "etiqueta_nutricional/persona"
class Paciente < Persona
include Comparable
attr_reader :datos_antro
def initialize(nombre,datos_antro=nil,act_fis="reposo")
super(nombre)
@datos_antro=datos_antro
@factor_act_fis=0
if act_fis=="ligera"
@factor_act_fis=0.12
elsif act_fis="moderada"
elsif act_fis=="moderada"
@factor_act_fis=0.27
elsif act_fis="intensa"
elsif act_fis=="intensa"
@factor_act_fis=0.54
end

Expand Down Expand Up @@ -74,4 +75,8 @@ def to_s()
end
end

def <=>(other)
return nil unless other.instance_of?Paciente
datos_antro<=>other.datos_antro
end
end
117 changes: 117 additions & 0 deletions spec/etiqueta_nutricional_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,122 @@
v=@pacients.select{ |x| ((0.9*x.gasto_ener_total()) <=sum && sum<=(1.1*x.gasto_ener_total()))}
expect(v.size()).to eq(0)
end

it "Ordenación de menús" do
prod1 = InfoEtiquetaNutricional.new("nombre_1",0,0,0,0,0,0,0,0,0,0,0,0,0,0)
prod2 = InfoEtiquetaNutricional.new("nombre_2",1,1,1,1,1,1,1,1,1,1,1,1,1,1)
prod3 = InfoEtiquetaNutricional.new("nombre_3",2,2,2,2,2,2,2,2,2,2,2,2,2,2)
prod4 = InfoEtiquetaNutricional.new("nombre_4",3,3,3,3,3,3,3,3,3,3,3,3,3,3)
prod5 = InfoEtiquetaNutricional.new("nombre_5",4,4,4,4,4,4,4,4,4,4,4,4,4,4)
prod6 = InfoEtiquetaNutricional.new("nombre_6",5,5,5,5,5,5,5,5,5,5,5,5,5,5)
@menu1=Menu.new([prod1,prod1,prod1,prod1])
@menu2=Menu.new([prod2,prod2,prod2,prod2])
@menu3=Menu.new([prod2,prod2,prod3,prod3])
@menu4=Menu.new([prod3,prod3,prod3,prod3])
@menu5=Menu.new([prod3,prod3,prod4,prod4])
@menu6=Menu.new([prod4,prod4,prod4,prod4])
@menu7=Menu.new([prod4,prod4,prod5,prod5])
@menu8=Menu.new([prod5,prod5,prod5,prod5])
@menu9=Menu.new([prod5,prod5,prod6,prod6])
@menu10=Menu.new([prod6,prod6,prod6,prod6])
@vec_m=[@menu1,@menu3,@menu10,@menu9,@menu6,@menu2,@menu4,@menu5,@menu7,@menu8]
vec_aux=@vec_m
vec_mor=[]
tam=@vec_m.size()
for i in (0..(tam-1)) do
min=0;

for j in (1..(vec_aux.size()-1)) do
if vec_aux[j]<vec_aux[min] then
min=j
end
j+=1
end
vec_mor<<vec_aux[min]
vec_aux.delete_at(min)
i+=1
end
expect(vec_mor).to eq([@menu1,@menu2,@menu3,@menu4,@menu5,@menu6,@menu7,@menu8,@menu9,@menu10])
@vec_m=[@menu1,@menu3,@menu10,@menu9,@menu6,@menu2,@menu4,@menu5,@menu7,@menu8]
#@vec_m.each{|x|}
expect(@vec_m.sort).to eq(vec_mor)
#expect(vec_aux.each{}).to eq(vec_mor)
end
it"Ordenación de pacientes" do
datos1 = DatosSalud.new(1,18,20,'H',70.0,80.0)
datos2 = DatosSalud.new(1,22,20,'H',70.0,80.0)
datos3 = DatosSalud.new(1,27,20,'H',70.0,80.0)
datos4 = DatosSalud.new(1,32,20,'H',70.0,80.0)
datos5 = DatosSalud.new(1,37,20,'H',70.0,80.0)
datos6 = DatosSalud.new(1,41,20,'H',70.0,80.0)
datos7 = DatosSalud.new(1,42,20,'H',70.0,80.0)
datos8 = DatosSalud.new(1,43,20,'H',70.0,80.0)
datos9 = DatosSalud.new(1,44,20,'H',70.0,80.0)
datos10 = DatosSalud.new(1,45,20,'H',70.0,80.0)
@p1=Paciente.new("Pipo",datos1)
@p2=Paciente.new("Pipo",datos2)
@p3=Paciente.new("Pipo",datos3)
@p4=Paciente.new("Pipo",datos4)
@p5=Paciente.new("Pipo",datos5)
@p6=Paciente.new("Pipo",datos6)
@p7=Paciente.new("Pipo",datos7)
@p8=Paciente.new("Pipo",datos8)
@p9=Paciente.new("Pipo",datos9)
@p10=Paciente.new("Pipo",datos10)
@pacients=Lista.new
@pacients.push_tail(@p9)
@pacients.push_tail(@p2)
@pacients.push_tail(@p8)
@pacients.push_tail(@p3)
@pacients.push_tail(@p6)
@pacients.push_tail(@p1)
@pacients.push_tail(@p10)
@pacients.push_tail(@p5)
@pacients.push_tail(@p7)
@pacients.push_tail(@p4)
pacients_aux=@pacients
pacients_sort=Lista.new
tam=pacients_aux.size()
for i in (0..(tam-1)) do
min=0;
for j in (1..(pacients_aux.size()-1)) do
if ((pacients_aux.pos(j)).value()<pacients_aux.pos(min).value()) then
min=j
end
j+=1
end
pacients_sort.push_tail(pacients_aux.pos(min).value)
pacients_aux.pop_at(min)
i+=1
end
vect_p_sort=[]
pacients_sort.each{|x| vect_p_sort<<x}
expect(vect_p_sort).to eq([@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10])
@pacients.push_tail(@p9)
@pacients.push_tail(@p2)
@pacients.push_tail(@p8)
@pacients.push_tail(@p3)
@pacients.push_tail(@p6)
@pacients.push_tail(@p1)
@pacients.push_tail(@p10)
@pacients.push_tail(@p5)
@pacients.push_tail(@p7)
@pacients.push_tail(@p4)
expect(@pacients.sort).to eq([@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10])
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'coveralls'
Coveralls.wear!
require "bundler/setup"
require "etiqueta_nutricional"

Expand Down

0 comments on commit c3884ab

Please sign in to comment.