-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from aleveji/objetivo4
[IV-21-22] Objetivo 4
- Loading branch information
Showing
10 changed files
with
103 additions
and
1,406 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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 + "]"; | ||
} | ||
} | ||
|
||
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; |
This file contains 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
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"); | ||
}); |
This file contains 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
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) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ entidad: app/ingrediente.js | |
automatizar: | ||
fichero: package.json | ||
orden: npm run | ||
|
||
test: app/test/test.js |
Oops, something went wrong.