from unittest.case import TestCase from tudelft.utilities.tools.atomic import AtomicBoolean class atomicTest(TestCase): def testSimple(self): a=AtomicBoolean(True) self.assertEqual(True,a.get()) self.assertEqual(False,a.compareAndSet(False,False)) self.assertEqual(False,a.compareAndSet(False,True)) self.assertEqual(True,a.get()) self.assertEqual(True,a.compareAndSet(True,True)) self.assertEqual(True,a.get()) self.assertEqual(True,a.compareAndSet(True,False)) self.assertEqual(False,a.get()) self.assertEqual(True,a.compareAndSet(False,False)) self.assertEqual(False,a.get()) self.assertEqual(True,a.compareAndSet(False,True)) self.assertEqual(True,a.get()) # FIXME it would be nice to stress test the AtomicBoolnan for thread safety. # I think we need to slow down AtomicBoolean processing for that, # and tthat would pollute the AtomicBoolean code...