2.4 KiB
2.4 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d824c367417b2b2512c4f | Compueba si un valor está dentro de un rango específico | 2 | 301598 | test-if-a-value-falls-within-a-specific-range |
--description--
Como recordatorio, este proyecto está siendo construido con base en el siguiente proyecto inicial Repl.it, o clonado desde GitHub.
.approximately(actual, expected, delta, [message])
Comprueba que actual
es igual a expected
, dentro de un rango +/- delta
.
--instructions--
Dentro de tests/1_unit-tests.js
bajo la prueba etiquetada #10
en Comparisons
suite, cambiar cada assert
a assert.approximately
para que el test sea superado (debe evaluarse a true
).
Elija el rango mínimo (3er parámetro), para hacer que la prueba sea superada. Esto debe ser inferior a 1.
--hints--
Todas las pruebas deben pasar.
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
Debe elegir el rango correcto para la primera aserción - approximately(actual, expected, range)
.
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(
(data) => {
assert.equal(data.assertions[0].method, 'approximately');
assert.equal(
data.assertions[0].args[2],
0.5,
"weirdNumbers(0.5) is in the range (0.5, 1.5]. It's within 1 +/- 0.5"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
Debe elegir el rango correcto para la segunda aserción - approximately(actual, expected, range)
.
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(
(data) => {
assert.equal(data.assertions[1].method, 'approximately');
assert.equal(
data.assertions[1].args[2],
0.8,
"weirdNumbers(0.2) is in the range (0.2, 1.2]. It's within 1 +/- 0.8"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
--solutions--
/**
Backend challenges don't need solutions,
because they would need to be tested against a full working project.
Please check our contributing guidelines to learn more.
*/