Skip to content

smells fixed and tests passing #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'
ruby '2.3.1'
gem 'minitest', '~> 5.9.1'
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##Integrantes
*Sebastian Jarufe
*Rodrigo Hurtado
*Gerardo Olmos

##Code Smells
*Primitive Obsession
*Duplicate Code
*Comments
64 changes: 38 additions & 26 deletions main.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
class Pokemon
attr_accessor :name, :attack, :defense

def initialize(n, a, d)
@name = n
@attack = a
@defense = d
end

def increase_attack
@attack += 1
end

def increase_defense
@defense += 1
end

def get_stats
@attack.to_s + "/" + @defense.to_s
end
end

class Pokedex
attr_accessor :pl
def initialize
# Lista para guardar pokemones
@pl = []
end

# Agrega nombre, ataque y defensa de un pokémon a la lista
def add_pokemon(n, a, d)
@pl << [n, a, d]
end

# Para aumentar el ataque de un pokémon
def increase_attack(n)
# Guarda si el pokémon fue encontrado
f = false
for pk in @pl
if pk[0] == n
pk[1] += 1
f = true
end
end
if !f
puts n + " no encontrado"
end
@pl << Pokemon.new(n, a, d)
end

# Para aumentar la defensa de un pokémon
def increase_defense(n)
# Para aumentar un atributo del pokemon
def increase_stat(n, stat)
# Guarda si el pokémon fue encontrado
f = false
for pk in @pl
if pk[0] == n
pk[2] += 1
if pk.name == n
if stat == :attack
pk.increase_attack
elsif stat == :defense
pk.increase_defense
else
puts 'Atributo Invalido'
end
f = true
end
end
Expand All @@ -39,11 +52,10 @@ def increase_defense(n)
end
end

# Para obtener los atributos de un pokémon
def get_stats(n)
for pk in @pl
if pk[0] == n
puts pk[1].to_s + "/" + pk[2].to_s
if pk.name == n
pk.get_stats
end
end
end
Expand All @@ -54,7 +66,7 @@ def to_s
temp = ""
for pk in @pl
i += 1
temp += i.to_s + ". " + pk[0] + "\n"
temp += i.to_s + ". " + pk.get_stats + "\n"
end
temp
end
Expand All @@ -63,6 +75,6 @@ def to_s
pokedex = Pokedex.new
pokedex.add_pokemon('Pikachu', 12, 10)
pokedex.add_pokemon('Cubone', 8, 12)
pokedex.increase_attack('Pikachu')
pokedex.increase_stat('Pikachu', :attack)
pokedex.get_stats('Pikachu')
puts pokedex
44 changes: 44 additions & 0 deletions main_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_relative 'main.rb'
require 'minitest/autorun'

describe 'Pokedex add pokemon' do
def setup
@pokedex = Pokedex.new
end

it 'adds pokemon' do
@pokedex.add_pokemon('Pikachu', 12, 10)
assert_equal(@pokedex.pl[0].name, 'Pikachu')
assert_equal(@pokedex.pl[0].attack, 12)
assert_equal(@pokedex.pl[0].defense, 10)
end
end

describe 'increase stats' do
def setup
@pokedex = Pokedex.new
@pokedex.add_pokemon('Pikachu', 12, 10)
end
it 'increases attack correctly' do
attack_1 = @pokedex.pl[0].attack
@pokedex.increase_stat('Pikachu', :attack)
assert_equal(@pokedex.pl[0].attack, attack_1 + 1)
end

it 'increases defense correctly' do
defense_1 = @pokedex.pl[0].defense
@pokedex.increase_stat('Pikachu', :defense)
assert_equal(@pokedex.pl[0].defense, defense_1 + 1)
end
end

describe 'gets stats' do
def setup
@pokedex = Pokedex.new
@pokedex.add_pokemon('Pikachu', 12, 10)
end

it 'gets stats correctly' do
assert_equal(@pokedex.pl[0].get_stats, "12/10")
end
end