-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cities.py
33 lines (26 loc) · 1.34 KB
/
test_cities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import unittest
import pandas as pd
# Function to create the DataFrame
def create_cities_dataframe():
cities_data = {
'City': ["Tokyo", "Delhi", "Shanghai", "Dhaka", "São Paulo", "Mexico City", "Cairo", "Beijing", "Mumbai", "Osaka"],
'Country': ["Japan", "India", "China", "Bangladesh", "Brazil", "Mexico", "Egypt", "China", "India", "Japan"],
'Population (Millions)': [37.2, 32.9, 24.8, 23.2, 22.6, 22.3, 22.2, 21.9, 20.7, 19.1]
}
return pd.DataFrame(cities_data)
class TestCitiesDataFrame(unittest.TestCase):
def setUp(self):
self.df = create_cities_dataframe()
def test_column_names(self):
expected_columns = ['City', 'Country', 'Population (Millions)']
self.assertListEqual(list(self.df.columns), expected_columns)
def test_number_of_rows(self):
self.assertEqual(len(self.df), 10)
def test_population_values(self):
expected_populations = [37.2, 32.9, 24.8, 23.2, 22.6, 22.3, 22.2, 21.9, 20.7, 19.1]
self.assertListEqual(list(self.df['Population (Millions)']), expected_populations)
def test_city_names(self):
expected_cities = ["Tokyo", "Delhi", "Shanghai", "Dhaka", "São Paulo", "Mexico City", "Cairo", "Beijing", "Mumbai", "Osaka"]
self.assertListEqual(list(self.df['City']), expected_cities)
if __name__ == '__main__':
unittest.main()