-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompareSignal.py
41 lines (41 loc) · 1.56 KB
/
CompareSignal.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
def Compare_Signals(file_name,Your_indices,Your_samples):
expected_indices=[]
expected_samples=[]
with open(file_name, 'r') as f:
line = f.readline()
line = f.readline()
line = f.readline()
line = f.readline()
while line:
# process line
L=line.strip()
if len(L.split(' '))==2:
L=line.split(' ')
V1=int(L[0])
V2=float(L[1])
expected_indices.append(V1)
expected_samples.append(V2)
line = f.readline()
else:
break
print("Current Output Test file is: ")
print(file_name)
print("\n")
if (len(expected_samples)!=len(Your_samples)) and (len(expected_indices)!=len(Your_indices)):
print("Test case failed, your signal have different length from the expected one")
return
for i in range(len(Your_indices)):
if(Your_indices[i]!=expected_indices[i]):
print("Test case failed, your signal have different indicies from the expected one")
return
for i in range(len(expected_samples)):
if abs(Your_samples[i] - expected_samples[i]) < 0.01:
continue
else:
print("i=",i)
print("index ",Your_indices[i])
print("your sample",Your_samples[i])
print("expected sample",expected_samples[i])
print("Test case failed, your signal have different values from the expected one")
return
print("Test case passed successfully")