public void adding_an_item_adds_it_to_the_items()
        {
            var model = new DoubleCollectionModel();

            model.Add(1d);
            Assert.Equal(1, model.Items.Count);
            Assert.Equal(1d, model.Items[0]);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initialises a new instance of the <see cref="WeatherModel"/> class.
 /// </summary>
 public WeatherModel()
 {
     AirTemperature = new DoubleCollectionModel();
     TrackTemperature = new DoubleCollectionModel();
     Humidity = new DoubleCollectionModel();
     WindSpeed = new DoubleCollectionModel();
     Pressure = new DoubleCollectionModel();
     WindAngle = new DoubleCollectionModel();
     Builder = new WeatherModelBuilder(this);
 }
        public void adding_an_item_updates_the_current()
        {
            var model = new DoubleCollectionModel();
            var observer = model.CreateObserver();

            model.Add(1d);
            Assert.Equal(1d, model.Current);
            model.Add(2d);
            Assert.Equal(2d, model.Current);

            Assert.Equal(2, observer.GetChangeCount(x => x.Current));
        }
        public void adding_an_item_updates_the_current_delta_type_if_it_has_changed()
        {
            var model = new DoubleCollectionModel();
            var observer = model.CreateObserver();

            model.Add(1d);
            Assert.Equal(DeltaType.None, model.CurrentDeltaType);
            model.Add(2d);
            Assert.Equal(DeltaType.Increase, model.CurrentDeltaType);
            model.Add(1d);
            Assert.Equal(DeltaType.Decrease, model.CurrentDeltaType);
            model.Add(1d);
            Assert.Equal(DeltaType.None, model.CurrentDeltaType);

            Assert.Equal(3, observer.GetChangeCount(x => x.CurrentDeltaType));
        }
        public void adding_an_item_updates_the_maximum_if_it_has_changed()
        {
            var model = new DoubleCollectionModel();
            var observer = model.CreateObserver();

            for(double item = -5d; item < 5d; ++item)
            {
                model.Add(item);
                Assert.Equal(item, model.Maximum);
                model.Add(item - 1);
                Assert.Equal(item, model.Maximum);
            }

            Assert.Equal(10, observer.GetChangeCount(x => x.Maximum));
        }
 private static void assert_has_default_property_values(DoubleCollectionModel model)
 {
     Assert.Equal(0, model.Count);
     Assert.Null(model.Current);
     Assert.Equal(DeltaType.None, model.CurrentDeltaType);
     Assert.Null(model.Maximum);
     Assert.Null(model.Mean);
     Assert.Equal(DeltaType.None, model.MeanDeltaType);
     Assert.Null(model.Minimum);
     Assert.Null(model.Range);
     Assert.Null(model.StandardDeviation);
     Assert.Empty(model.Items);
 }
        public void reset_raises_begin_and_end_events()
        {
            var resetBeginRaised = false;
            var resetCompleteRaised = false;
            var model = new DoubleCollectionModel();

            model.ResetBegin += delegate
            {
                Assert.False(resetBeginRaised);
                Assert.False(resetCompleteRaised);
                resetBeginRaised = true;
            };
            model.ResetComplete += delegate
            {
                Assert.True(resetBeginRaised);
                Assert.False(resetCompleteRaised);
                resetCompleteRaised = true;
            };
            model.Reset();
            Assert.True(resetBeginRaised && resetCompleteRaised);
        }
        public void can_reset()
        {
            var model = new DoubleCollectionModel();

            model.Add(1d);
            model.Add(2d);
            model.Reset();
            assert_has_default_property_values(model);
        }
        public void can_create()
        {
            var model = new DoubleCollectionModel();

            assert_has_default_property_values(model);
        }
        public void add_throws_if_item_a_not_a_number()
        {
            var model = new DoubleCollectionModel();

            Assert.Throws<ArgumentOutOfRangeException>(() => model.Add(Double.NaN));
        }
        public void adding_an_item_updates_the_standard_deviation()
        {
            var model = new DoubleCollectionModel();
            var observer = model.CreateObserver();

            for(double item = 0d; item < 10d; ++item)
            {
                model.Add(item);
            }

            Assert.Equal(2.8722813232690143, model.StandardDeviation);
            Assert.Equal(10, observer.GetChangeCount(x => x.StandardDeviation));
        }
        public void adding_an_item_updates_the_range()
        {
            var model = new DoubleCollectionModel();
            var observer = model.CreateObserver();

            model.Add(1d);
            Assert.Equal(0d, model.Range);
            model.Add(10d);
            Assert.Equal(9d, model.Range);

            Assert.Equal(2, observer.GetChangeCount(x => x.Range));

            model = new DoubleCollectionModel();
            observer = model.CreateObserver();

            model.Add(-20);
            Assert.Equal(0d, model.Range);
            model.Add(-10);
            Assert.Equal(10d, model.Range);
            model.Add(0d);
            Assert.Equal(20d, model.Range);
            model.Add(10d);
            Assert.Equal(30d, model.Range);

            Assert.Equal(4, observer.GetChangeCount(x => x.Range));
        }