Four pair programming job

Git address https://github.com/isliudong/WordCount
Knot work address to students < Companion blog >
Junction number of school students 201731062214
Personal blog address https://www.cnblogs.com/liudong123/
Work requirements < Operational requirements >

First, the pairing process (pictures)


Two, PSP form

PSP2.1 Personal Software Process Stages It is expected to take (minutes) The actual time-consuming (minutes)
Planning plan 30 20
Estimate Estimate how long this task 30 20
Development Development (requirements analysis - specific coding) 400 450
Analysis Requirements analysis (including learning new technologies) 200 200
Design Spec Generate design documents 20 30
Design Review Design review (audit and students to design documents) 30 40
Coding Standard Code specification (norm for the current development) 20 15
Design Specific design 60 80
Coding Specific coding 200 200
Code Review Code Review 60 60
Test Test (self-test, modify the code, the code submitted) 120 120
Reporting report 80 60
Test Report testing report 45 40
Size Measurement Computing workload 20 25
Postmortem & Process Improvement Plan Later summarized, and process improvement plan 20 15
total total 1335 1375

Third, the basic problem-solving ideas

1. When we see this article when probably looked demand, wordCount is a similar program used to count some of the content of TXT documents.

2. The process needs to read the text, and then split and split into an array of regular expression, and then be set in accordance with all the requirements of elements in the array, according to the blog address job specification, one by one to realize the function

3. Taking into account the follow-up may add some new features to stay ahead of the interface to achieve some functions may be implemented

4. First, a command-line programming established, then a transition to object-oriented programming


Fourth, the program design (detailed)

According to the command line after we first have to become realized, we intend to reconstruct the code, as well as code that implements the decoupling object-oriented programming, this experiment has several features roughly the following statistical character, then count the number of words, lines statistics
as well as each so the number of times the word appears designed several categories:
the Do class:
the Compare categories:

Program categories:

Read categories:

Text categories:

Write类:

  • Logic Process Design

  • Interface package design

  • Two additional features and custom command-line parameters of design

    • Custom command line
      in the array of string arguments cmd command line entry will be stored in the program main function main (string [] args) in. In order to ensure the order of the input parameters without affecting the program execution order, using branch statements determines and saves parameters. Then it is determined whether an empty path for input and output, the user input to prevent errors. In accordance with the requirements of the subject - i and -o parameter must be a combination of the -m and -n, but there will be three cases, so use branching statements to judge again.

         //对-l、-m、-n、-o参数识别并保存他们后面的输入值
         for(int i=0;i<args.Length;i++)
                  {
                      if (args[i] == "-l")//路径参数
                      { path = args[i + 1]; i++; }
                      else if (args[i] == "-m")//参数设定统计的词组长度
                      { wordlength = int.Parse(args[i+1]); i++; }
                      else if (args[i] == "-n")//参数设定输出的单词数量
                      { outnum = int.Parse(args[i + 1]); i++; }
                      else if (args[i] == "-o")//参数设定生成文件的存储路径
                      { outpath = args[i + 1]; i++; }
                  }
    • Generating a phrase (-m) in accordance with the corresponding parameter
      I nested loop to achieve a combination of words into an array, and the new string is stored in the array. The coincidence of the newly generated phrase. Just need to find the number of words in the document, the command line parameters -m, the number of times the outer loop mathematical relationship, the outer loop represents the number of how many phrases generation means to stop cross-border will not be there ; it represents the inner loop by the combination of words into a phrase also need to loop a few times to calculate the number of cycles and the -m parameter relationships mathematical relationship.

      //嵌套循环生成词组
            words[0] = word[1];
      
                  for(int i=0;i<word.Length-wordlenth;i++)
                  {
                      for (int j = i; j <= i+wordlenth-1; j++)
                      { words[i] = words[i] + " "+word[j]; }
                  }
    • A high-frequency output according to the number of parameters (-n) times
      the Compare subclass we designed statistical frequency word appears flat and dual-implemented method of sorting keyword dictionary and a frequency sorting time, so the design of this addition -n -n parameters only need to pass a subclass method can be achieved. It can be said here in the previous frame design has played a significant role.

      //单词比较算法
              public  int compare(String str1, String str2)
              {
                  int length1 = str1.Length;
                  int length2 = str2.Length;
                  int limit = Math.Min(length1, length2);
                  char[] a = str1.ToCharArray();
                  char[] b = str2.ToCharArray();
      
                  for (int i = 0; i < limit; i++)
                  {
                      char c1 = (char)(a[i] >= 'a' ? a[i] : (a[i] + 32));
                      char c2 = (char)(b[i] >= 'a' ? b[i] : (b[i] + 32));
                      if (c1 != c2)
                      {
                          return c1 - c2;
                      }
                  }
      
                  return length1 - length2;
      
              }

V. code specification

= "Use meaningful names when naming

= "Prohibit the use of Chinese name

= "Variable nomenclature employed hump

= "For some complex functions and code, plus detailed notes

= "Indented line feed mode, so the code looks neat Specification


Sixth, the code peer review

1. When code review, we found that there are a few names not in accordance with the requirements to name, so we corrected the name

2. When the function realized we found some small details, and that is the space character as the word input, resulting in a final count of the number is not more than the actual number, I put this place redesigned some, a little change of judge condition

3. There are some small bug did not have time to repair, but does not affect the actual operation (funny)

Seven, unit testing and exception handling

unit test:

  • The word dictionary comparison operator to compare (Compare.compare ()):

    public class CompareTests
        {
            [TestMethod()]
            public void compareTest()
            {
                Compare compare = new Compare();
                String[] word1 = { "as", "ae", "th", "cpig" };
                String[] word2 = { "we", "are", "the", "pig" };
                int t;
                bool k=false;
                for (int i = 0; i < 4; i++)
                {
                    t = compare.compare(word1[i], word2[i]);
                    if (t < 0)
                    {
                        k = true;
                    }
                    Assert.AreEqual(true,k );
                }           
            }
        }
  • Test Results:


  • Copy the characters mixed test

    Test text

testing successfully

Exception Handling:

  • On the file read test

    • Test code design:

      public void ReadTextTest()
              {
                  Read read = new Read();
                  read.ReadText("D:\a.txt", 1);
                  for(int i=0;i<read.word.Length;i++)
                  {
      
                      Assert.AreNotEqual("", read.word[i]);
                  }
                  //Assert.Fail();
              }
    • Run error:

Found to be due to the word = Regex.Split (sr.ReadToEnd (), @ "\ W +"); the code problems, split function by a regular expression to split up the case from beginning to end there is an empty word array.

Non-empty when the array is determined by stored hashtable, to solve the problem shown in FIG.

  • Document write file path exists exception handling:

    • Code design:

        FileStream fileStream1 = new FileStream(l, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                  fileStream1.Close();//如果文件不存在会自动在该路径下创建写入文件
      
  • Test experience:

    For the design of exception handling are a few points you want to share:
    1,

    2, Some functions are called function test is unsuccessful but the caller is processed in function, is also possible.


Eight, testing and performance improvements

Improved spend time: 25mins

  • Performance Testing:

  • Performance Analysis function:

The main is to create hashtable, letters, comparison and reading character eaten in three parts performance

improve proposals:


Nine, and the result of the program code shows screenshots

  • Main:

       public static void Main(string[] args)
            {           
                int wordlength=1;
                int outnum=0;
                string outpath="/";
                string path=null;                                     
                for(int i=0;i<args.Length;i++)
                {
                    if (args[i] == "-i")//路径参数
                    { path = args[i + 1]; i++; }
                    else if (args[i] == "-m")//参数设定统计的词组长度
                    { wordlength = int.Parse(args[i+1]); i++; }
                    else if (args[i] == "-n")//参数设定输出的单词数量
                    { outnum = int.Parse(args[i + 1]); i++; }
                    else if (args[i] == "-o")//参数设定生成文件的存储路径
                    { outpath = args[i + 1]; i++; }
                }
                new Do().doing(path, wordlength, outnum, outpath);
    
            }
  • ReadText:

          public String ReadText(String path,int wordlenth)
            {
                StreamReader sr = new StreamReader(path, Encoding.Default);
                while(sr.Read()!=-1)
                {
                    sum++; 
    
                }
                row= sr.ReadToEnd().Split('\n').Length;
    
                sr.BaseStream.Seek(0, SeekOrigin.Begin);//重置流指针
                row = sr.ReadToEnd().Split('\n').Length;//行数统计
                sr.BaseStream.Seek(0, SeekOrigin.Begin);
                word = Regex.Split(sr.ReadToEnd(), @"\W+");//
                words = new string[word.Length-wordlenth];
                words[0] = word[1];            
                for(int i=0;i<word.Length-wordlenth;i++)
                {
                    for (int j = i; j <= i+wordlenth-1; j++)
                    { words[i] = words[i] + " "+word[j]; }
                }
                sr.BaseStream.Seek(0, SeekOrigin.Begin);//重置流指针
                return sr.ReadToEnd();
            }  
  • Write to the file:

         using (StreamWriter sw = new StreamWriter(outpath))
                {
                    sw.WriteLine("单词数:" + count);//单词数
                    sw.WriteLine("字符数:" + zifushu);
                    sw.WriteLine("行数:" + hangshu);
                    sw.WriteLine("词汇量:" + cihui);
                    sw.WriteLine("词组频统计(词频优先字典序):");
                    for (int i = 0; i < wd.Length; i++)
                    {
                        sw.WriteLine(wd[i] + ": " + hashtable[wd[i]]);
                    }
    
                    sw.Close();
                    Console.ReadLine();
    
                }
  • The phrase into hashtable:

           for (int i = 0; i < read.words.Length; i++)
                {
    
                        if (hashtable.ContainsKey(read.words[i]))
                    {
                        geshu = (int)hashtable[read.words[i]];
                        geshu++;
                        hashtable[read.words[i]] = geshu;
    
                    }
                    else
                    {
                        if (read.words[i] != "")//取出split产生的空字符
                            hashtable.Add(read.words[i], times[i]);
                    }
                }
  • Command line to run the results:


Ten, experience summary

结对编程让我实际体会了1+1>2的效果,在一些时间很短的小项目上,结对编程的效率是远远大于单人开发的,当我们在某个具体代码实现的地方出现问题时,两个人解决问题的速度快于一个人,在我的伙伴实际编码的过程中,我会给他提出一些意见,在一个就是可以确定编码思路方向,另一个人只管实现就可以了,而且结对编程的过程中,每个代码就相当于看了两遍,这样出错的可能性大大减小。总的来说结对编程在敏捷这种思想下,是可行的。

Guess you like

Origin www.cnblogs.com/liudong123/p/11666729.html