public void FilterTestFilter0min()
        {
            QuantityFilter q = new QuantityFilter(100, 0);
            List<NewsItem> gottenNews =
                q.Filter(Archivist, Archivist.GetNews(new NewsQuery()));

            Assert.AreEqual(0, gottenNews.Count());
        }
        public void FilterTestReadingspeedIsZero()
        {
            Archivist.SetReadingSpeed(0);
            QuantityFilter q = new QuantityFilter(10, 20, 5);
            List<NewsItem> gottenNews =
                q.Filter(Archivist, Archivist.GetNews(new NewsQuery()));

            int expected = 0;
            int actual = gottenNews.Count;

            Assert.AreEqual(expected, actual);
        }
        public void FilterTestFilterMax2MinEach4MinMax2ItemsMax()
        {
            QuantityFilter q = new QuantityFilter(2, 4, 2);
            List<NewsItem> gottenNews =
                q.Filter(Archivist, Archivist.GetNews(new NewsQuery()));

            // Assert that a maximum of two news items were fetched.
            Assert.IsTrue(gottenNews.Count <= 2,
                "More than two NewsItems were fetched: " + gottenNews.Count);

            // Assert that each news item can be read in 5 or less minutes.
            int totalReadTime = 0;
            for (int i = 0; i < gottenNews.Count; i++)
            {
                int readTime = (int) ((double) gottenNews[i].WordCount /
                    (double) Archivist.GetReadingSpeed());
                totalReadTime += readTime;
                Assert.IsTrue(readTime <= 5,
                    "NewsItem at index " + i + " takes " + readTime + " minutes to read.");
            }

            Assert.IsTrue(totalReadTime <= 4,
                "The news did not take 4 or less minutes to read but " +
                totalReadTime + " minutes.");
        }
        public void FilterTestFilterMax2MinEach()
        {
            QuantityFilter q = new QuantityFilter(100, maxItemTime: 2);
            List<NewsItem> gottenNews =
                q.Filter(Archivist, Archivist.GetNews(new NewsQuery()));

            // Assert that each news item can be read in 5 or less minutes.
            for (int i = 0; i < gottenNews.Count; i++)
            {
                int readTime = (int) ((double) gottenNews[i].WordCount /
                    (double) Archivist.GetReadingSpeed());
                Assert.IsTrue(readTime <= 5,
                    "NewsItem at index " + i + " takes " + readTime + " minutes to read.");
            }
        }
        public void FilterTestFilter50minNotFull()
        {
            QuantityFilter q = new QuantityFilter(100, 50);
            List<NewsItem> gottenNews =
                q.Filter(Archivist, Archivist.GetNews(new NewsQuery()));

            // Count the time it will take to read the gotten news.
            int readTime = 0;
            foreach (NewsItem n in gottenNews)
            {
                readTime += (int) ((double) n.WordCount /
                    (double) Archivist.GetReadingSpeed());
            }

            Assert.IsTrue(readTime <= 25 && readTime >= 5,
                "The news " + readTime + " minutes to read.");
        }
Beispiel #6
0
        /// <summary>
        /// Curates undread news from the given <c>Archivist</c> instance based 
        /// on a maximum reading time, a maximum individual item reading time 
        /// and a limit.
        /// </summary>
        /// <param name="archivist">
        /// The <c>Archivist</c> instance giving access to the news that 
        /// should be curated.
        /// </param>
        /// <param name="limit">
        /// The maximum number of news to return.
        /// </param>
        /// <param name="maxTime">
        /// The maximum reading time for the curated news.
        /// </param>
        /// <param name="maxItemTime">
        /// The maximum reading time per news item.
        /// </param>
        /// <returns>
        /// A list of unread, curated <c>NewsItem</c>s received from the 
        /// <c>Archivist</c> instance.
        /// </returns>
        public static List<NewsItem> GetCuratedNews(Archivist archivist,
            int limit, int maxTime = -1, int maxItemTime = - 1)
        {
            // Get cached data and update if null.
            List<NewsItem> curatedNews = CachedNews;

            if (curatedNews == null)
            {
                // Update needed.

                NewsQuery query = new NewsQuery();
                // Only fetch unread news.
                query.Read = ReadStatus.Unread;
                query.OrderDateDesc = true;
                query.Limit = 100;
                curatedNews = archivist.GetNews(query);

                // If no news was found then there's no need to filter them.
                if (curatedNews.Count == 0)
                {
                    return curatedNews;
                }

                // Filter for interesting news.
                InterestFilter interestFilter = new InterestFilter();
                curatedNews = interestFilter.Filter(archivist, curatedNews);

                // Filter redundancy.
                RedundancyFilter redundancyFilter = new RedundancyFilter();
                curatedNews = redundancyFilter.Filter(archivist, curatedNews);

                // Update cache.
                CachedNews = curatedNews;
            }

            // Filter quantity.
            QuantityFilter quantityFilter = new QuantityFilter(limit,
                maxTime, maxItemTime);
            curatedNews = quantityFilter.Filter(archivist, curatedNews);

            // Return curated list.
            return curatedNews;
        }