zoukankan      html  css  js  c++  java
  • 【个人博客作业II】代码复审结果

    【代码复审结果】


     

    • General

      • Does the code work? Does it perform its intended function, the logic is correct etc.
        • 基本完成个人任务需求;
        • 未实现功能:带分数生成,括号支持不完善(无(1+5)×(3-5)这种,也有7/9/2*8这样存在二义性的情况出现),除零/负数的规避处理,规范化输出(N. 运算式);
        • 逻辑基本正确,有较为完善的异常处理机制;
      • Is all the code easily understood?
        • 较为易读,有较为完整的注释,命名直截了当,用规范化的接口说明;
      • Does it conform to your agreed coding conventions? These will usually cover location of braces, variable and function names, line length, indentations, formatting, and comments.
        • 因为使用的语言不一代码风格差异较大,括号换行处理方式不一(左括号不换行),其他基本一致;
      • Is there any redundant or duplicate code?
        • Equation.cpp里的solve函数没有用到,最后用的是重写的solve1;
      • Is the code as modular as possible?
        • 模块化程度较高,分数,表达式,IO处理各成一模块,分数和表达式集成到类里,分工细致;
        •  1 void fff();
           2 void exitErr(char* info, int errNum);
           3 void work1(int,int);
           4 void work2(char*, char*);
           5 int isp(char);
           6 int icp(char);
           7 
           8 class Fraction{
           9 public:
          10     Fraction();
          11     Fraction(int, int);
          12     int static gcd(int, int);
          13     Fraction operator+(const Fraction &);
          14     Fraction operator-(const Fraction &);
          15     Fraction operator*(const Fraction &);
          16     Fraction operator/(const Fraction &);
          17     Fraction operator=(const Fraction &);
          18     bool operator==(const Fraction &);
          19     int numerator;
          20     int denominator;
          21     string toString();
          22 };
          23 
          24 class Equation{
          25 public:
          26     Equation();
          27     Equation(int); //构造,输入maxNum
          28     string getLeft(); //返回左边式子
          29     string getRight(); //返回右边式子 用于输出
          30     bool equals(Equation &); //用于判重
          31 
          32     static int solve(char*);
          33     static Fraction solve1(string);
          34 
          35 private:
          36     int leftSum; //用于算式判重
          37     Fraction rightSum; //用于算式判重
          38     string rightStr;
          39     string leftStr;
          40 
          41     
          42     //char* solveDiv(char*);
          43 };
          44 
          45 #endif
      • Can any global variables be replaced?
        • 仅用了宏函数,无全局变量;
        • #define random(max) (rand()%(max))
      • Is there any commented out code?
        • 有注释掉的代码;
      • Do loops have a set length and correct termination conditions?
        • 均有设置,不过也存在较为繁冗的判断条件,如Equaltion::solve1中的 while (signTop != 0 && icp(str[i])<=isp(signStack[signTop - 1]) && !RMeetL)//这里检查符号栈是否为空,且判断符号优先级顺序,并检查左右符号是否已经完成匹配,不过其实只需要判断栈空即可进入循环,对于括号匹配和优先级顺序判断可以嵌入到if else语句分支中,相应设置break即可;
        •  1 int isp(char c){
           2     switch (c)
           3     {
           4     case '#':
           5         return 0;
           6         break;
           7     case '^':
           8         return 7;
           9         break;
          10     case '*':case '/': case '%':
          11         return 5;
          12         break;
          13     case '+':case '-':
          14         return 3;
          15         break;
          16     case '(':
          17         return 1;
          18         break;
          19     case ')':
          20         return 8;
          21         break;
          22     default:
          23         exitErr("Error in isp", -9);
          24         return -1;
          25         break;
          26     }
          27 }
      • Can any of the code be replaced with library functions?
        • 没有可用库函数替代的函数
      • Can any logging or debugging code be removed?
        • 无相关代码

    • Security

      • Are all data inputs checked (for the correct type, length, format, and range) and encoded?
        • 执行批改功能时文件需规范化文件格式,命令行参数输入检查比较完善(三次检查)
          1 if (strlen(argv[i]) != 2) exitErr("command valid", -2);
          2         tmpchar = argv[i][0];
          3         cmdchar = argv[i][1];
          4         if (tmpchar != '-' || (cmdchar != 'n'&&cmdchar != 'r'&&cmdchar != 'e'&&cmdchar != 'a'))exitErr("command valid", -1);
          5         i++;
          6         if (i == argc) exitErr("command valid", -2);
      • Where third-party utilities are used, are returning errors being caught?
        • 未使用第三方程序
      • Are output values checked and encoded?
        • 有较全面的异常分析和相应的错误码输出,并写有专门的错误处理函数:
        • void exitErr(char* info, int errNum){
              printf("%s; error code:%d", info, errNum);
              exit(errNum);
          }
           1 case '(':  //当前进栈只可能是 ) # 才会把 ( 出栈
           2                     //左括号出栈没有计算操作,不需要执行后面的数字、字符入栈与出栈操作,所以continue跳过
           3                     //直接continue会将后面的signTop--出栈操作跳过,造成死循环
           4                     //需要在此将字符'('出栈
           5                     //和上面不同的是,当前字符str[i]不需要入栈
           6                     if (str[i] == ')'){
           7                         signTop--;
           8                         RMeetL = true;
           9                     }
          10                     else{
          11                         exitErr("左括号后没有右括号", -11);
          12                     }
          13                     break;
      • Are invalid parameter values handled?
        • 由专门的错误处理函数void exitErr(char* info, int errNum)

    • Documentation

      • Do comments exist and describe the intent of the code?
        • 有较为简洁的Readme文档
      • Are all functions commented?
        • 暂无,下同
      • Is any unusual behavior or edge-case handling described?
      • Is the use and function of third-party libraries documented?
      • Are data structures and units of measurement explained?
      • Is there any incomplete code? If so, should it be removed or flagged with a suitable marker like ‘TODO’?

    • Testing

      • Is the code testable? i.e. don’t add too many or hide dependencies, unable to initialize objects, test frameworks can use methods etc.
        • 可以测试,无过多依赖对象,大部分在函数内部已经完成相应初始化操作
      • Do tests exist and are they comprehensive? i.e. has at least your agreed on code coverage.
        • 无测试单元,下同
      • Do unit tests actually test that the code is performing the intended functionality?
      • Are arrays checked for ‘out-of-bound’ errors?
      • Could any test code be replaced with the use of an existing API?

    • Summary

      • 程序代码较为规范,设计思路清晰,模块化程度高,可读性强,有详细的注释,在输入输出等安全处理方面有仔细考虑过,并限制了较为严格的条件来避免复杂的错误情况,唯一不足就是功能还有待完善,因为除零异常检查尚不完善致使程序测试存在一定的难度,有待进一步改进

     

  • 相关阅读:
    【转】 测试人员的职业规划 --整理标注
    关于数据准备
    功能点算法及在软件测试中的应用
    MySQL常用命令大全
    Python学习笔记
    python 学习笔记 if语句
    一个男人关心的东西 决定了他的层次
    Oracle 计算两个时间的差值
    javascript对下拉列表框(select)的操作
    java需要掌握内容、核心不断更新中
  • 原文地址:https://www.cnblogs.com/kibbon/p/4847672.html
Copyright © 2011-2022 走看看