def testSetup(self): """ Test the setup interface function. """ # Construct. tsd = TimeStepDistribution() # Set the time. time = numpy.random.rand() # Call setup. tsd.setup("step", time, "configuration") # Check that the time was saved. self.assertAlmostEqual(tsd._TimeStepDistribution__last_time, time, 12)
def testSetup(self): """ Test the setup interface function. """ # Construct. tsd = TimeStepDistribution() # Set the time. time = numpy.random.rand() # Call setup. tsd.setup("step", time, "configuration") # Check that the time was saved. self.assertAlmostEqual(tsd._TimeStepDistribution__last_time, time, 12)
def testRegisterStep(self): """ Test the register step interface function. """ # Construct. binsize = 1.23 tsd = TimeStepDistribution(binsize=binsize) # Store the histogram size for reference. h_size = len(tsd._TimeStepDistribution__histogram) # Set the first time and call setup. t0 = numpy.random.rand() tsd.setup("step", t0, "configuration") # Call the step function with a new time. t1 = t0 + 5 * numpy.random.rand() tsd.registerStep("step", t1, "configuration") # Calculate the bin. b = int((t1 - t0) / binsize) # Check that this bin was incremented. self.assertEqual(tsd._TimeStepDistribution__histogram[b], 1) for i in range(10): if i != b: self.assertEqual(tsd._TimeStepDistribution__histogram[i], 0) # Give a new value that requires the histogram to be extended. t2 = 10 tsd.registerStep("step", t2, "configuration") t3 = 23 tsd.registerStep("step", t3, "configuration") # Check that the length has incresed to 11. self.assertEqual(len(tsd._TimeStepDistribution__histogram), 11) self.assertEqual(tsd._TimeStepDistribution__histogram[10], 1) # Increment again. This should end up with a length of 22. t4 = 48 tsd.registerStep("step", t4, "configuration") self.assertEqual(len(tsd._TimeStepDistribution__histogram), 22)
def testRegisterStep(self): """ Test the register step interface function. """ # Construct. binsize = 1.23 tsd = TimeStepDistribution(binsize=binsize) # Store the histogram size for reference. h_size = len(tsd._TimeStepDistribution__histogram) # Set the first time and call setup. t0 = numpy.random.rand() tsd.setup("step", t0, "configuration") # Call the step function with a new time. t1 = t0 + 5*numpy.random.rand() tsd.registerStep("step", t1, "configuration") # Calculate the bin. b = int((t1 - t0) / binsize) # Check that this bin was incremented. self.assertEqual(tsd._TimeStepDistribution__histogram[b], 1) for i in range(10): if i != b: self.assertEqual(tsd._TimeStepDistribution__histogram[i], 0) # Give a new value that requires the histogram to be extended. t2 = 10 tsd.registerStep("step", t2, "configuration") t3 = 23 tsd.registerStep("step", t3, "configuration") # Check that the length has incresed to 11. self.assertEqual(len(tsd._TimeStepDistribution__histogram), 11) self.assertEqual(tsd._TimeStepDistribution__histogram[10], 1) # Increment again. This should end up with a length of 22. t4 = 48 tsd.registerStep("step", t4, "configuration") self.assertEqual(len(tsd._TimeStepDistribution__histogram), 22)