Advertisement
YavorGrancharov

GUnit

Jan 6th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace GUnit
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             SortedDictionary<string, SortedDictionary<string, SortedSet<string>>> map =
  13.                 new SortedDictionary<string, SortedDictionary<string, SortedSet<string>>>();
  14.  
  15.             Dictionary<string, int> classUnits = new Dictionary<string, int>();
  16.  
  17.             string input = Console.ReadLine();
  18.             string pattern = @"^([A-Z][a-zA-Z0-9]+) \| ([A-Z][a-zA-Z0-9]+) \| ([A-Z][a-zA-Z0-9]+)$";
  19.  
  20.             Regex regex = new Regex(pattern);
  21.  
  22.             while (input != "It's testing time!")
  23.             {
  24.                 Match match = regex.Match(input);
  25.                 if (match.Success)
  26.                 {
  27.                     string className = match.Groups[1].Value.Trim();
  28.                     string methods = match.Groups[2].Value.Trim();
  29.                     string tests = match.Groups[3].Value.Trim();
  30.  
  31.                     if (!map.ContainsKey(className))
  32.                     {
  33.                         map.Add(className, new SortedDictionary<string, SortedSet<string>>());
  34.                         classUnits.Add(className, 0);
  35.                     }
  36.  
  37.                     if (!map[className].ContainsKey(methods))
  38.                     {
  39.                         map[className].Add(methods, new SortedSet<string>());
  40.                     }
  41.  
  42.                     if (!map[className][methods].Contains(tests))
  43.                     {
  44.                         map[className][methods].Add(tests);
  45.                         classUnits[className] += 1;
  46.                     }
  47.                 }
  48.                 input = Console.ReadLine();
  49.             }
  50.  
  51.             Dictionary<string, SortedDictionary<string, SortedSet<string>>> sortedMap = map
  52.                 .OrderByDescending(c => classUnits[c.Key])
  53.                 .ThenBy(c => c.Value.Count())
  54.                 .ToDictionary(c => c.Key, c => c.Value);
  55.  
  56.             foreach (var clas in sortedMap)
  57.             {
  58.                 Console.WriteLine(clas.Key + ":");
  59.  
  60.                 foreach (var method in clas.Value.OrderByDescending(m => m.Value.Count))
  61.                 {
  62.                     Console.WriteLine("##" + method.Key);
  63.                     foreach (var unit in method.Value.OrderBy(t => t.Length))
  64.                     {
  65.                         Console.WriteLine("####" + unit);
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement