Example #1
0
        public static IEnumerable<WordCard> FilterByCounter(IEnumerable<WordCard> dictionary, CounterFilterType filterType, int filterValue, TrainingType trainingType)
        {
            IEnumerable<WordCard> result = dictionary;
            switch (filterType)
            {
                case CounterFilterType.Equals:
                    result =
                        from c in dictionary
                        where c.Counter1[trainingType] == filterValue || c.Counter2[trainingType] == filterValue
                        select c;
                    break;
                case CounterFilterType.More:
                    result =
                        from c in dictionary
                        where c.Counter1[trainingType] > filterValue || c.Counter2[trainingType] > filterValue
                        select c;
                    break;
                case CounterFilterType.Less:
                    result =
                        from c in dictionary
                        where c.Counter1[trainingType] < filterValue || c.Counter2[trainingType] < filterValue
                        select c;
                    break;
                default:
                    throw new ArgumentException("Unsupported filter type");
            }

            return result;
        }
        // count amount of words with specified counter in dictionary
        private int CountWordsByCounter(WordsDictionary dictionary, CounterFilterType type, int counter)
        {
            int count = 0;
            foreach (var item in dictionary)
            {
                if (type == CounterFilterType.Equals)
                {
                    if (item.Counter1[trainingType] == counter || item.Counter2[trainingType] == counter)
                        count++;
                }
                else if (type == CounterFilterType.More)
                {
                    if (item.Counter1[trainingType] > counter || item.Counter2[trainingType] > counter)
                        count++;
                }
                else if (type == CounterFilterType.Less)
                {
                    if (item.Counter1[trainingType] < counter || item.Counter2[trainingType] < counter)
                        count++;
                }
            }
            return count;

        }
 // Check that all words in result have specified counter value
 // return words amount in result
 private int CheckFilterCounter(IEnumerable<WordCard> result, CounterFilterType type, int counter)
 {
     int count = 0;
     foreach (var item in result)
     {
         if (type == CounterFilterType.Equals)
             Assert.IsTrue(item.Counter1[trainingType] == counter || item.Counter2[trainingType] == counter);
         else if (type == CounterFilterType.More)
             Assert.IsTrue(item.Counter1[trainingType] > counter || item.Counter2[trainingType] > counter);
         else if (type == CounterFilterType.Less)
             Assert.IsTrue(item.Counter1[trainingType] < counter || item.Counter2[trainingType] < counter);
         count++;
     }
     return count;
 }