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));
        }
        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_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 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_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_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 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 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));
        }