def test_buflen(self):
    tm_0 = TimeMeasure(1)
    self.assertEqual(0, tm_0.count())
    tm_0.tick()
    tm_0.tack()
    self.assertEqual(1, tm_0.count())

    count_ = 1024
    tm_1 = TimeMeasure(count_)

    for i in range(count_):
      self.assertEqual(i, tm_1.count())
      tm_1.tick()
      tm_1.tack()

    for i in range(count_):
      tm_1.tick()
      tm_1.tack()
      self.assertEqual(count_ + 1, tm_1.count())
    return
  def test_stat(self):
    tm_ = TimeMeasure()
    maxi  = [0.0]
    mini  = [0.0]
    mean  = [0.0]
    stdev = [0.0]

    self.assertEqual(False, tm_.getStatistics(maxi, mini, mean, stdev))
    tm_.tick()
    self.assertEqual(False, tm_.getStatistics(maxi, mini, mean, stdev))
    tm_.tack()
    self.assertEqual(True, tm_.getStatistics(maxi, mini, mean, stdev))
    tm_.reset()
    self.assertEqual(False, tm_.getStatistics(maxi, mini, mean, stdev))
    return
  def test_coutn(self):
    tm_ = TimeMeasure()
    self.assertEqual(0, tm_.count())

    count0 = 10
    for i in range(10):
      tm_.tick()
      tm_.tack()
    self.assertEqual(10, tm_.count())

    tm_.reset()
    self.assertEqual(0, tm_.count())


    count0 = 102
    for i in range(102):
      tm_.tick()
      tm_.tack()
    self.assertNotEqual(102, tm_.count())
    return
  def test_1s(self):
    wait_ = 1.0 # [s]
    tm_ = TimeMeasure()
    for i in range(1):
      tm_.tick()
      time.sleep(wait_)
      tm_.tack()

    maxi  = [0.0]
    mini  = [0.0]
    mean  = [0.0]
    stdev = [0.0]
    tm_.getStatistics(maxi, mini, mean, stdev)
    print "test_1ms"
    print "max interval : ", maxi[0], " [sec]"
    print "min interval : ", mini[0], " [sec]"
    print "mean interval: ", mean[0], " [sec]"
    print "stddev       : ", stdev[0], " [sec]"
    self.assert_(maxi[0] < (wait_ + 0.030))
    self.assert_(mini[0] > (wait_ - 0.010))
    self.assert_(math.fabs(mean[0] - wait_) < 0.03)
    self.assert_(stdev[0] < (wait_ / 5.0))
    return
 def setUp(self):
   self._tm = TimeMeasure(10)