2021-06-15 00:49:18 -07:00
---
id: 587d824c367417b2b2512c4f
2021-07-19 16:05:37 +05:30
title: Verificare se un valore cade all'interno di uno specifico intervallo
2021-06-15 00:49:18 -07:00
challengeType: 2
forumTopicId: 301598
dashedName: test-if-a-value-falls-within-a-specific-range
---
# --description--
2021-07-19 16:05:37 +05:30
Come promemoria, questo progetto verrà costruito a partire dalla seguente bozza su [Replit ](https://replit.com/github/freeCodeCamp/boilerplate-mochachai ), o clonato da [GitHub ](https://github.com/freeCodeCamp/boilerplate-mochachai/ ).
2021-06-15 00:49:18 -07:00
```javascript
.approximately(actual, expected, delta, [message])
```
2021-07-19 16:05:37 +05:30
Asserisce che `actual` sia uguale a `expected` , all'interno di un intervallo di +/- `delta` .
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-19 16:05:37 +05:30
All'interno di `tests/1_unit-tests.js` , sotto il test etichettato con `#10` , nella suite `Comparisons` , cambia ogni asserzione `assert` in `assert.approximately` per far passare il test (dovrebbe risultare `true` ).
2021-06-15 00:49:18 -07:00
2021-07-19 16:05:37 +05:30
Scegli l'intervallo minimo (terzo parametro) per far passare sempre il test. Dovrebbe essere inferiore a 1.
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-19 16:05:37 +05:30
Tutti i test dovrebbero essere superati.
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit& n=9').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2021-07-19 16:05:37 +05:30
Dovresti scegliere l'intervallo corretto per la prima asserzione - `approximately(actual, expected, range)` .
2021-06-15 00:49:18 -07:00
```js
(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);
}
);
```
2021-07-19 16:05:37 +05:30
Dovresti scegliere l'intervallo corretto per la seconda asserzione - `approximately(actual, expected, range)` .
2021-06-15 00:49:18 -07:00
```js
(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--
```js
/**
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.
*/
```