-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest script.py
More file actions
49 lines (41 loc) · 1.5 KB
/
Test script.py
File metadata and controls
49 lines (41 loc) · 1.5 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Author: Or Basker
# ID: 316388743
from data_summary import DataSummary
if __name__ == "__main__":
try:
DS_err = DataSummary() # This should raise an exception
except Exception as err:
print("Exception: ", err)
else:
print("unexpected DataSummary constructor")
DS = DataSummary(datafile="Ex1.json", metafile="Happiness Metadata.csv")
print(DS[3]) # Test __getitem__ by index
print(DS["Country"]) # Test __getitem__ by key
try:
DS["GDP"] # This should raise an exception
except Exception as err:
print("Exception: ", err)
else:
print("unexpected feature GDP")
try:
DS["data"] # This should raise an exception
except Exception as err:
print("Exception: ", err)
else:
print("unexpected feature data")
print(DS.mean("Happiness Score")) # Test mean method
print(DS.mode("Class")) # Test mode method
print(DS.unique("Region")) # Test unique method
try:
DS.min("Country") # This should raise an exception
except Exception as err:
print("Exception: ", err)
else:
print("unexpected function min for categorical feature")
print(DS.max("Happiness Score")) # Test max method
print(DS.empty("Happiness Score")) # Test empty method
test_filename = "test_output.csv"
DS.to_csv(test_filename) # Test to_csv method
print(f"CSV exported to {test_filename}")
import os
os.remove(test_filename)