public void AtomicObjectCompareAndSetReturnsFalseIfComparisonDoesNotMatch() { var o = new AtomicObject <string>("bar"); bool result = o.CompareAndSet("foo", "bar"); Assert.IsFalse(result); Assert.AreEqual("bar", o.Value); Assert.AreEqual("bar", (string)o); }
public void AtomicObjectCompareAndSetReturnsExpectedValuesForFailedMatchesMultiThreaded() { const int expected = 1000; var o = new AtomicObject <string>("foo"); var values = new ConcurrentCountedSet <bool>(); System.Threading.Tasks.Parallel.For(0, 1000, i => values.Add(o.CompareAndSet(i % 2 == 0 ? "bar" : "foo", "bar"))); Assert.AreEqual(expected, values[true] + values[false]); }
public void AtomicObjectCompareAndSetReturnsExpectedValuesForFailedMatches() { const int expected = 1000; var o = new AtomicObject <string>("foo"); var values = new ConcurrentCountedSet <bool>(); for (int i = 0; i < 1000; i++) { values.Add(o.CompareAndSet(i % 2 == 0 ? "bar" : "foo", "bar")); } Assert.AreEqual(expected, values[true] + values[false]); }