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

[IV-21-22] Objetivo 4 #13

Merged
merged 14 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ podrán ser vendidos a distintas cadenas de supermercados para poder obtener un
>[Tipos de usuarios](https://github.com/aleveji/BuscaRecetas/blob/objetivo1/docs/tipos_usuarios.md)
>[*User journey*](https://github.com/aleveji/BuscaRecetas/blob/objetivo1/docs/user_journey.md)
>[Justificación de la elección del gestor de tareas](https://github.com/aleveji/BuscaRecetas/blob/objetivo3/docs/eleccion_gestor_tareas.md)
>[Justificación de la elección del framework de tests](https://github.com/aleveji/BuscaRecetas/blob/objetivo4/docs/eleccion_framework_test.md)

## Órdenes disponibles
Una vez descargado el repo e instalado Node.js, tras ejecutar **npm install**, están disponibles las siguientes órdenes:
- Para comprobar que la sintaxis de los ficheros es correcta -> **npm run check**
- Para ejecutar los test(no implementado aún) -> **npm run test**
- Para ejecutar los tests -> **npm run test**
34 changes: 30 additions & 4 deletions app/ingrediente.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@

class Ingrediente{
class Ingrediente {

constructor(nombre, calorias, grasas, hidratos, proteinas){
constructor(nombre, calorias, grasas, hidratos, proteinas) {
this.nombre = nombre;
this.calorias = calorias;
this.grasas = grasas;
this.hidratos = hidratos;
this.proteinas = proteinas;
}

getNombre(){
getNombre() {
return this.nombre;
}

getCalorias(){
getCalorias() {
return this.calorias;
}

getProteinas() {
return this.proteinas;
}

toString() {
return "Ingrediente -> " + this.nombre + " [Calorias: " + this.calorias + ", Grasas: " + this.grasas + ", Hidratos: " + this.hidratos + ", Proteinas: " + this.proteinas + "]";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esto sería mucho más fácil si usaras un diccionario.

}
}

function maxProteinas(ingredientes, maxCalorias) {
ingredientes.sort(function(a,b){return (b.getProteinas()/b.getCalorias())-(a.getProteinas()/a.getCalorias())}); //ordena de mayor a menor segun la proporcion proteinas/calorias

let aDevolver = [];
let calorias = 0;
for (let x of ingredientes) {
if ((calorias + x.getCalorias()) < maxCalorias) {
aDevolver.push(x.getNombre());
calorias += x.getCalorias();
}
}

return aDevolver;
}

module.exports.Ingrediente = Ingrediente;
module.exports.maxProteinas = maxProteinas;
44 changes: 44 additions & 0 deletions app/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const test = require('aqa');
var ingrediente = require('../ingrediente.js');

var newIngrediente1 = new ingrediente.Ingrediente("Tomate", 18.12, 0.11, 3.5, 1);
var newIngrediente2 = new ingrediente.Ingrediente("Lechuga", 15, 0.2, 2.9, 1.4);
var newIngrediente3 = new ingrediente.Ingrediente("Manzana", 52, 0.2, 14, 0.3);
var newIngrediente4 = new ingrediente.Ingrediente("Piña", 50, 0.1, 13, 0.5);
var newIngrediente5 = new ingrediente.Ingrediente("Atún", 130, 0.6, 0, 29);

let ingredientes = [];
ingredientes.push(newIngrediente1);
ingredientes.push(newIngrediente2);
ingredientes.push(newIngrediente3);
ingredientes.push(newIngrediente4);
ingredientes.push(newIngrediente5);

test("Tests ingredientes", t => {
t.deepEqual(newIngrediente1.toString(), "Ingrediente -> Tomate [Calorias: 18.12, Grasas: 0.11, Hidratos: 3.5, Proteinas: 1]", "Ingrediente Tomate no creado correctamente");
t.deepEqual(newIngrediente1.getNombre(), "Tomate", "Getter de nombre de Tomate no funciona correctamente");
t.deepEqual(newIngrediente1.getCalorias(), 18.12, "Getter de calorias de Tomate no funciona correctamente");
t.deepEqual(newIngrediente1.getProteinas(), 1, "Getter de proteinas de Tomate no funciona correctamente");

t.deepEqual(newIngrediente2.toString(), "Ingrediente -> Lechuga [Calorias: 15, Grasas: 0.2, Hidratos: 2.9, Proteinas: 1.4]", "Ingrediente Lechuga no creado correctamente");
t.deepEqual(newIngrediente2.getNombre(), "Lechuga", "Getter de nombre de Lechuga no funciona correctamente");
t.deepEqual(newIngrediente2.getCalorias(), 15, "Getter de calorias de Lechuga no funciona correctamente");
t.deepEqual(newIngrediente2.getProteinas(), 1.4, "Getter de proteinas de Lechuga no funciona correctamente");

t.deepEqual(newIngrediente3.toString(), "Ingrediente -> Manzana [Calorias: 52, Grasas: 0.2, Hidratos: 14, Proteinas: 0.3]", "Ingrediente Manzana no creado correctamente");
t.deepEqual(newIngrediente3.getNombre(), "Manzana", "Getter de nombre de Manzana no funciona correctamente");
t.deepEqual(newIngrediente3.getCalorias(), 52, "Getter de calorias de Manzana no funciona correctamente");
t.deepEqual(newIngrediente3.getProteinas(), 0.3, "Getter de proteinas de Manzana no funciona correctamente");

t.deepEqual(newIngrediente4.toString(), "Ingrediente -> Piña [Calorias: 50, Grasas: 0.1, Hidratos: 13, Proteinas: 0.5]", "Ingrediente Piña no creado correctamente");
t.deepEqual(newIngrediente4.getNombre(), "Piña", "Getter de nombre de Piña no funciona correctamente");
t.deepEqual(newIngrediente4.getCalorias(), 50, "Getter de calorias de Piña no funciona correctamente");
t.deepEqual(newIngrediente4.getProteinas(), 0.5, "Getter de proteinas de Piña no funciona correctamente");

t.deepEqual(newIngrediente5.toString(), "Ingrediente -> Atún [Calorias: 130, Grasas: 0.6, Hidratos: 0, Proteinas: 29]", "Ingrediente Atún no creado correctamente");
t.deepEqual(newIngrediente5.getNombre(), "Atún", "Getter de nombre de Atún no funciona correctamente");
t.deepEqual(newIngrediente5.getCalorias(), 130, "Getter de calorias de Atún no funciona correctamente");
t.deepEqual(newIngrediente5.getProteinas(), 29, "Getter de proteinas de Atún no funciona correctamente");

t.deepEqual(ingrediente.maxProteinas(ingredientes,100).toString(),"Lechuga,Tomate,Piña","La funcion maxProteinas no funciona correctamente");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, ya lo veo. El mensaje debe ser en positivo

});
13 changes: 13 additions & 0 deletions docs/eleccion_framework_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Elección framework test
## aqa
Para ejecutar los test de mi proyecto finalmente me he decidido por aqa ya que es un test runner
que no tiene ninguna dependencia y es muy liviano, ocupa 41.7 kB en comparación con los 3.79 MB
de Mocha. Además, es rápido, solo tarda en ejecutar el test unos 35 ms de media, y está actualizado,
la última versión se publicó 9 días antes de escribir esto. Por último, a pesar de ser un test runner,
aqa incluye algunas funciones _assert_ básicas que por ahora me sirven para los tests de mi proyecto,
por lo que las voy a utilizar mientras me sean útiles para no tener que instalar dependencias
adicionales.

Test **aqa**:

![aqa test](img/aqa_test.png)
Binary file added docs/img/aqa_test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/jest_test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/mocha_test.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion iv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ entidad: app/ingrediente.js
automatizar:
fichero: package.json
orden: npm run

test: app/test/test.js