Beispiel #1
0
 def get_next_hop(self):
    hist = Histogram()
    print hist
    for message in self.ferry.messages:
       hist.count(message.dest)
    priorities = hist.norm_hist()
    hop = random.choice(self.ferry.term_map.items())
    max_rating = 0.0
    for term in self.ferry.term_map.keys():
       try:
          prio = priorities[term]
          d = self.dist(self.term_pos(self.current_term), self.term_pos(term))
          rating = priorities[term] / self.dist(self.term_pos(self.current_term), self.term_pos(term))
       except:
          rating = 0.0
       if rating > max_rating:
          max_rating = rating
          hop = term, self.term_pos(term)
    self.current_term = hop[0]
    return hop
class HistogramTest(unittest.TestCase):

    def setUp(self):
        self.h = Histogram()
        self.h.add("Apache")
        self.h.add("Apache")

    def test_add(self):
        assert self.h.get_dict().get("Apache") is not None

    def test_count(self):
        self.assertEqual(self.h.count("Apache"), 2)
Beispiel #3
0
class HistogramTests(unittest.TestCase):

    def setUp(self):
        self.ap = 'Apache'
        self.ng = 'nginx'
        self.iis = 'IIS'
        self.h = Histogram()

    def testAddRecord(self):
        self.h.add(self.ap)
        self.assertEqual(1, len(self.h.get_dict()))

    def testAddRecord_2(self):
        self.h.add(self.ap)
        self.h.add(self.ng)
        self.assertEqual(2, len(self.h.get_dict()))

    def testCountRecord(self):
        self.h.add(self.ap)
        self.assertEqual(1, self.h.count("Apache"))

    def testCountRecord_2(self):
        self.h.add(self.ap)
        self.h.add(self.ap)
        self.assertEqual(2, self.h.count("Apache"))

    def testCountRecord_3(self):
        self.h.add(self.ap)
        self.h.add(self.ap)
        self.h.add(self.ng)
        self.assertEqual(None, self.h.count("IBM Web Server"))

    def testGetDict_4(self):
        self.h.add(self.ap)
        self.h.add(self.ap)
        self.h.add(self.ng)
        self.h.add(self.ng)
        self.h.add(self.iis)
        self.assertEqual(self.h.get_dict(), {"Apache": 2, "nginx": 2, "IIS": 1})