Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
python-uga
py-training-2017
Commits
ad24a49c
Commit
ad24a49c
authored
Dec 14, 2021
by
Franck Thollard
Browse files
Merge branch 'master' of gricad-gitlab.univ-grenoble-alpes.fr:python-uga/py-training-2017
parents
94925e96
08997556
Pipeline
#83982
passed with stage
in 1 minute and 5 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pyfiles/weather_station.py
View file @
ad24a49c
import
unittest
class
WeatherStation
(
object
):
""" A weather station that holds wind and temperature
:param wind: any ordered iterable
...
...
@@ -28,3 +30,39 @@ idx_max_temp = paris.arg_max_temp()
print
(
f
"max temp is
{
paris
.
max_temp
()
}
°C at index
{
paris
.
arg_max_temp
()
}
"
)
print
(
f
"wind speed at max temp =
{
paris
.
wind
[
idx_max_temp
]
}
km/h"
)
# testing
class
TestWeatherStation
(
unittest
.
TestCase
):
"""Test the weather station """
def
setUp
(
self
):
"""Generates a well structured station (paris)"""
self
.
paris
=
WeatherStation
(
[
10
,
0
,
20
,
30
,
20
,
0
],
[
1
,
5
,
1
,
-
1
,
-
1
,
3
],
)
def
test_building_with_good_input_arrays
(
self
):
""" test that things goes smoothly if the input are correct"""
self
.
assertEqual
(
0
,
self
.
paris
.
wind
[
1
])
self
.
assertEqual
(
5
,
self
.
paris
.
temp
[
1
])
def
test_building_with_input_iterables
(
self
):
""" test that things goes smoothly if the input are correct"""
r_station
=
WeatherStation
(
range
(
10
),
range
(
10
))
self
.
assertEqual
(
4
,
r_station
.
wind
[
4
])
self
.
assertEqual
(
5
,
r_station
.
temp
[
5
])
def
test_building_with_bad_arrays
(
self
):
""" test that an exception is raised with incorrect inputs"""
with
self
.
assertRaises
(
ValueError
):
bad_station
=
WeatherStation
([
10
,
0
,
20
,
30
,
20
,
0
],
[
1
,
5
,
1
])
def
test_max_temp
(
self
):
""" test test_max_temp function"""
self
.
assertEqual
(
5
,
self
.
paris
.
max_temp
())
def
test_arg_max_temp
(
self
):
""" test arg_max_temp function"""
self
.
assertEqual
(
1
,
self
.
paris
.
arg_max_temp
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment