circular_buffer_test.py
Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2011, Georgia Tech Research Corporation
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are met:
00007 #     * Redistributions of source code must retain the above copyright
00008 #       notice, this list of conditions and the following disclaimer.
00009 #     * Redistributions in binary form must reproduce the above copyright
00010 #       notice, this list of conditions and the following disclaimer in the
00011 #       documentation and/or other materials provided with the distribution.
00012 #     * Neither the name of the Georgia Tech Research Corporation nor the
00013 #       names of its contributors may be used to endorse or promote products
00014 #       derived from this software without specific prior written permission.
00015 #
00016 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00017 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00020 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 #
00027 
00028 #  \author Charlie Kemp (Healthcare Robotics Lab, Georgia Tech.)
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 


hrl_lib
Author(s): Cressel Anderson, Travis Deyle, Advait Jain, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:06