Example #1
0
        public void Exchange()
        {
            AtomicIntegerArray ai = new AtomicIntegerArray(DEFAULT_COLLECTION_SIZE);

            for (int i = 0; i < DEFAULT_COLLECTION_SIZE; ++i)
            {
                ai[i] = 1;
                Assert.AreEqual(1, ai.Exchange(i, 0));
                Assert.AreEqual(0, ai.Exchange(i, -10));
                Assert.AreEqual(-10, ai.Exchange(i, 1));
            }
        }
Example #2
0
        public void IndexerChokesOnOutOfRangeIndex()
        {
            AtomicIntegerArray ai = new AtomicIntegerArray(DEFAULT_COLLECTION_SIZE);
            int a = 0;

            TestHelper.AssertException <IndexOutOfRangeException>(
                delegate { a = ai[DEFAULT_COLLECTION_SIZE]; });
            TestHelper.AssertException <IndexOutOfRangeException>(
                delegate { a = ai[-1]; });
            TestHelper.AssertException <IndexOutOfRangeException>(
                delegate { ai.Exchange(DEFAULT_COLLECTION_SIZE, 0); });
            TestHelper.AssertException <IndexOutOfRangeException>(
                delegate { ai.Exchange(-1, 0); });
            Assert.AreEqual(0, a);
        }