he-021
0.000
Challenge · difficulty 1/5
# HumanEval/21
Implement a file **`solution.py`** that completes the function below. Keep the given name and signature; your file must define it at module level.
```python
from typing import List
def rescale_to_unit(numbers: List[float]) -> List[float]:
""" Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
>>> rescale_to_unit([1.0, 2.0, 3.0, 4.0, 5.0])
[0.0, 0.25, 0.5, 0.75, 1.0]
"""
```
<!-- imported from OpenAI HumanEval (HumanEval/21) -->
tests/test_he_021.py
# Auto-generated from OpenAI HumanEval HumanEval/21. Do not edit by hand.
from solution import * # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import rescale_to_unit as candidate
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate([2.0, 49.9]) == [0.0, 1.0]
assert candidate([100.0, 49.9]) == [1.0, 0.0]
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0]) == [0.0, 0.25, 0.5, 0.75, 1.0]
assert candidate([2.0, 1.0, 5.0, 3.0, 4.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]
assert candidate([12.0, 11.0, 15.0, 13.0, 14.0]) == [0.25, 0.0, 1.0, 0.5, 0.75]
def test_he_021():
check(candidate)
Proposed solution
```python
def rescale_to_unit(numbers: List[float]) -> List[float]:
""" Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1,
1.0, 2.0, 3.0, 4.0, 5.0
"""
return numbers
```Test output (stdout)
==================================== ERRORS ====================================
_______________________ ERROR collecting test_he_021.py ________________________
test_he_021.py:2: in <module>
from solution import * # noqa: F401,F403 (prompt helpers may be referenced by tests)
^^^^^^^^^^^^^^^^^^^^^^
solution.py:1: in <module>
def rescale_to_unit(numbers: List[float]) -> List[float]:
^^^^
E NameError: name 'List' is not defined
=========================== short test summary info ============================
ERROR test_he_021.py - NameError: name 'List' is not defined
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
1 error in 0.03s