public void adding_an_item_adds_it_to_the_items()
        {
            var item = PT(32, PostedTimeType.Normal, 5);
            var model = new PostedTimeCollectionModel();

            model.Add(item);
            Assert.Equal(1, model.Items.Count);
            Assert.Equal(item, model.Items[0]);
        }
Exemple #2
0
 /// <summary>
 /// Initialises a new instance of the <see cref="DriverModel"/> class and specifies the
 /// driver's Id.
 /// </summary>
 /// <param name="id">The driver's Id.</param>
 public DriverModel(int id)
 {
     Id = id;
     LapTimes = new LapTimesModel();
     PitTimes = new PostedTimeCollectionModel();
     QuallyTimes = new QuallyTimesModel();
     Status = DriverStatus.InPits;
     Builder = new DriverModelBuilder(this);
 }
 /// <summary>
 /// Initialises a new instance of the <see cref="LapTimesModel"/> class.
 /// </summary>
 public LapTimesModel()
 {
     S1 = new PostedTimeCollectionModel();
     S2 = new PostedTimeCollectionModel();
     S3 = new PostedTimeCollectionModel();
     Subscribe(S3.Items, OnCollectionChanged);
     Laps = new PostedTimeCollectionModel();
     InnerHistory = new ObservableCollection<LapHistoryEntry>();
     History = new ReadOnlyObservableCollection<LapHistoryEntry>(InnerHistory);
 }
        public void adding_an_item_updates_the_current()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();
            var current = PT(35d, PostedTimeType.Normal, 5);

            model.Add(current);
            Assert.Equal(current, model.Current);
            current = PT(65d, PostedTimeType.Normal, 5);
            model.Add(current);
            Assert.Equal(current, model.Current);
            Assert.Equal(2, observer.GetChangeCount(x => x.Current));
        }
        public void adding_an_item_updates_the_maximum_if_it_has_changed()
        {
            PostedTime item;
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

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

            Assert.Equal(5, observer.GetChangeCount(x => x.Maximum));
        }
 private static void assert_has_default_property_values(PostedTimeCollectionModel model)
 {
     Assert.Equal(0, model.Count);
     Assert.Null(model.Current);
     Assert.Null(model.CurrentDelta);
     Assert.Null(model.Maximum);
     Assert.Null(model.Mean);
     Assert.Null(model.Minimum);
     Assert.Equal(0, model.PersonalBestCount);
     Assert.Null(model.Previous);
     Assert.Null(model.Range);
     Assert.Equal(0, model.SessionBestCount);
     Assert.Empty(model.Items);
 }
        public void replacing_an_item_updates_the_range()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(0), model.Range);
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(0), model.Range);
            model.Add(PT(20, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(10), model.Range);

            Assert.Equal(2, observer.GetChangeCount(x => x.Range));
        }
        public void replacing_an_item_updates_the_session_best_count()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.Normal, 1));
            Assert.Equal(0, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);
            model.ReplaceCurrent(PT(15, PostedTimeType.PersonalBest, 1));
            Assert.Equal(0, model.SessionBestCount);

            Assert.Equal(4, observer.GetChangeCount(x => x.SessionBestCount));
        }
        public void bug()
        {
            var model = new PostedTimeCollectionModel();
            var time = PT(23.3, PostedTimeType.SessionBest, 0);

            model.Add(time);

            model.ReplaceCurrent(PT(23.3, PostedTimeType.PersonalBest, 0));

            Assert.NotEqual(time, model.Minimum);
        }
        public void adding_an_item_updates_the_session_best_count()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(15, PostedTimeType.SessionBest, 1));
            Assert.Equal(1, model.SessionBestCount);

            Assert.True(observer.HasChanged(x => x.SessionBestCount));
        }
 public static void NotEmpty(this Assertions assert, PostedTimeCollectionModel model)
 {
     assert.NotEmpty(model.Items);
 }
        public void replacing_an_item_updates_the_mean()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(1, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(10), model.Mean);

            Assert.True(observer.HasChanged(x => x.Mean));
        }
        public void replace_current_throws_if_replacement_is_null()
        {
            var model = new PostedTimeCollectionModel();

            Assert.Throws<ArgumentNullException>(() => model.ReplaceCurrent(null));
        }
        public void replacing_an_item_does_not_update_the_count()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(1, PostedTimeType.Normal, 1));
            observer.ClearChanges();

            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(1, model.Count);

            Assert.False(observer.HasChanged(x => x.Count));
        }
        public void replace_current_throws_if_current_has_not_been_set()
        {
            var model = new PostedTimeCollectionModel();

            Assert.Throws<InvalidOperationException>(() => model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1)));
        }
        public void can_reset()
        {
            var model = new PostedTimeCollectionModel();

            model.Add(PT(65d, PostedTimeType.PersonalBest, 5));
            model.Reset();
            assert_has_default_property_values(model);
        }
        public void can_create()
        {
            var model = new PostedTimeCollectionModel();

            assert_has_default_property_values(model);
        }
        public void adding_an_item_updates_the_mean()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(1d, PostedTimeType.Normal, 1));
            Assert.Equal(TS(1d), model.Mean);
            model.Add(PT(1d, PostedTimeType.Normal, 1));
            Assert.Equal(TS(1d), model.Mean);
            model.Add(PT(4d, PostedTimeType.Normal, 1));
            Assert.Equal(TS(2d), model.Mean);

            Assert.Equal(2, observer.GetChangeCount(x => x.Mean));
        }
        public void replacing_an_item_updates_the_minimum_if_it_has_changed()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();
            var replacement = PT(20, PostedTimeType.Normal, 1);

            model.Add(PT(30, PostedTimeType.Normal, 1));
            observer.ClearChanges();

            model.ReplaceCurrent(replacement);
            Assert.Equal(replacement, model.Minimum);
            Assert.True(observer.HasChanged(x => x.Minimum));

            model.Add(PT(10, PostedTimeType.Normal, 1));
            observer.ClearChanges();

            replacement = PT(5, PostedTimeType.Normal, 1);
            model.ReplaceCurrent(replacement);
            Assert.Equal(replacement, model.Minimum);
            Assert.True(observer.HasChanged(x => x.Minimum));
        }
        public void replacing_an_item_updates_the_items()
        {
            var model = new PostedTimeCollectionModel();
            var replacement = PT(50, PostedTimeType.Normal, 1);

            model.Add(PT(1, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(replacement);
            Assert.Equal(replacement, model.Items[0]);
        }
        public void add_throws_if_item_is_null()
        {
            var model = new PostedTimeCollectionModel();

            Assert.Throws<ArgumentNullException>(() => model.Add(null));
        }