1 | from unittest.case import TestCase
|
---|
2 | from tudelft.utilities.tools.atomic import AtomicBoolean
|
---|
3 |
|
---|
4 | class atomicTest(TestCase):
|
---|
5 | def testSimple(self):
|
---|
6 | a=AtomicBoolean(True)
|
---|
7 | self.assertEqual(True,a.get())
|
---|
8 | self.assertEqual(False,a.compareAndSet(False,False))
|
---|
9 | self.assertEqual(False,a.compareAndSet(False,True))
|
---|
10 | self.assertEqual(True,a.get())
|
---|
11 | self.assertEqual(True,a.compareAndSet(True,True))
|
---|
12 | self.assertEqual(True,a.get())
|
---|
13 | self.assertEqual(True,a.compareAndSet(True,False))
|
---|
14 | self.assertEqual(False,a.get())
|
---|
15 | self.assertEqual(True,a.compareAndSet(False,False))
|
---|
16 | self.assertEqual(False,a.get())
|
---|
17 | self.assertEqual(True,a.compareAndSet(False,True))
|
---|
18 | self.assertEqual(True,a.get())
|
---|
19 |
|
---|
20 | # FIXME it would be nice to stress test the AtomicBoolnan for thread safety.
|
---|
21 | # I think we need to slow down AtomicBoolean processing for that,
|
---|
22 | # and tthat would pollute the AtomicBoolean code... |
---|