public void AtomicIntegerArray_Load_Acquire_Should_Success(MemoryOrder order)
        {
            var atomicIntegerArray = new AtomicIntegerArray(new int[3], order);

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                Assert.Equal(0, atomicIntegerArray.Load(i, MemoryOrder.Acquire));
                atomicIntegerArray.Store(i, i, MemoryOrder.Release);
            }

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                Assert.Equal(i, atomicIntegerArray.Load(i, MemoryOrder.Acquire));
            }
        }
        public void AtomicIntegerArray_Indexer_MemoryOrder_Should_Success(MemoryOrder order)
        {
            var atomicIntegerArray = new AtomicIntegerArray(new int[3], order);

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                Assert.Equal(0, atomicIntegerArray[i]);
                atomicIntegerArray[i] = i;
            }

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                Assert.Equal(i, atomicIntegerArray[i]);
            }
        }
        public void AtomicIntegerArray_Should_Copy_Source(MemoryOrder memoryOrder)
        {
            var item1 = 1;
            var item2 = 2;
            var source = new [] { item1, 0, item2, 0};
            var ar = new AtomicIntegerArray(source, memoryOrder);
            
            Assert.True(source.SequenceEqual(ar));
            Assert.Equal(0, source[1]);
            Assert.Equal(0, ar[1]);
            
            source[1] = -1;

            Assert.False(source.SequenceEqual(ar));

            Assert.Equal(0, source[3]);
            Assert.Equal(0, ar[3]);
            Assert.Equal(0, source[3]);
            Assert.Equal(0, ar[3]);

            source[3] = -1;

            Assert.Equal(-1, source[3]);
            Assert.Equal(0, ar[3]);
            Assert.False(source.SequenceEqual(ar));
        }
        public void AtomicIntegerArray_Items_With_Length_Ctor_Should_Be_Null(int length, MemoryOrder memoryOrder)
        {
            var ar = new AtomicIntegerArray(length, memoryOrder);
            foreach (var o in ar)
            {
                Assert.Equal(0, o);
            }

            for (int i = 0; i < ar.Count; i++)
            {
                Assert.Equal(0, ar[i]);
            }
        }
 public void AtomicIntegerArray_Ctor_Should_Track_Length(MemoryOrder order)
 {
     Assert.Throws<ArgumentException>(() => new AtomicIntegerArray(-1, order));
     GC.KeepAlive(new AtomicIntegerArray(0, order));
     GC.KeepAlive(new AtomicIntegerArray(1, order));
 }
 public void AtomicIntegerArray_With_Null_Source_Should_Fail(MemoryOrder memoryOrder)
 {
     Assert.Throws<ArgumentNullException>(() => new AtomicIntegerArray(null, memoryOrder));
 }
 public void AtomicInteger_IsLockFree_Should_Success(int initialValue, MemoryOrder order, bool isLockFree)
 {
     var atomicInteger = new AtomicInteger(initialValue, order);
     Assert.Equal(atomicInteger.IsLockFree, isLockFree);
 }
 public void AtomicReferenceArray_Ctor_Should_Track_Length(MemoryOrder order)
 {
     Assert.Throws<ArgumentException>(() => new AtomicReferenceArray<object>(-1, order));
     GC.KeepAlive(new AtomicReferenceArray<object>(0, order));
     GC.KeepAlive(new AtomicReferenceArray<object>(1, order));
 }
 public void AtomicLong_Store_Should_Success(long initialValue, long storeValue, MemoryOrder order)
 {
     var atomicLong = new AtomicLong(initialValue, MemoryOrder.Relaxed);
     atomicLong.Store(storeValue, order);
     Assert.Equal(storeValue, atomicLong.Value);
 }
 public void AtomicIntegerArray_IsLockFree_Should_Success(int initialValue, MemoryOrder order, bool isLockFree)
 {
     var atomicIntegerArray = new AtomicIntegerArray(new[] { initialValue }, order);
     Assert.Equal(atomicIntegerArray.IsLockFree, isLockFree);
 }
        public void AtomicIntegerArray_Decrement_Should_Success(MemoryOrder memoryOrder)
        {
            var ar = new AtomicIntegerArray(10, memoryOrder);
            foreach (var o in ar)
            {
                Assert.Equal(0, o);
            }

            for (int i = 0; i < ar.Count; i++)
            {
                Assert.Equal(0, ar[i]);
            }

            for (int i = 0; i < ar.Count; i++)
            {
                ar[i] = i;
                ar.DecrementAt(i);
            }

            Assert.Equal(Enumerable.Range(-1, 10), ar);
        }
 public void AtomicIntegerArray_Store_Should_Success(int initialValue, int storeValue, MemoryOrder order)
 {
     var atomicIntegerArray = new AtomicIntegerArray(new int[] {initialValue}, MemoryOrder.Relaxed);
     atomicIntegerArray.Store(0, storeValue, order);
     Assert.Equal(storeValue, atomicIntegerArray[0]);
 }
        public void AtomicReferenceArray_Should_Copy_Source(MemoryOrder memoryOrder)
        {
            var item1 = new object();
            var item2 = new object();
            var source = new object[] { item1, null, item2, null};
            var ar = new AtomicReferenceArray<object>(source, memoryOrder);
            
            Assert.True(source.SequenceEqual(ar));
            Assert.Null(source[1]);
            Assert.Null(ar[1]);
            
            source[1] = new object();

            Assert.False(source.SequenceEqual(ar));

            Assert.Null(source[3]);
            Assert.Null(ar[3]);
            Assert.Null(source[3]);
            Assert.Null(ar[3]);

            source[3] = new object();

            Assert.NotNull(source[3]);
            Assert.Null(ar[3]);
            Assert.False(source.SequenceEqual(ar));
        }
        public void AtomicReferenceArray_Items_With_Length_Ctor_Should_Be_Null(int length, MemoryOrder memoryOrder)
        {
            var ar = new AtomicReferenceArray<object>(length, memoryOrder);
            foreach (var o in ar)
            {
                Assert.Null(o);
            }

            for (int i = 0; i < ar.Count; i++)
            {
                Assert.Null(ar[i]);
            }
        }
 public void AtomicBoolean_Store_Should_Success(bool initialValue, bool storeValue, MemoryOrder order)
 {
     var atomicBoolean = new AtomicBoolean(initialValue, order);
     atomicBoolean.Store(storeValue, order);
     Assert.Equal(storeValue, atomicBoolean.Value);
 }
        public void AtomicIntegerArray_Store_MemoryOrder_Should_Success(MemoryOrder order)
        {
            var atomicIntegerArray = new AtomicIntegerArray(new int[3], order);

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                atomicIntegerArray.Store(i, i, order);
            }

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                Assert.Equal(i, atomicIntegerArray.Load(i, order));
            }

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                atomicIntegerArray.Store(i, i, order);
            }

            for (int i = 0; i < atomicIntegerArray.Count; i++)
            {
                Assert.Equal(i, atomicIntegerArray.Load(i, order));
            }
        }
 public void AtomicBoolean_IsLockFree_Should_Success(bool initialValue, MemoryOrder order, bool isLockFree)
 {
     var atomicBoolean = new AtomicBoolean(initialValue, order);
     Assert.Equal(atomicBoolean.IsLockFree, isLockFree);
 }
 public void AtomicInteger_Store_Should_Success(int initialValue, int storeValue, MemoryOrder order)
 {
     var atomicInteger = new AtomicInteger(initialValue, order);
     atomicInteger.Store(storeValue, order);
     Assert.Equal(storeValue, atomicInteger.Value);
 }
 public void AtomicLong_IsLockFree_Should_Success(long initialValue, MemoryOrder order, bool isLockFree)
 {
     var atomicLong = new AtomicLong(initialValue, order);
     Assert.Equal(atomicLong.IsLockFree, isLockFree);
 }
 public void AtomicReferenceArray_With_Null_Source_Should_Fail(MemoryOrder memoryOrder)
 {
     Assert.Throws<ArgumentNullException>(() => new AtomicReferenceArray<object>(null, memoryOrder));
 }