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 
00015 def eps_equal(a, b, err=0.001):
00016     return abs(a - b) < err
00017 
00018 
00019 class TestTopicCompare(unittest.TestCase):
00020     """Subscribing three topics
00021     * /origin
00022     * /origin (the same topic)
00023     * /half
00024     """
00025 
00026     def test_same_topic(self):
00027         while not tc.isAllTopicAvailable(20):
00028             rospy.sleep(1)
00029         print tc.getTotalBytes(0) / (tc.getEndTime(0) - tc.getStartTime(0))
00030         print tc.getTotalBytes(1) / (tc.getEndTime(1) - tc.getStartTime(1))
00031         self.assertTrue(eps_equal(tc.getBandwidth(0), tc.getBandwidth(1), 20))
00032 
00033     def test_half_topic(self):
00034         while not tc.isAllTopicAvailable(20):
00035             rospy.sleep(1)
00036         print tc.getTotalBytes(0) / (tc.getEndTime(0) - tc.getStartTime(0))
00037         print tc.getTotalBytes(2) / (tc.getEndTime(2) - tc.getStartTime(2))
00038         self.assertTrue(eps_equal(tc.getBandwidth(0), 2 * tc.getBandwidth(2), 20))
00039 
00040 
00041 if __name__ == "__main__":
00042     import rostest
00043     rospy.init_node("test_topic_compare")
00044     tc = ROSTopicCompare()
00045     tc.registerTopic("/origin")
00046     tc.registerTopic("/origin")
00047     tc.registerTopic("/half")
00048     rostest.rosrun("jsk_topic_tools", "test_topic_compare", TestTopicCompare)


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Fri Sep 8 2017 03:38:56