MCPcopy Index your code
hub / github.com/python/cpython / test_inplace_operations

Method test_inplace_operations

Lib/test/test_collections.py:2323–2343  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2321 self.assertEqual(counter_result, dict.fromkeys(set_result, 1))
2322
2323 def test_inplace_operations(self):
2324 elements = 'abcd'
2325 for i in range(1000):
2326 # test random pairs of multisets
2327 p = Counter(dict((elem, randrange(-2,4)) for elem in elements))
2328 p.update(e=1, f=-1, g=0)
2329 q = Counter(dict((elem, randrange(-2,4)) for elem in elements))
2330 q.update(h=1, i=-1, j=0)
2331 for inplace_op, regular_op in [
2332 (Counter.__iadd__, Counter.__add__),
2333 (Counter.__isub__, Counter.__sub__),
2334 (Counter.__ior__, Counter.__or__),
2335 (Counter.__iand__, Counter.__and__),
2336 (Counter.__ixor__, Counter.__xor__),
2337 ]:
2338 c = p.copy()
2339 c_id = id(c)
2340 regular_result = regular_op(c, q)
2341 inplace_result = inplace_op(c, q)
2342 self.assertEqual(inplace_result, regular_result)
2343 self.assertEqual(id(inplace_result), c_id)
2344
2345 def test_subtract(self):
2346 c = Counter(a=-5, b=0, c=5, d=10, e=15,g=40)

Callers

nothing calls this directly

Calls 5

updateMethod · 0.95
copyMethod · 0.95
CounterClass · 0.90
idFunction · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected