OpenCores
URL https://opencores.org/ocsvn/heap_sorter/heap_sorter/trunk

Subversion Repositories heap_sorter

[/] [heap_sorter/] [trunk/] [standard_version/] [sort_test_check.py] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 wzab
#!/usr/bin/python
2
# This Python script checks if the records were sorted
3
# correctly...
4
import sys
5
# We read the input records and store them in one vector
6
fi=open("events.in","r")
7
ri=fi.read().split("\n")
8
ri=[i.split(" ") for i in ri]
9
# Leave only valid records
10
ri=[i for i in ri if len(i)==3 and i[0]=="01"]
11
# We read the output vectors and store them in a second vector
12
fo=open("events.out","r")
13
ro=fo.read().split("\n")
14
ro=[i.split(" ") for i in ro ]
15
# Leave only valid records
16
ro=[i for i in ro if len(i)==3 and i[0]=="01"]
17
# We check if the output vectors are correctly sorted
18
for i in range(1,len(ro)):
19
  # Theoretically we could simply check the condition:
20
  # int(ro[i-1][1],2) <= int(ro[i][1],2)
21
  # However for longer sequences we may need to 
22
  # consider the fact that sort keys (time stamps)
23
  # will wrap around.
24
  # Therefore we need to perform slightly more 
25
  # complicated test - if we use N bits to store
26
  # the sort key, then we need to subtract keys modulo
27
  # 2**N and if the difference is in range (0,2**(N-1)]
28
  # we consider the difference positive, while in range
29
  # (2**(N-1),(2**N)-1) we consider it negative.
30
  k1 = ro[i-1][1]
31
  k2 = ro[i][1]
32
  dlim = 1<<len(k1)
33
  diff=(int(k2,2)-int(k1,2)) % dlim
34
  if diff > dlim/2:
35
     print "Records unsorted!\n"
36
     print str(i-1)+": "+str(ro[i-1])
37
     print str(i)+": "+str(ro[i])
38
     sys.exit(1)
39
# We check if all input vectors were transferred to the output
40
# Now we only check size of vectors
41
if len(ro) != len(ri):
42
    print "Not all records transferred!\n"
43
    sys.exit(1)
44
print "Test passed!\n"
45
sys.exit(0)
46
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.