00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import numpy as np
00032 import circular_buffer as cb
00033
00034 t = cb.CircularBuffer(5,())
00035
00036 def compare_lists(proven_list, test_list, slice_str):
00037 proven = proven_list
00038 test = test_list
00039 proven_command = "proven" + "[" + slice_str + "]"
00040 proven_out = eval(proven_command)
00041 test_command = "test" + "[" + slice_str + "]"
00042 test_out = eval(test_command)
00043 passed = True
00044 if len(proven_out) != len(test_out):
00045 passed = False
00046 for pi, ti in zip(proven_out, test_out):
00047 if (pi - ti) > 0.0000001:
00048 passed = False
00049 if not passed:
00050 print "***************************"
00051 print "****** FAILED TEST *******"
00052 print proven_command + " ="
00053 print proven_out
00054 print test_command + " ="
00055 print test_out
00056 print "***************************"
00057 else:
00058 print "---------------------------"
00059 print "------ passed test -------"
00060 print proven_command + " ="
00061 print proven_out
00062 print test_command + " ="
00063 print test_out
00064 print "---------------------------"
00065
00066
00067 t.append(0)
00068 t.append(1)
00069 t.append(2)
00070 t.append(3)
00071 m = np.arange(0.0, 4.0, 1.0).tolist()
00072 print 't =', t
00073 print 'len(t) =', len(t)
00074 print 'm =', m
00075 print 'len(m) =', len(m)
00076 print
00077
00078 compare_lists(m, t, ":")
00079 compare_lists(m, t, "1:")
00080 compare_lists(m, t, "1:2")
00081 compare_lists(m, t, "2:2")
00082 compare_lists(m, t, "::2")
00083 compare_lists(m, t, "-1:")
00084
00085 print "t.append(4)"
00086 t.append(4)
00087 print "t.append(5)"
00088 t.append(5)
00089 print "t.append(6)"
00090 t.append(6)
00091 print "t.append(7)"
00092 t.append(7)
00093 print "m = range(3,8)"
00094 m = np.arange(3.0, 8.0, 1.0).tolist()
00095 print
00096 print
00097 print 't =', t
00098 print 'len(t) =', len(t)
00099 print 'm =', m
00100 print 'len(m) =', len(m)
00101 print
00102
00103 compare_lists(m, t, ":")
00104 compare_lists(m, t, "1:")
00105 compare_lists(m, t, "1:2")
00106 compare_lists(m, t, "2:2")
00107 compare_lists(m, t, "::2")
00108 compare_lists(m, t, "-1:")
00109
00110 compare_lists(m, t, ":")
00111 compare_lists(m, t, "0:")
00112 compare_lists(m, t, "1:")
00113 compare_lists(m, t, "2:")
00114 compare_lists(m, t, "3:")
00115 compare_lists(m, t, "4:")
00116 compare_lists(m, t, "5:")
00117
00118 compare_lists(m, t, "-1:3")
00119 compare_lists(m, t, "-3:3")
00120 compare_lists(m, t, ":3")
00121 compare_lists(m, t, ":10")
00122 compare_lists(m, t, ":100")
00123 compare_lists(m, t, "-3:")
00124 compare_lists(m, t, "-10:")
00125 compare_lists(m, t, "-100:")
00126 compare_lists(m, t, ":-3")
00127 compare_lists(m, t, ":-10")
00128 compare_lists(m, t, ":-100")
00129 compare_lists(m, t, "10:")
00130 compare_lists(m, t, "100:")
00131
00132
00133