test_topic_compare.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import os
00003 import sys
00004 
00005 import unittest
00006 
00007 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", 
00008                                                 "scripts")))
00009 from topic_compare import ROSTopicCompare
00010 
00011 import rospy
00012 import time
00013 
00014 def eps_equal(a, b, err=0.001):
00015     return abs(a - b) < err
00016 
00017 # subscribing three topics
00018 #   * /origin
00019 #   * /origin (the same topic)
00020 #   * /half
00021 class TestTopicCompare(unittest.TestCase):
00022     def test_same_topic(self):
00023         current_time = time.time()
00024         self.assertTrue(eps_equal(tc.getTotalBytes(0) / (current_time - tc.getStartTime(0)),
00025                                   tc.getTotalBytes(1) / (current_time - tc.getStartTime(1)), 1))
00026     def test_half_topic(self):
00027         current_time = time.time()
00028         rospy.loginfo(tc.getTotalBytes(0) / (current_time - tc.getStartTime(0)))
00029         rospy.loginfo(tc.getTotalBytes(2) * 2 / (current_time - tc.getStartTime(2)))
00030 
00031         self.assertTrue(eps_equal(tc.getTotalBytes(0) / (current_time - tc.getStartTime(0)),
00032                                   tc.getTotalBytes(2) * 2 / (current_time - tc.getStartTime(2)), 1))
00033 
00034 if __name__ == "__main__":
00035     import rostest
00036     rospy.init_node("test_topic_compare")
00037     tc = ROSTopicCompare()
00038     tc.registerTopic("/origin")
00039     tc.registerTopic("/origin")
00040     tc.registerTopic("/half")
00041     rospy.loginfo("wait 30sec to acuumulate topics...")
00042     rospy.sleep(30)
00043     rostest.rosrun("jsk_topic_tools", "test_topic_compare", TestTopicCompare)
00044 
00045 


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Sun Jan 25 2015 00:30:41