/// <summary> /// The main test method. /// </summary> public static void Test() { string db = "redundancy_perf.sdf"; // Check if the file exists. bool dbExists = File.Exists(db); // Set up database. SqlCeArchivist archivist = new SqlCeArchivist(db); archivist.Open(); // Seed only if the db did not exist. if (!dbExists) { // Seed database. Change the dataDir to the correct one. string dataDir = @"C:\Users\Andreas Petersen\Documents\GitHub\NyhedsfilterP2\System\NewsTrainer\data"; DBSeeder.SeedDatabaseWithNews(archivist, dataDir, 100); // Seed the database with redundant news. Change the dataDir to the correct one. dataDir = @"C:\Users\Andreas Petersen\Documents\GitHub\NyhedsfilterP2\System\NewsFilter\TestProject\redundancy_perf_test"; DBSeeder.SeedDatabaseWithNews(archivist, dataDir, 100); Console.WriteLine(); } // Get the redundant news set. List<NewsItem> redundantNews = archivist.GetNews(new NewsQuery() { CategoryId = archivist.GetCategories(). Find(n => n.Name.Equals("redundant")).Id }); // Get some news not in the redundant set. They themselves might // include some redundant news, but shouldn't be so in relation // to the redundant news set. List<NewsItem> nonRedundantNews = archivist.GetNews(new NewsQuery() { Limit = 200 }); int nonRedundantNewsCount = 100 - redundantNews.Count; // Find news not in the redundant news. nonRedundantNews = nonRedundantNews.FindAll(n => !redundantNews.Contains(n)); nonRedundantNews.RemoveRange( nonRedundantNewsCount - 1, nonRedundantNews.Count - nonRedundantNewsCount); // Assemble all the news. List<NewsItem> allNews = new List<NewsItem>(); foreach (NewsItem n in redundantNews) { allNews.Add(n); } foreach (NewsItem n in nonRedundantNews) { allNews.Add(n); } // Set all the news as unread. foreach (NewsItem n in allNews) { archivist.SetNewsReadStatus(n, false); } // Each list item contains a set of redundant news items. List<List<int>> redundantNewsIds = new List<List<int>>(); redundantNewsIds.Add(new List<int>() { redundantNews.Find(n => n.Title.Equals("1")).Id, redundantNews.Find(n => n.Title.Equals("2")).Id }); redundantNewsIds.Add(new List<int>() { redundantNews.Find(n => n.Title.Equals("3")).Id, redundantNews.Find(n => n.Title.Equals("4")).Id }); redundantNewsIds.Add(new List<int>() { redundantNews.Find(n => n.Title.Equals("5")).Id, redundantNews.Find(n => n.Title.Equals("6")).Id }); redundantNewsIds.Add(new List<int>() { redundantNews.Find(n => n.Title.Equals("7")).Id, redundantNews.Find(n => n.Title.Equals("8")).Id, redundantNews.Find(n => n.Title.Equals("9")).Id }); redundantNewsIds.Add(new List<int>() { redundantNews.Find(n => n.Title.Equals("10")).Id, redundantNews.Find(n => n.Title.Equals("11")).Id }); redundantNewsIds.Add(new List<int>() { redundantNews.Find(n => n.Title.Equals("12")).Id, redundantNews.Find(n => n.Title.Equals("13")).Id }); // Filter the news. RedundancyFilter filter = new RedundancyFilter(); List<NewsItem> result = filter.Filter(archivist, allNews); // Check that the result filters redundant news. int correctCount = 0; int falsePositiveCount = 0; foreach(List<int> set in redundantNewsIds) { // Count number of news that went through the filter. int newsCount = 0; foreach (int id in set) { if (result.Exists(p => p.Id == id)) { newsCount++; } } // Count correct count and false positive count. correctCount += set.Count - newsCount; falsePositiveCount += newsCount != 1 ? 1 : 0; } // Calculate the expected correct count. int expectedCorrectCount = 0; foreach (List<int> s in redundantNewsIds) { expectedCorrectCount += s.Count - 1; } // Print the results. Console.WriteLine("Redundant news removed: {0}/{1}, false positives: {2}", correctCount, expectedCorrectCount, falsePositiveCount); archivist.Close(); }