staafl

exam-check-1

May 22nd, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.70 KB | None | 0 0
  1. (коментарите тип "Program.cs:30" съм си ги сложил предварително и се отнасят за оригиналния сорс който ползвам за сравнение)
  2.  
  3. Code Refactoring
  4.  
  5. Name well the bad identifiers in the code
  6.  
  7. Bad identifiers: ConsoleApplication1, Problem_2, Class2, code, data, REP, REPNew, input (should be output), i, j, k, s, strings, str0, str1, conv, flag, Class1, Class2, sb, name2, Strings, old, obj, obj2, num, nums, oldent, newent, list, sorted, dict, multidict, found, ...
  8.  
  9. Identifiers are bad
  10.  
  11. --> Identifiers need more improvement
  12. REP, REPNew, etc. CommandValidator е по-скоро CommandExecutor. OutputResultManager е по-скоро някакъв utility class, макар че с този си по-скоро не трябва да съществува
  13.  
  14. Indentifiers are well named
  15.  
  16. Format the code well
  17.  
  18. Code formatting is bad
  19.  
  20. Code formatting is average
  21.  
  22. --> Code formatting is good
  23.  
  24. на някои места има доста дълги редове които би било добре да се разделят:
  25. if (phoneNumberDigits.Length >= 2 && phoneNumberDigits[0] == '0' && phoneNumberDigits[1] == '0')
  26.  
  27. Code formatting is excellent
  28.  
  29. Remove unused using statements: System.Data.* and System.Net.*
  30.  
  31. Unused usings are removed
  32.  
  33. Unused usings are partially removed
  34.  
  35. --> Unused usings are NOT removed
  36.  
  37. из доста от файловете имаш ненужни using-и
  38.  
  39. Remove meaningless / wrong comments
  40.  
  41. --> left // this works!
  42.  
  43. removed // this works!
  44.  
  45. Remove meaningless / wrong comments
  46.  
  47. left // Error reading from console
  48.  
  49. --> removed // Error reading from console
  50.  
  51. Remove meaningless / wrong comments
  52.  
  53. left // first command, // second command, // third command
  54.  
  55. partially left // first command, // second command, // third command
  56.  
  57. --> removed // first command, // second command, // third command
  58.  
  59. Remove the unneeded namespaces
  60.  
  61. (at least one of them)
  62.  
  63. No
  64.  
  65. --> Yes
  66.  
  67. Fix incorrect error handling
  68.  
  69. // Program.cs:30
  70. The code “Console.WriteLine("error!"); Environment.Exit(0);” is left untouched
  71.  
  72. The code “Console.WriteLine("error!"); Environment.Exit(0);” is partially fixed
  73.  
  74. --> Appropriate exception is thrown instead of the code “Console.WriteLine("error!"); Environment.Exit(0);”
  75.  
  76. Fix incorrect error handling
  77.  
  78. // Program.cs:37
  79. The incorrect recursive call “Main();” is left untouched
  80.  
  81. Partially fixed the incorrect recursive call “Main();”
  82.  
  83. --> Changed the incorrect recursive call “Main();” with throwing an exception
  84.  
  85. Fix incorrect error handling
  86.  
  87. // Program.cs:60
  88. The code “throw new StackOverflowException();” is left untouched
  89.  
  90. Partially fixed the code “throw new StackOverflowException();”
  91.  
  92. --> A correct exception with correct message is thrown instead of “throw new StackOverflowException();”
  93.  
  94. Fix incorrect error handling
  95.  
  96. // REPNew.cs: 43
  97. --> The line “Console.WriteLine("Duplicated name in the phonebook found: " + name);” is left untouched
  98.  
  99. Partially fixed the “Console.WriteLine("Duplicated name in the phonebook found: " + name);”
  100.  
  101. The line “Console.WriteLine("Duplicated name in the phonebook found: " + name);” changed to throw an exception
  102.  
  103. Fix incorrect error handling
  104.  
  105. // REP.cs:62
  106. --> The line “Console.WriteLine("Invalid start index or count.");” is left untouched
  107.  
  108. Partially fixed the “Console.WriteLine("Invalid start index or count.");”
  109.  
  110. The line “Console.WriteLine("Invalid start index or count.");” changed to throw an exception
  111.  
  112. Long methods are split into small, simple and well named sub-methods
  113.  
  114. // Program.cs:16
  115. Method Main() is left too long
  116.  
  117. --> Method Main() is partially refactored
  118.  
  119. за съжаление не е много добре рефакториран (парсването и switch-а са заровени в един и същи метод, проверката за null е безсмислена), имаш и грешки (при грешен брой аргументи хвърляш "invalid command name")
  120.  
  121. Method Main() is split into several simpler methods
  122.  
  123. Removed the bad cohesion in the method Cmd() or its renamed form
  124.  
  125. // Program.cs:66
  126. A parameter says what the method should do instead of having 3 separate methods
  127.  
  128. --> Тhe method Cmd(…) still has a parameter that indicates what operation to execute
  129.  
  130. Тhe method Cmd(…) is partially refactored and improved
  131.  
  132. Тhe method Cmd(…) is split into 3 methods with better cohesion: for adding a phone, for changing a phone, for listing phones
  133.  
  134. Simplify complex expressions
  135.  
  136. // Program.cs:89
  137. look around "numbers changed"
  138.  
  139. The expression is left untouched: Print("" + data.ChangePhone(conv(strings[0]), conv(strings[1])) + " numbers changed");
  140.  
  141. The expression is partially simplified: Print("" + data.ChangePhone(conv(strings[0]), conv(strings[1])) + " numbers changed");
  142.  
  143. --> Split the complex expression into few meaningful sub-expressions: Print("" + data.ChangePhone(conv(strings[0]), conv(strings[1])) + " numbers changed");
  144.  
  145. Simplify complex expressions
  146.  
  147. // Program.cs:94
  148. look around int.Parse(...)
  149.  
  150. --> The expression is left untouched: IEnumerable<Class1> entries = data.ListEntries(int.Parse(strings[0]), int.Parse(strings[1]));
  151.  
  152. The expression is partially simplified: IEnumerable<Class1> entries = data.ListEntries(int.Parse(strings[0]), int.Parse(strings[1]));
  153.  
  154. Split the complex expression into few meaningful sub-expressions: IEnumerable<Class1> entries = data.ListEntries(int.Parse(strings[0]), int.Parse(strings[1]));
  155.  
  156. Make public the IPhonebookRepository interface
  157.  
  158. The interface IPhonebookRepository is NOT public
  159.  
  160. --> The interface IPhonebookRepository is public
  161.  
  162. Make public the major interfaces and classes
  163.  
  164. The classes implementing the IPhonebookRepository interface (REP and REPNew) are NOT public
  165.  
  166. --> The classes implementing the IPhonebookRepository interface (REP and REPNew) are public
  167.  
  168. Make public the major interfaces and classes
  169.  
  170. The "phonebook entry" class is NOT public
  171.  
  172. --> The "phonebook entry" class is public
  173.  
  174. Make public the main program class
  175.  
  176. (this will be needed for the unit tests)
  177.  
  178. The main program class is NOT public
  179.  
  180. --> The main program class is public
  181.  
  182. Move each public class / interface into separate C# file
  183.  
  184. All classes and interfaces stay in the same file
  185.  
  186. Some classes / interfaces are in separate files, some are in the same file
  187.  
  188. --> All classes and interfaces stay in separate files
  189.  
  190. Refactor the public fields
  191.  
  192. // Entry.cs:25
  193. public SortedSet<string> Strings;
  194.  
  195. --> The field is left untouched: public SortedSet<string> Strings;
  196.  
  197. преименувано но не променено
  198.  
  199. The field is partially fixed: public SortedSet<string> Strings;
  200.  
  201. The field is made private or converted to a read-only propety: public SortedSet<string> Strings;
  202.  
  203. Refactor the public fields
  204.  
  205. // REPNew.cs:7
  206. public List<Class1> entries = new List<Class1>();
  207.  
  208. --> The field is left untouched: public List<Class1> entries = new List<Class1>();
  209.  
  210. The field is partially fixed: public List<Class1> entries = new List<Class1>();
  211.  
  212. The field is made private or converted to a read-only propety: public List<Class1> entries = new List<Class1>();
  213.  
  214. The field is missing because its entire class is removed.
  215.  
  216. Bug Fixing
  217.  
  218. // Program.cs:80
  219. Change "Phone entry created." to "Phone entry created"
  220.  
  221. (with no dot at the end)
  222.  
  223. --> Not fixed
  224.  
  225. Fixed
  226.  
  227. // Program:cs - Cmd
  228. The code for processing the commands “AddPhone” and “List” is interchanged
  229.  
  230. Not fixed
  231.  
  232. --> Fixed
  233.  
  234. // Program:cs - 50
  235. The command “ChangeРhone” is wrongly spelled
  236.  
  237. (with Cyrillic „Р“ instead of Latin letter “P”)
  238.  
  239. --> Not fixed
  240.  
  241. Fixed
  242.  
  243. Unit Testing
  244.  
  245. Method IPhonebookRepository.AddPhone(): single phonebook entry
  246.  
  247. Add а single phonebook entry and assert it is correctly entered in the repository as new entry
  248.  
  249. --> No
  250.  
  251. Partially
  252.  
  253. Yes
  254.  
  255. Method IPhonebookRepository.AddPhone(): duplicated entry
  256.  
  257. Add duplicated entry (add several times the same name + phones) and assert the entry is correctly entered in the repository only once. The first call to AddPhone() should return true, while the next calls should return false.
  258.  
  259. --> No
  260.  
  261. Partially
  262.  
  263. Yes
  264.  
  265. Method IPhonebookRepository.AddPhone(): different casing
  266.  
  267. Add multiple phones for the same name passed with different casing (e.g. “AddPhone(Nakov, +359111)”, then “AddPhone(naKOV, +359222)”) and assert only one phonebook entry is created. The first call to AddPhone() should return true, while the next calls should return false.
  268.  
  269. --> No
  270.  
  271. Partially
  272.  
  273. Yes
  274.  
  275. Method IPhonebookRepository.AddPhone(): add with merge
  276.  
  277. Test add with merge: add several sets of phones for the same name and assert that in the repository the set of phones are intersected (all unique phones are kept while all duplicates are removed).
  278.  
  279. --> No
  280.  
  281. Partially
  282.  
  283. Yes
  284.  
  285. Method IPhonebookRepository.ListEntries(…): single entry
  286.  
  287. Single entry with single phone / multiple phones: test adding a single entry with a single phone and / or multiple phones and list it, then check for correctness
  288.  
  289. --> No
  290.  
  291. Partially
  292.  
  293. Yes
  294.  
  295. Method IPhonebookRepository.ListEntries(…): sorting the phonebook entries
  296.  
  297. Test sorting the phonebook entries: add several entries, list them and assert their sorting order is correct
  298.  
  299. --> No
  300.  
  301. Partially
  302.  
  303. Yes
  304.  
  305. Method IPhonebookRepository.ListEntries(…): sorting the phones within an entry
  306.  
  307. Test sorting the phones within an entry: add an entry with several phones, list them and assert the phones are sorted correctly
  308.  
  309. --> No
  310.  
  311. Partially
  312.  
  313. Yes
  314.  
  315. Method IPhonebookRepository.ListEntries(…): merge + list
  316.  
  317. Merge + list: add few phonebook entries with the same name to cause their phones to be merged. Then list the added entries and assert the merge was correct
  318.  
  319. --> No
  320.  
  321. Partially
  322.  
  323. Yes
  324.  
  325. Method IPhonebookRepository.ListEntries(…): paging
  326.  
  327. Paging: add n entries, then list less than n entries and assert the extracted page is correct. E.g. if we have 5 entries, try List(1, 3) and assert the result is correct
  328.  
  329. --> No
  330.  
  331. Almost no
  332.  
  333. Partially
  334.  
  335. Not fully
  336.  
  337. Yes
  338.  
  339. Method IPhonebookRepository.ListEntries(…): invalid range - negative start
  340.  
  341. List invalid range (negative start): try to list an invalid range (negative start) and assert an exception is thrown
  342.  
  343. --> No
  344.  
  345. Yes
  346.  
  347. Method IPhonebookRepository.ListEntries(…): invalid range - too big start
  348.  
  349. List invalid range (invalid start): try to list an invalid range (too big start) and assert an exception is thrown
  350.  
  351. --> No
  352.  
  353. Yes
  354.  
  355. Method IPhonebookRepository.ListEntries(…): invalid range - too big count
  356.  
  357. List invalid range (invalid count): try to list an invalid range (too big count) and assert an exception is thrown
  358.  
  359. --> No
  360.  
  361. Yes
  362.  
  363. Method IPhonebookRepository.ChangePhone(…): change existing phone
  364.  
  365. Change existing phone: add a phonebook entry, then change its phone, assert 1 phone number is affected and list the phone and check it is correct
  366.  
  367. --> No
  368.  
  369. Partially
  370.  
  371. Yes
  372.  
  373. Method IPhonebookRepository.ChangePhone(…): change non-existing phone
  374.  
  375. Change non-existing phone: change a non-existing phone and assert the number of affected phones is 0 and no changes were made in the phonebook repository
  376.  
  377. --> No
  378.  
  379. Partially
  380.  
  381. Yes
  382.  
  383. Method IPhonebookRepository.ChangePhone(…): change shared phone
  384.  
  385. Change shared phone: add several phonebook entries that have a common (shared) phone number; change the common phone number; assert the number of affected phones is correct; list the phones and assert they are correct
  386.  
  387. --> No
  388.  
  389. Almost no
  390.  
  391. Partially
  392.  
  393. Not fully
  394.  
  395. Yes
  396.  
  397. Method IPhonebookRepository.ChangePhone(…): marge with duplicates
  398.  
  399. Change phone with merge and duplicates: add few phonebook entries; change a phone number with another phone number already in the phonebook to cause duplicated phones (obtained after the change) to be merged; list the phonebook and assert the phones are correctly merged
  400.  
  401. --> No
  402.  
  403. Partially
  404.  
  405. Not fully
  406.  
  407. Yes
  408.  
  409. Check the code coverage for the class implementing IPhonebookRepository
  410.  
  411. --> 0% ... 24%
  412.  
  413. 25% ... 54%
  414.  
  415. 55% ... 84%
  416.  
  417. 85% ... 100%
  418.  
  419. Code Documentation
  420.  
  421. Document all public methods and properties defined in the IPhonebookRepository interface using XML documentation
  422.  
  423. The documentation should be in the IPhonebookRepository interface
  424.  
  425. No documentation
  426.  
  427. Some documentation exists, but far away from finished
  428.  
  429. Some interface methods documented partially
  430.  
  431. Most interface methods documented partially
  432.  
  433. All interface methods documented partially (or documentation is in the class instead in the interface)
  434.  
  435. --> All interface methods documented well
  436.  
  437. Performance Bottlenecks
  438.  
  439. // Program.cs:12
  440. IPhonebookRepository implementation (look around "static IPhonebookRepository")
  441.  
  442. Boottleneck description: the program uses the slower IPhonebookRepository implementation (REPNew instead of REP). The implementation based on list (REPNew) is many times slower than the implementation based on ordered sets and dictionaries (REP)
  443.  
  444. --> Bottleneck NOT found
  445.  
  446. Bottleneck found (described somehow in the code, but not fixed)
  447.  
  448. Bottleneck found and fixed (the faster IPhonebookRepository implementation is used)
  449.  
  450. // Program.cs:104
  451. Phone convertion to canonical form (look around "IsDigit()")
  452.  
  453. The performance bottleneck is in the method “conv(…)” that converts a phone number into canonical form. It has unneeded for-loop that does nothing but repeating the phonebook conversion logic many times. In the loop body the conversion is made several times with no good reason.
  454.  
  455. --> Bottleneck NOT found
  456.  
  457. Bottleneck found (described somehow in the code, but not fixed)
  458.  
  459. Bottleneck found and fixed (remove the unneeded for-loop and repeated conversion logic)
  460.  
  461. ToList() invocation in IPhonebookRepository.ChangePhone()
  462.  
  463. // REP.cs:48
  464. The performance bottleneck is in the method ChangePhone() of IPhonebookRepository"s fast implementation. It performs ToList() for all matched phonebook entries which is slow operation. No fix is available.
  465.  
  466. --> Bottleneck NOT found
  467.  
  468. Bottleneck found, but not well described
  469.  
  470. Bottleneck found and is correctly described
Advertisement
Add Comment
Please, Sign In to add comment