コード例 #1
0
 def test_combine_other_empty(self):
     s1 = Statistics()
     s2 = Statistics()
     s1.add(1.0)
     s3 = s1.combine(s2)
     self.assertEqual(1, len(s3))
     self.assertEqual(1.0, s3.mean)
コード例 #2
0
 def test_add_zero_once(self):
     s = Statistics()
     s.add(0.0)
     self.assertEqual(1, len(s))
     self.assertEqual(0.0, s.mean)
     self.assertEqual(0.0, s.var)
     self.assertEqual(0.0, s.std)
     self.assertEqual(0.0, s.min)
     self.assertEqual(0.0, s.max)
コード例 #3
0
 def test_add_multiple(self):
     s = Statistics()
     s.add(0.0)
     s.add(1.0)
     s.add(2.0)
     self.assertEqual(3, len(s))
     self.assertEqual(1.0, s.mean)
     # note that np.var returns the variance, not sample variance
     sample_variance = 3.0 / 2.0 * np.var([0.0, 1.0, 2.0])
     self.assertEqual(1.0, sample_variance)
     self.assertEqual(sample_variance, s.var)
     self.assertEqual(np.sqrt(sample_variance), s.std)
     self.assertEqual(0.0, s.min)
     self.assertEqual(2.0, s.max)
コード例 #4
0
 def test_combine(self):
     s1 = Statistics()
     for x in np.arange(0, 11):
         s1.add(x)
     s2 = Statistics()
     for x in np.arange(11, 21):
         s2.add(x)
     s3 = Statistics()
     for x in np.arange(0, 21):
         s3.add(x)
     sc = s1.combine(s2)
     self.assertEqual(len(s3), len(sc))
     self.assertEqual(s3.mean, sc.mean)
     self.assertEqual(s3.var, sc.var)
     self.assertEqual(s3.std, sc.std)
     self.assertEqual(s3.min, sc.min)
     self.assertEqual(s3.max, sc.max)
コード例 #5
0
 def test_combine_both_empty(self):
     s1 = Statistics()
     s2 = Statistics()
     s3 = s1.combine(s2)
     self.assertEqual(0, len(s3))