def test_scalar_multiply_bucket(self): IFBucket = self.family.IF.Bucket x = IFBucket([(1, 2), (2, 3), (3, 4)]) allkeys = list(x.keys()) for factor in 0, 1, 5, 10: result = self._callFUT([(x, factor)]) self.assertEqual(allkeys, list(result.keys())) for key in x.keys(): self.assertEqual(result[key], x[key] * factor)
def test_scalar_multiply_bucket(self): from BTrees.IFBTree import IFBucket x = IFBucket([(1, 2), (2, 3), (3, 4)]) allkeys = list(x.keys()) for factor in 0, 1, 5, 10: result = self._callFUT([(x, factor)]) self.assertEqual(allkeys, list(result.keys())) for key in x.keys(): self.assertEqual(result[key], x[key]*factor)
def test_pairs(self): IFBTree = self.family.IF.BTree IFBucket = self.family.IF.Bucket t1 = IFBTree([(1, 10), (3, 30), (7, 70)]) t2 = IFBTree([(3, 30), (5, 50), (7, 7), (9, 90)]) allkeys = [1, 3, 5, 7, 9] b1 = IFBucket(t1) b2 = IFBucket(t2) for x in t1, t2, b1, b2: for key in x.keys(): self.assertEqual(key in allkeys, 1) for y in t1, t2, b1, b2: for w1, w2 in (0, 0), (1, 10), (10, 1), (2, 3): expected = [] for key in allkeys: if key in x and key in y: result = x[key] * w1 + y[key] * w2 expected.append((key, result)) expected = sorted(expected) got = self._callFUT([(x, w1), (y, w2)]) self.assertEqual(expected, list(got.items())) got = self._callFUT([(y, w2), (x, w1)]) self.assertEqual(expected, list(got.items()))
def test_pairs(self): from BTrees.IFBTree import IFBTree from BTrees.IFBTree import IFBucket t1 = IFBTree([(1, 10), (3, 30), (7, 70)]) t2 = IFBTree([(3, 30), (5, 50), (7, 7), (9, 90)]) allkeys = [1, 3, 5, 7, 9] b1 = IFBucket(t1) b2 = IFBucket(t2) for x in t1, t2, b1, b2: for key in x.keys(): self.assertEqual(key in allkeys, 1) for y in t1, t2, b1, b2: for w1, w2 in (0, 0), (1, 10), (10, 1), (2, 3): expected = [] for key in allkeys: if key in x or key in y: result = x.get(key, 0) * w1 + y.get(key, 0) * w2 expected.append((key, result)) expected.sort() got = self._callFUT([(x, w1), (y, w2)]) self.assertEqual(expected, list(got.items())) got = self._callFUT([(y, w2), (x, w1)]) self.assertEqual(expected, list(got.items()))
def test_identity_bucket(self): IFBucket = self.family.IF.Bucket x = IFBucket([(1, 2)]) result = self._callFUT([(x, 1)]) self.assertEqual(len(result), 1) self.assertEqual(list(result.items()), list(x.items()))
def test_identity_bucket(self): from BTrees.IFBTree import IFBucket x = IFBucket([(1, 2)]) result = self._callFUT([(x, 1)]) self.assertEqual(len(result), 1) self.assertEqual(list(result.items()), list(x.items()))
def setUp(self): self.t = IFBucket()