-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_trajectory.py
140 lines (106 loc) · 3.78 KB
/
test_trajectory.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
## Libraries
import pytest
from trajectory_class import Trajectory
import pandas as pd
from os import path
## Checking method
def check(trajectory:Trajectory):
"""applying the TDD method to the Trajectory class"""
## checking if the file path exists
if trajectory.test == 0:
if path.exists(trajectory.file_path):
return 'file path exists'
## checking if the file is a csv or txt file
if trajectory.test == 1:
if trajectory.file_path.endswith('.csv'):
trajectory.df = pd.read_csv(trajectory.file_path)
trajectory.df = trajectory.df.dropna(axis=0, how="any")
return 'file format is correct'
if trajectory.file_path.endswith('.txt'):
trajectory.df = pd.read_csv(trajectory.file_path, sep=' ')
trajectory.df = trajectory.df.dropna(axis=0, how="any")
return 'file format is correct'
## checking if the file is not empty
if trajectory.test == 2:
if trajectory.df.shape[0] >= 3 and trajectory.df.shape[1] >= 2:
return 'file is not empty'
## checking if the data shape is correct
if trajectory.test == 3:
if trajectory.df.shape[1] == 4:
trajectory.df.columns = ['x', 'y', 'nx', 'ny']
return 'all data is there'
## checking the format of the data
if trajectory.test == 4:
if (trajectory.df[['x', 'y']].dtypes == 'float64').all() or (trajectory.df[['x', 'y']].dtypes == 'int64').all():
trajectory.df = trajectory.df.select_dtypes(include=['float64'])
return 'data format is correct'
## checking if coordinates are uploaded succesfuly
if trajectory.test == 5:
trajectory.get_coord()
print(f"Trajectory '{trajectory}' is uploaded succesfuly")
return 'Trajectory is uploaded succesfuly'
## Example
### file path
file_path = 'cabspottingdata/new_uvreoipy.txt'
### The input Trajectories
## TESTS
## test 0
def test_file_existence():
"""checking the existence of the file path"""
trajectory = Trajectory(file_path)
assert check(trajectory) == 'file path exists'
## test 1
def test_file_format():
"""checking the file format"""
trajectory = Trajectory(file_path)
check(trajectory)
trajectory.next_test()
assert check(trajectory) == 'file format is correct'
## test 2
def test_empty_file():
"""checking that the file is not empty"""
trajectory = Trajectory(file_path)
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
assert check(trajectory) == 'file is not empty'
## test 3
def test_all_data_there():
"""checking that all data is there"""
trajectory = Trajectory(file_path)
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
assert check(trajectory) == 'all data is there'
## test 4
def test_data_format():
"""checking the data format is correct"""
trajectory = Trajectory(file_path)
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
assert check(trajectory) == 'data format is correct'
## test 5
def test_upload_coordinates():
"""checking the coordinates upload"""
trajectory = Trajectory(file_path)
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
check(trajectory)
trajectory.next_test()
assert check(trajectory) == 'Trajectory is uploaded succesfuly'