MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_inplace_operations

Method test_inplace_operations

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

Source from the content-addressed store, hash-verified

2299 self.assertEqual(counter_result, dict.fromkeys(set_result, 1))
2300
2301 def test_inplace_operations(self):
2302 elements = 'abcd'
2303 for i in range(1000):
2304 # test random pairs of multisets
2305 p = Counter(dict((elem, randrange(-2,4)) for elem in elements))
2306 p.update(e=1, f=-1, g=0)
2307 q = Counter(dict((elem, randrange(-2,4)) for elem in elements))
2308 q.update(h=1, i=-1, j=0)
2309 for inplace_op, regular_op in [
2310 (Counter.__iadd__, Counter.__add__),
2311 (Counter.__isub__, Counter.__sub__),
2312 (Counter.__ior__, Counter.__or__),
2313 (Counter.__iand__, Counter.__and__),
2314 ]:
2315 c = p.copy()
2316 c_id = id(c)
2317 regular_result = regular_op(c, q)
2318 inplace_result = inplace_op(c, q)
2319 self.assertEqual(inplace_result, regular_result)
2320 self.assertEqual(id(inplace_result), c_id)
2321
2322 def test_subtract(self):
2323 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