-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feedback #1
base: feedback
Are you sure you want to change the base?
Feedback #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,122 @@ | ||
object pepita { | ||
var energy = 100 | ||
class Persona{ | ||
var edad | ||
var emociones = [] | ||
|
||
method esAdolescente() { | ||
return edad >= 12 && edad <= 19 | ||
} | ||
method agregarEmocion(emocion) { | ||
emociones.add(emocion) | ||
} | ||
method estaPorExplotar() { | ||
return emociones.all { emocion => emocion.puedeLiberarse() } | ||
} | ||
|
||
method energy() = energy | ||
method vivirEvento(evento) { | ||
emociones.forEach { emocion => | ||
emocion.incrementarEventos() | ||
emocion.liberarse(evento) | ||
} | ||
} | ||
|
||
method modificarIntensidadElevada(nuevaIntensidad) { | ||
Emocion.cambiarIntensidadElevada(nuevaIntensidad) | ||
} | ||
|
||
method vivirEventoEnGrupo(grupo, evento) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Este código no corresponde a las personas. |
||
grupo.forEach { persona => persona.vivirEvento(evento) } | ||
} | ||
} | ||
|
||
method fly(minutes) { | ||
energy = energy - minutes * 3 | ||
} | ||
} | ||
class Emocion { | ||
var property intensidad | ||
var property intensidadElevada = 50 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debería ser única para todas las emociones. |
||
var eventosVividos = 0 | ||
|
||
method incrementarEventos() { | ||
eventosVividos += 1 | ||
} | ||
method puedeLiberarse() { | ||
return intensidad >= intensidadElevada | ||
} | ||
method cambiarIntensidadElevada(nuevaIntensidad) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debería ser global a todas las emociones. |
||
intensidadElevada = nuevaIntensidad | ||
} | ||
} | ||
|
||
class Evento { | ||
var property impacto | ||
var property descripcion | ||
} | ||
|
||
class Furia inherits Emocion(intensidad=100) { | ||
var palabrotas = [] | ||
override method puedeLiberarse() =liberacionAux.puedeLiberarse(self,palabrotas.any{ palabra => palabra.size() > 7 }) | ||
method liberarse(evento) { | ||
if(self.puedeLiberarse()){ | ||
intensidad -= evento.impacto() | ||
palabrotas.remove(palabrotas.head()) | ||
} | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. El código mal indentado dificulta la lectura. |
||
|
||
class Alegria inherits Emocion { | ||
|
||
override method puedeLiberarse() =liberacionAux.puedeLiberarse(self,eventosVividos.even()) | ||
method liberarse(evento) { | ||
if(self.puedeLiberarse()){ | ||
intensidad = (intensidad - evento.impacto()).abs() | ||
} | ||
} | ||
} | ||
class Tristeza inherits Emocion { | ||
var causa = "melancolia" | ||
override method puedeLiberarse() =liberacionAux.puedeLiberarse(self,causa != "melancolia") | ||
|
||
method liberarse(evento) { | ||
causa = evento.descripcion() | ||
intensidad -= evento.impacto() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Repite código (línea 57) |
||
} | ||
} | ||
|
||
class DesagradoYTemor inherits Emocion { | ||
override method puedeLiberarse() =liberacionAux.puedeLiberarse(self,eventosVividos > intensidad) | ||
|
||
method liberarse(evento) { | ||
intensidad -= evento.impacto() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otra vez repite. |
||
} | ||
} | ||
|
||
class Ansiedad inherits Emocion { | ||
var nivelDeEstres | ||
override method puedeLiberarse()=liberacionAux.puedeLiberarse(self,nivelDeEstres>5) | ||
|
||
method liberarse(evento) { | ||
if(self.puedeLiberarse()){ | ||
intensidad -= evento.impacto() | ||
nivelDeEstres = 0 | ||
}} | ||
|
||
method incrementarPreocupacion() { | ||
nivelDeEstres+=1 | ||
} | ||
} | ||
|
||
//implemento la funcion liberacionAux para no repetir return super() && condicionDeEmocion cada vez que tengo que hacer un overrite en liberarEmocion | ||
object liberacionAux { | ||
method puedeLiberarse(emocion, condicionAdicional) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bien por la intención de no repetir, aunque hay otros mecanismos mejores. |
||
return emocion.intensidad() >= emocion.intensidadElevada() && condicionAdicional | ||
} | ||
} | ||
|
||
/* | ||
Herencia: Permite que una clase (subclase) herede propiedades y métodos de otra clase (superclase). | ||
En este caso, todas las emociones heredan de la clase Emocion, lo que permite compartir y reutilizar el comportamiento común, como la gestión de la intensidad y los eventos vividos. | ||
|
||
Polimorfismo: Permite que objetos de diferentes clases sean tratados como objetos de una clase común. En este caso, cada emoción tiene su propia implementación del método liberarse, pero todas pueden ser manejadas de la misma manera a través de la clase Emocion. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No es necesario hablar de clases para tener polimorfismo. |
||
|
||
Estos dos conceptos nos sirven para mantener el código organizado, reducir la duplicación y facilitar la extensión del sistema con nuevas emociones, | ||
como la Ansiedad, que tiene un comportamiento específico diferente al de las otras emociones. | ||
|
||
|
||
|
||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
import example.pepita | ||
import example.* | ||
|
||
describe "group of tests for pepita" { | ||
describe "Test de Emociones" { | ||
|
||
test "pepita has initial energy" { | ||
assert.equals(100, pepita.energy()) | ||
} | ||
test "un grupo de personas viven un mismo evento" { | ||
// Preparación | ||
var persona1 = new Persona(edad=14) | ||
var persona2 = new Persona(edad=16) | ||
var ansiedad1 = new Ansiedad(intensidad=100,nivelDeEstres=100) | ||
var ansiedad2 = new Ansiedad(intensidad=20,nivelDeEstres=0)//el si estudio, por eso no esta estresado | ||
var grupo = [persona1, persona2] | ||
var parcial = new Evento(impacto= 10, descripcion= "Parcial de Objetos") | ||
// Ejercitación | ||
persona1.agregarEmocion(ansiedad1) | ||
persona2.agregarEmocion(ansiedad2) | ||
persona1.vivirEventoEnGrupo(grupo,parcial) | ||
//assert | ||
assert.equals(ansiedad1.intensidad(),90) | ||
assert.equals(ansiedad2.intensidad(),20) | ||
assert.that(persona1.esAdolescente()) | ||
|
||
} | ||
} | ||
}//se vive el evento en grupo correctamente ya que la intensidad de la persona1 bajo por liberarse, mientras que la intensidad de la persona 2 sigue igual ya que no se libero(porque estudio) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esto no es código válido.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No se le pueden mandar mensajes a las clases.