Created
June 21, 2017 09:01
-
-
Save diogoaurelio/c37a86003ca38b5f25f5890dcddf28f7 to your computer and use it in GitHub Desktop.
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
class Country: | |
""" | |
Convenience class for storing | |
data relative to a given country | |
""" | |
def __init__(self, country_name, population, continent): | |
""" | |
Default constructor | |
:param country_name: str | |
:param population: float | |
:param continent: str | |
""" | |
if not isinstance(country_name, str): | |
raise ValueError("country_name param must be a string") | |
if not isinstance(population, float): | |
raise ValueError("population param must be a float") | |
if not isinstance(continent, str): | |
raise ValueError("continent param must be a string") | |
self.country_name = country_name | |
self.population = population | |
self.continent = continent | |
def get_population_in_millions(self): | |
return round(self.population, 2) | |
def test_population(): | |
""" | |
Note: If the result is wrong, calling test_population | |
will throw exception 'AssertionError' | |
""" | |
country = Country("myFakeCountry", 10.0, "EU") | |
expected = 10.00 | |
result = expected == country.get_population_in_millions() | |
print("Test result = {res}".format(res=result)) | |
assert result | |
test_population() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment