def testTValue(self): """Tests calculation of the t-value using Welch's formula.""" # Results can be verified by directly plugging variables into Welch's # equation (e.g. using a calculator or the Python interpreter). stats1 = ttest.SampleStats(mean=0.299, var=0.05, size=150) stats2 = ttest.SampleStats(mean=0.307, var=0.08, size=165) # Note that a negative t-value is obtained when the first sample has a # smaller mean than the second, otherwise a positive value is returned. self.assertAlmostEqual(-0.27968236, ttest._TValue(stats1, stats2)) self.assertAlmostEqual(0.27968236, ttest._TValue(stats2, stats1))
def testTValue_ConstantSamples_ResultIsInfinity(self): """If there is no variation, infinity is used as the t-statistic value.""" stats = ttest.SampleStats(mean=1.0, var=0, size=10) self.assertEqual(float('inf'), ttest._TValue(stats, stats))