Guest User

Untitled

a guest
Aug 10th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Class
  6. {
  7. private string clasName;
  8. private List<Method> methods;
  9.  
  10. public Class(string className)
  11. {
  12. this.clasName = className;
  13. }
  14.  
  15. public string ClassName
  16. {
  17. get { return clasName; }
  18. set { this.clasName = value; }
  19. }
  20.  
  21. public List<Method> Methods
  22. {
  23. get { return methods; }
  24. set { this.methods = value; }
  25. }
  26. }
  27.  
  28. class Method
  29. {
  30. private string methodName;
  31. private List<string> tests;
  32.  
  33. public Method(string methodName)
  34. {
  35. this.methodName = methodName;
  36. }
  37.  
  38. public string MethodName
  39. {
  40. get { return methodName; }
  41. set { this.methodName = value; }
  42. }
  43.  
  44. public List<string> Tests
  45. {
  46. get { return tests; }
  47. set { this.tests = value; }
  48. }
  49. }
  50.  
  51. public class GUnit
  52. {
  53. static string @class;
  54. static string method;
  55. static string test;
  56.  
  57. static List<Class> classCollection = new List<Class>();
  58.  
  59. public static void Main()
  60. {
  61. ReadNextLinesUntilTestingTimeFrom(Console.ReadLine());
  62. PrintAllClassesFromClassCollection();
  63. }
  64.  
  65. static void PrintAllClassesFromClassCollection()
  66. {
  67. foreach (var item in classCollection
  68. .OrderByDescending(clas => clas.Methods.Sum(method => method.Tests.Distinct().Count()))
  69. .ThenBy(clas => clas.Methods.Count)
  70. .ThenBy(clas => clas.ClassName).Distinct())
  71. {
  72. Console.WriteLine(item.ClassName + ":");
  73.  
  74. foreach (var method in item.Methods
  75. .OrderByDescending(method => method.Tests.Distinct().ToList().Count)
  76. .ThenBy(method => method.MethodName).Distinct())
  77. {
  78. Console.WriteLine("##{0}", method.MethodName);
  79.  
  80. foreach (var test in method.Tests
  81. .OrderBy(test => test.Length)
  82. .ThenBy(test => test).Distinct())
  83. {
  84. Console.WriteLine("####{0}", test);
  85. }
  86. }
  87. }
  88. }
  89.  
  90. static void ReadNextLinesUntilTestingTimeFrom(string input)
  91. {
  92. if (input != "It's testing time!")
  93. {
  94. DivideAndRuleCurrent(input);
  95. ReadNextLinesUntilTestingTimeFrom(Console.ReadLine());
  96. }
  97. else return;
  98. }
  99.  
  100. static void DivideAndRuleCurrent(string input)
  101. {
  102. var patern = new string[] { " | " };
  103. var splited = input.Split(patern, StringSplitOptions.RemoveEmptyEntries);
  104. if (isValidInput(splited))
  105. {
  106. @class = splited[0];
  107. method = splited[1];
  108. test = splited[2];
  109.  
  110. AddOrUpdateToClassCollection();
  111. }
  112. else return;
  113. }
  114.  
  115. static bool isValidInput(string[] splited)
  116. {
  117. var isValid = true;
  118. isValid = splited.Length == 3;
  119. if (!isValid)
  120. {
  121. return false;
  122. }
  123. foreach (var item in splited)
  124. {
  125. if (!isValid)
  126. {
  127. return false;
  128. }
  129. isValid = AreOnlyLetersAndDigits(item);
  130. }
  131. return isValid;
  132. }
  133.  
  134. private static bool AreOnlyLetersAndDigits(string item)
  135. {
  136. return item.Length >= 2 &&
  137. (item[0] >= 'A' && item[0] <= 'Z') &&
  138. !item.Any(x => (x < 'a' || x > 'z') && (x < 'A' || x > 'Z') && (x < '0' || x > '9'));
  139.  
  140. }
  141.  
  142. static void AddOrUpdateToClassCollection()
  143. {
  144. if (!classCollection.Any(x => x.ClassName == @class))
  145. {
  146. var newMethod = new Method(method);
  147. newMethod.Tests = new List<string>();
  148. newMethod.Tests.Add(test);
  149.  
  150. var newClass = new Class(@class);
  151. newClass.Methods = new List<Method>();
  152. newClass.Methods.Add(newMethod);
  153.  
  154. classCollection.Add(newClass);
  155. }
  156. else UpdateCurrentClass();
  157. }
  158.  
  159. static void UpdateCurrentClass()
  160. {
  161. var currentClass = classCollection.Where(x => x.ClassName == @class).FirstOrDefault();
  162. if (!currentClass.Methods.Any(x => x.MethodName == method))
  163. {
  164. var newMethod = new Method(method);
  165. newMethod.Tests = new List<string>();
  166. newMethod.Tests.Add(test);
  167.  
  168. currentClass.Methods.Add(newMethod);
  169. }
  170. else currentClass.Methods.Where(x => x.MethodName == method).FirstOrDefault().Tests.Add(test);
  171. }
  172. }
Add Comment
Please, Sign In to add comment