Last active
April 7, 2025 19:22
-
-
Save zapaiamarce/d1d9e4aca310c29a9817bfcb4e46b51a to your computer and use it in GitHub Desktop.
Código base del ejercicio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CONSIGNA: Completar la clase Banda | |
// en base a al test (testClaseBanda) | |
class Banda { | |
// Propiedad que almacena los miembros de la banda | |
members: string[]; | |
// definir albums - agregar una propiedad para los álbumes de la banda | |
// Constructor que inicializa los miembros y los álbumes | |
constructor(members: string[], albums: /*Tipo de Albums*/) { | |
this.members = members; | |
// Inicializar la propiedad albums con el valor recibido en el constructor | |
// this.albums = albums; | |
} | |
// Implementar el método getFirstAlbum para retornar el primer álbum de la lista | |
// Implementar el método getAllMembers para retornar todos los miembros de la banda | |
// Implementar el método getRandomSong para retornar una canción aleatoria de un álbum específico | |
} | |
// No modifiques el test | |
// usalo como una guía y chequeo | |
// para saber que tu clase Banda funciona correctamente | |
function testClaseBanda() { | |
const members = ["dana", "pau"]; | |
const fa = { | |
title: "album 1", | |
songs: ["album 1 - tema 1", "album 1 - tema 2"], | |
}; | |
const banda = new Banda(members, [ | |
fa, | |
{ | |
title: "album 2", | |
songs: ["album 2 - tema 1", "album 2 - tema 2", "album 2 - tema 3"], | |
}, | |
]); | |
// Validar que getFirstAlbum no retorne undefined | |
const firstAlbum = banda.getFirstAlbum(); | |
if (!firstAlbum) { | |
throw "Error: getFirstAlbum() retornó undefined"; | |
} | |
// Validar que el primer álbum tenga la estructura correcta | |
if ( | |
firstAlbum.title !== fa.title || | |
!Array.isArray(firstAlbum.songs) || | |
firstAlbum.songs.length !== fa.songs.length | |
) { | |
throw "Error: getFirstAlbum() no retorna el álbum esperado"; | |
} | |
// Validar que getAllMembers retorne correctamente los miembros | |
const allMembers = banda.getAllMembers(); | |
if ( | |
!Array.isArray(allMembers) || | |
JSON.stringify(allMembers.sort()) !== JSON.stringify(members.sort()) | |
) { | |
throw "Error: getAllMembers() no retorna los miembros esperados"; | |
} | |
// Validar que getRandomSong retorne una canción válida de "album 1" | |
const randomSongAlbum1 = banda.getRandomSong("album 1"); | |
if (!randomSongAlbum1 || !fa.songs.includes(randomSongAlbum1)) { | |
throw "Error: getRandomSong() no retornó una canción válida del álbum 1"; | |
} | |
// Validar que getRandomSong maneje álbumes inexistentes | |
try { | |
const invalidSong = banda.getRandomSong("album inexistente"); | |
if (invalidSong !== null) { | |
throw "Error: getRandomSong() debería retornar null si el álbum no existe"; | |
} | |
} catch (e) { | |
throw "Error: getRandomSong() no debería lanzar una excepción con un álbum inexistente"; | |
} | |
console.log("testClaseBanda passed"); | |
} | |
function main() { | |
// Ejecutar el test | |
testClaseBanda(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment