BUAA_OO_ first unit Essays

BUAA_OO_ first unit Essays

This article will be divided into five modules be analyzed according to the job requirements of five.

Based on metrics to analyze their program structure

First, of course, start with a look into the UML general structure.

As can be seen, my design is divided into three elements: Poly, Item, Factor, which is around polynomials to design the structure, Poly is a polynomial, Item is key, Factor is the factor, MyConst is my constant class , which put a lot of frequently used constants, such as a match factor of regular expressions and so on. The Factor is divided into a PowerFactor, SinFactor, CosFactor these three factors, in fact, this is thirty-five kinds of factors on job requirements, the other two are signed constant factor and expression, there is no special set these two species.

This is my analysis for eleven classes, can be clearly seen, the complexity of the OCavg among the highest Factory, indeed, it has done a lot of string processing operations, and regular expression matching, and many are traversing but as for Item and Poly two classes, or because we want to complete the simplified operating on another loop through the presence of a large number, 60 characters for this job can afford, mostly controlled at about 0.2s, but if increased, it may be there TLE this case, it can be optimized.

Analysis bug own program

The first two did not work bug, the third time in two operations.

  • There is a mutual test, for the reasons Factor.toString () To para brackets can be used as factors for determining whether, because it can output at least one bracket, but I own string matches () method, I it is thought that the whole match, I did not expect just from scratch match.
  • There is also a strong measure bug, is completely sin () brackets as Poly dealt with, forget the expression factor must take (), so sin (1-x) with me is legitimate.

Analysis: careless, or testing is incomplete, did not test this wrong format, take their own evaluation and measuring machine does not come out with or without brackets, or inadequate test (test measured his enthusiasm is far better than others), write code when carelessness.

Policy analysis found himself bug procedures adopted by others

I used two

  • py with xeger generate data, with sympy test accuracy, combined shell scripts to automate testing, but only the accuracy evaluation can not determine the correct output format
  • Write a shell script to manually input data, the results will be all output through "visual inspection", judge correctness, so that we can construct a number of specific examples, its coverage test. To achieve the following specific
  • As for the code structure is designed in conjunction with the program under test, usually I do not look at someone else's code, too long.
#!/bin/bash
if [ $# -eq 0 ]
then
    echo please input your data to hack them
else
    ls -d */ > students.txt
    cat students.txt | 
    while read line
    do 
        cd ./$line
        head=$line的输出是:
        ans=$(echo $1 | java MainClass)
        echo $head $ans
        cd ..
    done
fi

Application object creation mode

The first job

The first operation took MainClass, Poly, PolyFactory, these three species, PolyFactory is the factory model, he had no designs on these two classes, it should be regarded as a simple factory pattern. That is, a string handle it, mainly with the regular match gradual transformation of this operation.

Second job

Then, when in fact the second time my main job is basically architectural design has been formed, which is so much like, just because something is in parentheses trigonometric single, I used a regular array to store different factors, it is in order to improve efficiency, as well as for data processing time can resolve quickly.

The third operation

FIG uml same in a second operation, the biggest difference is that the string processing Factory complex number, the original train is changed by the recursive solution. And the addition of this element in the para Factor used to save the trigonometric parentheses Poly. As well as some optimization merger of similar items.

And comparing experiences

Code scalability done well can save a lot of time, mainly to spend more time on the design of the future must improve his enthusiasm for the measure, others do not always want to measure.

Guess you like

Origin www.cnblogs.com/Wandy666/p/12524933.html