示例#1
0
        public void Setting_the_value_of_an_AtomicDouble_results_in_the_value_set()
        {
            AtomicDouble ad = new AtomicDouble();

            ad.Value = 10.02;

            Assert.Equal(10.02, ad.Value);
        }
示例#2
0
        public void Default_value_is_correctly_assigned_when_specified_in_constructor(double expectedValue)
        {
            var atomicDouble = new AtomicDouble(expectedValue);

            var value = atomicDouble.Get();

            value.Should().Be(expectedValue);
        }
示例#3
0
        public void Default_value_is_zero()
        {
            var atomicDouble = new AtomicDouble();

            var value = atomicDouble.Get();

            value.Should().Be(0);
        }
示例#4
0
        public void Get_and_set_returns_the_original_value(double originalValue)
        {
            var atomicDouble = new AtomicDouble(originalValue);

            var value = atomicDouble.GetAndSet(1000);

            value.Should().Be(originalValue);
        }
示例#5
0
        public void Adding_one_to_an_empty_AtomicDouble_results_in_the_value_of_one()
        {
            AtomicDouble ad = new AtomicDouble();

            ad.Add(1.0);

            Assert.Equal(1.0, ad.Value);
        }
示例#6
0
        public void Get_and_set_updates_the_value_as_specified(double newValue)
        {
            var atomicDouble = new AtomicDouble();

            atomicDouble.GetAndSet(newValue);

            var value = atomicDouble.Get();

            value.Should().Be(newValue);
        }
示例#7
0
        public void Incrementing_the_value_by_the_specified_amount_increments_the_value_correctly(double originvalValue, double amount, double expectedValue)
        {
            var atomicDouble = new AtomicDouble(originvalValue);

            atomicDouble.Increment(amount);

            var value = atomicDouble.Get();

            value.Should().BeApproximately(expectedValue, 0.1);
        }
示例#8
0
        public void Incrementing_the_value_increments_the_value(double originvalValue, double expectedValue)
        {
            var atomicDouble = new AtomicDouble(originvalValue);

            atomicDouble.Increment();

            var value = atomicDouble.Get();

            value.Should().Be(expectedValue);
        }
示例#9
0
        public void Setting_the_value_updates_the_value_as_expected(double newValue)
        {
            var atomicDouble = new AtomicDouble();

            atomicDouble.Set(newValue);

            var value = atomicDouble.Get();

            value.Should().Be(newValue);
        }
示例#10
0
        public void Compare_and_set_does_not_update_the_value_when_original_value_is_incorrect(double newValue)
        {
            var atomicDouble = new AtomicDouble();

            atomicDouble.CompareAndSet(newValue, 100);

            var value = atomicDouble.Get();

            value.Should().Be(0);
        }
示例#11
0
        public void TestAtomicDouble()
        {
            var d = AtomicDouble.From(0.1);

            Assert.Equal(0.1, d.Value);
            Assert.True(d.CompareExchange(0.2, 0.1));
            Assert.Equal(0.2, d.Value);
            Assert.True(d.Exchange(0.3));
            Assert.Equal(0.3, d.Value);
            Assert.Equal(0.3, d);
        }
示例#12
0
        /// <summary>
        /// Collects the average value.
        /// </summary>
        /// <returns></returns>
        public void Collect()
        {
            lock (this)
            {
                var count     = this.Count.Value;
                var aggregate = this.Aggregate.Value;
                if (count == 0)
                {
                    return;
                }

                var old     = this.Value;
                var current = aggregate / count;

                this.Count     = 0;
                this.Aggregate = 0;

                this.Value = (current + old) / 2;
            }
        }
示例#13
0
        public void AtomicityDouble()
        {
            AtomicTypeBase <double> atomic = new AtomicDouble(0);

            var expected = BitConverter.DoubleToInt64Bits(0);

            expected += 900;

            void SumTask()
            {
                for (var x = 0; x < 300; x++)
                {
                    atomic++;
                }
            }

            Task.WaitAll(
                Task.Run(SumTask),
                Task.Run(SumTask),
                Task.Run(SumTask));

            Assert.That(atomic.Value, Is.EqualTo(BitConverter.Int64BitsToDouble(expected)));
        }
示例#14
0
        public void AtomicityDouble()
        {
            AtomicTypeBase <double> atomic = new AtomicDouble();

            void SumTask()
            {
                for (var x = 0; x < 300; x++)
                {
                    atomic++;
                }
            }

            Task.WaitAll(
                Task.Factory.StartNew(SumTask),
                Task.Factory.StartNew(SumTask),
                Task.Factory.StartNew(SumTask));

            if (atomic.Value < 900)
            {
                Assert.Ignore("We need to fix this");
            }

            Assert.That(atomic.Value, Is.EqualTo(900));
        }
示例#15
0
        public void AtomicDouble_has_the_initial_value_of_zero()
        {
            AtomicDouble ad = new AtomicDouble();

            Assert.Equal(0.0, ad.Value);
        }
示例#16
0
        public void TestAtomicDoubleDefaultCtor()
        {
            var ad = new AtomicDouble();

            Assert.Equal(0.0, ad.Value);
        }
示例#17
0
 public GaugeMetric(LabelValues labels)
 {
     _labels = labels;
     _value  = new AtomicDouble(0);
 }
示例#18
0
 public override void Setup()
 {
     _num = new AtomicDouble(0);
 }