def test_resize_shrink(self): d = Dist(5) for i in range(len(d)): d[i] = i + 1 self.assertEqual(5, len(d)) self.assertEqual(15, d.counts()) d.resize(3) self.assertEqual(3, len(d)) self.assertEqual(6, d.counts()) for i in range(len(d)): self.assertEqual(i + 1, d[i])
def test_resize_shrink(self): d = Dist(5) for i in range(len(d)): d[i] = i+1 self.assertEqual(5, len(d)) self.assertEqual(15, d.counts()) d.resize(3) self.assertEqual(3, len(d)) self.assertEqual(6, d.counts()) for i in range(len(d)): self.assertEqual(i+1, d[i])
def test_resize_grow(self): d = Dist(3) for i in range(len(d)): d[i] = i + 1 self.assertEqual(3, len(d)) self.assertEqual(6, d.counts()) d.resize(5) self.assertEqual(5, len(d)) self.assertEqual(6, d.counts()) for i in range(3): self.assertEqual(i + 1, d[i]) for i in range(3, len(d)): self.assertEqual(0, d[i])
def test_resize_grow(self): d = Dist(3) for i in range(len(d)): d[i] = i+1 self.assertEqual(3, len(d)) self.assertEqual(6, d.counts()) d.resize(5) self.assertEqual(5, len(d)) self.assertEqual(6, d.counts()) for i in range(3): self.assertEqual(i+1, d[i]) for i in range(3,len(d)): self.assertEqual(0, d[i])
def test_copy(self): d = Dist(5) for i in range(len(d)): d[i] = i + 1 self.assertEqual(5, len(d)) self.assertEqual(15, d.counts()) e = d.copy() self.assertEqual(5, len(d)) self.assertEqual(15, d.counts()) for i in range(len(d)): self.assertEqual(e[i], d[i]) d[0] = 5 self.assertNotEqual(e[0], d[0])
def test_copy(self): d = Dist(5) for i in range(len(d)): d[i] = i+1 self.assertEqual(5, len(d)) self.assertEqual(15, d.counts()) e = d.copy() self.assertEqual(5, len(d)) self.assertEqual(15, d.counts()) for i in range(len(d)): self.assertEqual(e[i], d[i]) d[0] = 5 self.assertNotEqual(e[0], d[0])
def test_tick(self): d = Dist(2) self.assertEqual(1, d.tick(0)) self.assertEqual(2, d.tick(0)) self.assertEqual(2, d.counts()) self.assertTrue(d.valid())
def test_counts(self): d = Dist(2) self.assertEqual(0, d.counts()) d[0] = 3 self.assertEqual(3, d.counts()) d[0] = 2 self.assertEqual(2, d.counts()) d[1] = 3 self.assertEqual(5, d.counts()) d[0] = 0 d[1] = 0 self.assertEqual(0, d.counts())
def test_dump(self): d = Dist(5) for i in range(1, len(d)): d[i] = i+1 self.assertEqual(14, d.counts()) probs = d.dump() self.assertTrue((probs == np.array([0., 2./14, 3./14, 4./14, 5./14])).all())
def test_dump(self): d = Dist(5) for i in range(1, len(d)): d[i] = i + 1 self.assertEqual(14, d.counts()) probs = d.dump() self.assertTrue( (probs == np.array([0., 2. / 14, 3. / 14, 4. / 14, 5. / 14])).all())