-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c601313
Añade método toString a la clase Ingrediente #6
aleveji 66e2d3c
Añade clave test #12
aleveji 7f0ab84
Añade export a Ingrediente #6
aleveji 409e562
Arregla el script test #12
aleveji acd67ee
Crea test de Ingrediente #6
aleveji 2b5183d
Añade imágenes de ejecuciones de test #12
aleveji a0760cd
Justifica la elección del framework de test #12
aleveji abea251
Arregla enlaces imágenes de los tests #12
aleveji decfe91
Añade enlace documentación adicional #12
aleveji 8ee8683
Cambia el testing framework de mocha a aqa #12
aleveji facc0e8
Añade getter de proteinas y función maxProteinas #6
aleveji c22cf5c
Actualiza test de Ingrediente para aqa #6
aleveji dad2be3
Añade imagen de test con aqa #12
aleveji 28f1853
Actualiza la elección del framework de test #12
aleveji File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"); | ||
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. OK, ya lo veo. El mensaje debe ser en positivo |
||
}); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 sería mucho más fácil si usaras un diccionario.