Beispiel #1
0
    def test_basic_operations(self):
        d = DistributionCell()
        d.update(10)
        self.assertEqual(d.get_cumulative(), DistributionData(10, 1, 10, 10))

        d.update(2)
        self.assertEqual(d.get_cumulative(), DistributionData(12, 2, 2, 10))

        d.update(900)
        self.assertEqual(d.get_cumulative(), DistributionData(912, 3, 2, 900))
Beispiel #2
0
  def test_basic_operations(self):
    d = DistributionCell()
    d.update(10)
    self.assertEqual(d.get_cumulative(),
                     DistributionData(10, 1, 10, 10))

    d.update(2)
    self.assertEqual(d.get_cumulative(),
                     DistributionData(12, 2, 2, 10))

    d.update(900)
    self.assertEqual(d.get_cumulative(),
                     DistributionData(912, 3, 2, 900))
Beispiel #3
0
 def test_integer_only(self):
   d = DistributionCell()
   d.update(3.1)
   d.update(3.2)
   d.update(3.3)
   self.assertEqual(d.get_cumulative(),
                    DistributionData(9, 3, 3, 3))
Beispiel #4
0
  def test_parallel_access(self):
    # We create NUM_THREADS threads that concurrently modify the distribution.
    threads = []
    d = DistributionCell()
    for _ in range(TestDistributionCell.NUM_THREADS):
      t = threading.Thread(target=TestDistributionCell._modify_distribution,
                           args=(d,))
      threads.append(t)
      t.start()

    for t in threads:
      t.join()

    total = (self.NUM_ITERATIONS * (self.NUM_ITERATIONS-1)/2 * self.NUM_THREADS)

    count = (self.NUM_ITERATIONS * self.NUM_THREADS)

    self.assertEqual(d.get_cumulative(),
                     DistributionData(total, count, 0,
                                      self.NUM_ITERATIONS - 1))
Beispiel #5
0
    def test_parallel_access(self):
        # We create NUM_THREADS threads that concurrently modify the distribution.
        threads = []
        d = DistributionCell()
        for _ in range(TestDistributionCell.NUM_THREADS):
            t = threading.Thread(
                target=TestDistributionCell._modify_distribution, args=(d, ))
            threads.append(t)
            t.start()

        for t in threads:
            t.join()

        total = (self.NUM_ITERATIONS * (self.NUM_ITERATIONS - 1) // 2 *
                 self.NUM_THREADS)

        count = (self.NUM_ITERATIONS * self.NUM_THREADS)

        self.assertEqual(
            d.get_cumulative(),
            DistributionData(total, count, 0, self.NUM_ITERATIONS - 1))
Beispiel #6
0
 def test_integer_only(self):
     d = DistributionCell()
     d.update(3.1)
     d.update(3.2)
     d.update(3.3)
     self.assertEqual(d.get_cumulative(), DistributionData(9, 3, 3, 3))