def testMultiThreadedCounterUpdates(self): n = 250000 # perform this many increment/decrement/get operations per thread c = Counter() value = 1000000 c.set(value) self.assertEqual(value, c.get()) threads = [] for i in range(8): ops = ['+' for x in range(n)] + ['-' for x in range(n) ] + ['R' for x in range(n)] random.shuffle(ops) threads.append( threading.Thread(target=self._updateThread, args=(c, ops))) for t in threads: t.start() for t in threads: t.join() self.assertEqual(value, c.get())
def testDecrementValue(self): c = Counter() c.set(1) c.decrement() self.assertEqual(0, c.get())
def testIncrementValue(self): c = Counter() c.set(1) c.increment() self.assertEqual(2, c.get())
def testSetValue(self): c = Counter() c.set(1) self.assertEqual(1, c.get())
def testDecrementNoneValue(self): c = Counter() c.decrement() self.assertEqual(None, c.get())
def testInitSetsValueToNone(self): c = Counter() self.assertEqual(None, c.get())