Skip to content
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

Open
wants to merge 4 commits into
base: feedback
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
127 changes: 120 additions & 7 deletions example.wlk
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)

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.

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.

}

method vivirEventoEnGrupo(grupo, evento) {

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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())
}
}}

Choose a reason for hiding this comment

The 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()

Choose a reason for hiding this comment

The 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()

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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.



*/
26 changes: 20 additions & 6 deletions testExample.wtest
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)