public void CanDecToValue(double initial, double value, double expected) { var tslong = new ThreadSafeDouble(initial); tslong.DecTo(value); Assert.Equal(expected, tslong.Value); }
public void ThreadSafeDouble_ValueSet() { var tsdouble = new ThreadSafeDouble(); tsdouble.Value = 3.14; Assert.Equal(3.14, tsdouble.Value); }
public void CanAddValue(double initial, double added, double expected) { var tsdouble = new ThreadSafeDouble(initial); tsdouble.Add(added); Assert.Equal(expected, tsdouble.Value); }
public void CanSetValue(double value) { var tsdouble = new ThreadSafeDouble(0); tsdouble.Value = value; Assert.Equal(value, tsdouble.Value); }
public void ThreadSafeDouble_Add() { var tsdouble = new ThreadSafeDouble(3.10); tsdouble.Add(0.50); tsdouble.Add(2.00); Assert.Equal(5.6, tsdouble.Value); }
public void ThreadSafeDouble_Constructors() { var tsdouble = new ThreadSafeDouble(0.0); Assert.Equal(0.0, tsdouble.Value); tsdouble = new ThreadSafeDouble(1.42); Assert.Equal(1.42, tsdouble.Value); }
public void ThreadSafeDouble_Overrides() { var tsdouble = new ThreadSafeDouble(9.15); var equaltsdouble = new ThreadSafeDouble(9.15); var notequaltsdouble = new ThreadSafeDouble(10.11); Assert.Equal("9.15", tsdouble.ToString()); Assert.True(tsdouble.Equals(equaltsdouble)); Assert.False(tsdouble.Equals(notequaltsdouble)); Assert.False(tsdouble.Equals(null)); Assert.True(tsdouble.Equals(9.15)); Assert.False(tsdouble.Equals(10.11)); Assert.Equal(9.15.GetHashCode(), tsdouble.GetHashCode()); }
public void ThreadSafeDouble_Overrides() { var tsdouble = new ThreadSafeDouble(9.15); var equaltsdouble = new ThreadSafeDouble(9.15); var notequaltsdouble = new ThreadSafeDouble(10.11); Assert.AreEqual(9.15.ToString(CultureInfo.CurrentCulture), tsdouble.ToString()); Assert.IsTrue(tsdouble.Equals(equaltsdouble)); Assert.IsFalse(tsdouble.Equals(notequaltsdouble)); Assert.IsFalse(tsdouble.Equals(null)); Assert.IsTrue(tsdouble.Equals(9.15)); Assert.IsFalse(tsdouble.Equals(10.11)); Assert.AreEqual((9.15).GetHashCode(), tsdouble.GetHashCode()); }
public async Task DecToMultiThreads(int threads, int observations) { var tslong = new ThreadSafeDouble(0); var testData = new IEnumerable <double> [threads]; var min = double.MaxValue; for (var i = 0; i < threads; i++) { var data = GenerateTestData(observations); min = Math.Min(data.min, min); testData[i] = data.items; } await Task.WhenAll(testData.Select(async d => { foreach (double item in d) { await Task.Yield(); tslong.DecTo(item); } }).ToArray()); Assert.Equal(min, tslong.Value); }
public async Task AddMultiThreads(int threads, int observations) { var tslong = new ThreadSafeDouble(0); var testData = new IEnumerable <double> [threads]; var sum = 0D; for (var i = 0; i < threads; i++) { var data = GenerateTestData(observations); sum += data.sum; testData[i] = data.items; } await Task.WhenAll(testData.Select(async d => { foreach (double item in d) { await Task.Yield(); tslong.Add(item); } }).ToArray()); Assert.Equal(Math.Round(sum, 5), Math.Round(tslong.Value, 5)); }
public void AddThrowsOnNaN(double initial, double added) { var tsdouble = new ThreadSafeDouble(initial); Assert.Throws <InvalidOperationException>(() => tsdouble.Add(added)); }
public void IsNaN(double value, bool result) { var isNaN = ThreadSafeDouble.IsNaN(value); Assert.Equal(result, isNaN); }
public void CanInitConstructor(double value) { var tsdouble = new ThreadSafeDouble(value); Assert.Equal(value, tsdouble.Value); }
public void IncToThrowsOnNaN(double initial, double value) { var tsdouble = new ThreadSafeDouble(initial); Assert.Throws <InvalidOperationException>(() => tsdouble.IncTo(value)); }