Pre-training - personal projects (Metro Line)

Metro Line project

2019.7.21
   完成了程序构思与模块划分;填写PSP表计划时间;完成了模块设计;异常处理说明;测试用例等部分内容,下一步进行单元测试、黑盒测试和并完成程序的分析与优化。
   

Conception and program module division

本项目核心问题实质上是无向无权图中,求最短路径,通过对此项目进行分析,整个程序大致划分为如下几个模块:
  • Command analysis module: type of command line arguments, and extracting input parameter values.
  • Module IO operations: reading subway map data file is an array of strings, the output data string is converted into a plurality of lines written to the output file.
  • Subway map parsing module: converting an array of strings for the subway line, the subway station, and to extract the transfer station, a subway route map constructed object.
  • Line query module: receiving the input line information, the line corresponding to the query, a list of all stations in the output of the query line subway map object.
  • Line search module: Accept the starting point and the terminal point information input by the shortest path algorithm to find the shortest route path.
  • Control module: coordination of each module to ensure the program runs correctly. The main control module invoke the command parsing module, until the command and response parameters; parsing module call Metro subway map objects are constructed according to a different command, calling line query module queries that return to the line site information, call the line search module acquires beginning to the end the minimum transfer line.

The estimated time required for exploitation, and by the following table PSP record:

PSP2.1 Personal Software Process Stages Time Real Time
Planning plan 1h
  · Estimate    • Estimate how much time this task requires 1h
Development Develop 21h
  · Analysis    · Needs analysis (including learning new technologies) 2h
  · Design Spec   Generate design documents 2h
  · Design Review    · Design Review (and his colleagues reviewed the design documents) 1h
  · Coding Standard   · Code specifications (development of appropriate norms for the current development) 2h
  · Design    · Specific design 2h
  · Coding    · Specific coding 6h
  · Code Review   · Code Review 2h
  · Test    · Test (self-test, modify the code, submit modifications) 4h
Reporting report 6h
  · Test Report   · testing report 2h
  · Size Measurement   · Computing workload 2h
  · Postmortem & Process Improvement Plan   · Hindsight, and propose process improvement plan 2h
total 28h

Module Design and Implementation

1. The map file format designed
to make the file easy to maintain, but also to facilitate the program parses the data map file, the file format of the form I designed for:

地铁线1,站点1,站点2,站点3,...,站点n\r\n
地铁线2,站点1,站点2,站点3,...,站点n\r\n
说明:文件中的每一行表示一条地铁线,通过\r\n分割
      通过逗号分割每一行字符串,分割后的字符串数组的第一个字符串为线路名称,后面的字符串为地铁线路按顺序的对应站点。

2. Module Design

  • Command parsing module: accept parameters into the command line when running the correct parameters are extracted, and can ignore the error parameters give prompt response if necessary.

    Specific procedures: through all the parameters, determines whether the command belongs, if the corresponding command, the extract command parameter value corresponding to the back, if the parameter value is not extracted in the prompt command must be an error message, in order to complete all the processing parameters Finally, return to the command and extract the corresponding parameters.

  • Metro map analysis module:

    Object (1) Analysis of the project involved, including the site, subway line, the subway route map, the path (a line of two sites), define the following configuration.

    Sites

     class Station {
        public:
            string StationName;//站点名称
            vector<string> BelongTo ;//地铁线的名称
            vector<int> IndexOfLine;//对应的地铁线上的站序号
            bool Visited;//是否已被访问
     };
地铁线路
    template<class T> class Line 
    {
    public:
        string LineName;
        vector<T> Stations;
    };
地铁线路图
    class Map {
        public:
            //所有的站点
            map<string, Station> Stations;
            //所有的地铁线
            map<string, Line<Station>> Lines;
    };
路径
    class Path{
        public:
            int Start;//线路段开始序号
            int End;//线路段结束序号
            int Next;//下一段序号
            Line<Station> PathLine;//当前地铁线
    };
(2)读入地图文件中的字符串数据,进行字符串分割并创建上面列出的一系列对象,作为后续线路查询和线路搜索任务的数据。
  • Line query module:

    vector stations. Specific process is as follows:

    (1) FIG objects traverse subway lines,

    (2) determine whether the current line is equal to the line StationName entered name,

    (3) If the object is returned equal Line.

  • Line search module:
    receives the name of the starting point and the terminal station input, multi-output subway line path vector <vector > Paths, there may be a plurality of lines of the same length. Specific process is as follows:

    (1) Firstly Stations subway map object, find the corresponding subway line directly by name,

    (2) a corresponding site as a starting point for traversal depth: search direction in which its two lines, one for each forward a search site, the number of recording path through the site, adding a new path through the transfer point (in other by two line directions) until reaching the corresponding end point,

    (3) record the path of each subway line passes, a return path of the array, that is, the shortest path we want to search. This path may be more than one.

  • IO operation module:

    (1) reads the map file: each row of data array of strings input map file path, output file.

    (2) The results written to the file: The results of the processing module output (vector stations or vector <vector > Paths), format the results into demand requirements, written to the output file.

  • Control module:
    The main role of this module is to link the various modules to form a complete program, which frame substantially as shown below:

    Overall framework

Program Analysis and Optimization

//TODO:分析思路、优化手段

unit test

单元测试部分,我们将每个模块视为一个单元,对模块暴露的接口进行测试,在进行单元测试的时候,很有必要根据模块的具体功能需求,按照白盒测试用例的设计思路采用语句覆盖、判定覆盖、条件覆盖、判定条件覆盖、条件组合、路径覆盖等方法尽可能对代码的逻辑路径进行覆盖测试。

//TODO:列举设计的单元测试用例

Exception handling instructions

  • Parameter Error Exception: For unsupported command prompt type response; command corresponding to the case of failure a prompt response to the number of parameters.
  • IO Exception: For operating the file, the file exists before detection, then open the file; capturing abnormal response when writing to the file, and prompts.
  • Null pointer exception: for checking all pointers null pointer type, then use.

Test Case

1. Test Case Design

黑盒测试用例的设计方法多种多样,本次项目主要采用了等价类划分法、边界值分析法、错误推测法等进行用例的设计。
  • Equivalence partitioning method: The test range is divided into several subsets do not want to pay, and their union is complete works, selected from a plurality of representative values ​​as a subset of each test case.

  • Boundary value analysis: extensive testing experience tells us that a lot of errors occur at the boundaries of the input range, rather than occurring inside the input and output range. Therefore, design test cases for a variety of border situations, can find out more errors.
  • Error reckoning: in the test program, people can speculate based on experience or intuition programs that may exist in a variety of error, which has targeted inspection method to write test cases these errors. This approach has no fixed form, relying on experience and intuition, very often, we will unconsciously use to.

2. Test Case

 依据上面的用例设计方法,设计了一些测试用例,下表中列举了部分用例:
No. title Pre-conditions Entry Steps expected results
1 The right to access lines 1. Can run on the current testing system
2. line query exists in the map file
subway.exe -a 1号线 -map subway.txt -o station.txt 1. Enter command
2. Observation command output folder and file directory station.txt
3. Comparative Results
1. Procedure no errors
Command line no error message
3.station.txt correct file format written by line 1 all the sites, and the correct order (all site information is omitted here)
2 Query line error, the line does not exist 1.能在当前测试系统上运行
2.查询的线路不存在于地图文件中
subway.exe -a 20号线 -map subway.txt -o station.txt 1.输入命令
2.观察命令行输出及程序文件夹目录的station.txt文件
3.对比结果
1.程序没有出错
2.命令行提示"没有要查找的地铁线"
3.station.txt文件不存在或者数据为空
3 查询线路错误,缺少必要参数-o 1.能在当前测试系统上运行 subway.exe -a 1号线 -map subway.txt 1.输入命令
2.观察命令行输出及程序文件夹目录的station.txt文件
3.对比结果
1.程序没有出错
2.命令行提示"缺少必要的参数-o"
3.station.txt文件不存在或者数据为空
4 查询线路错误,缺少必要参数,地图文件路径 1.能在当前测试系统上运行 subway.exe -a 1号线 -map -o station.txt 1.输入命令
2.观察命令行输出及程序文件夹目录的station.txt文件
3.对比结果
1.程序没有出错
2.命令行提示"缺少地图文件路径"
3.station.txt文件不存在或者数据为空
5 查询线路错误,缺少必要参数,输出结果文件路径 1.能在当前测试系统上运行 subway.exe -a 1号线 -map subway.txt -o 1.输入命令
2.观察命令行输出
3.对比结果
1.程序没有出错
2.命令行提示"缺少输出结果文件路径"
6 正确搜索路径,单条地铁线 1.能在当前测试系统上运行 subway.exe -b 刘园 洪湖里 -map subway.txt -o routine.txt 1.输入命令
2.观察命令行输出
3.对比结果
1. The program is not error
Command line error message
3.routine.txt file in the correct format output by the No. 1 line and all the information from the site to Liu Honghu Park Lane
7 Correct search path, two subway lines 1. Can run on the current testing system subway.exe -b Honghuli Fuxing Road -map subway.txt -o routine.txt 1. Enter command
2. Observation command output
3. Comparative Results
1. The program is not error
Command line error message
3.routine.txt file in the correct format according to the output: Line 1 Honghuli West Station Line 6 Fuxing Road
8 Correct search path, no line up 1 run on the current test system
new line 2. The map file a line 20, the line and other lines which do not transfer station, and there is a station on the line Century
subway.exe -b Honghuli Century City -map subway.txt -o routine.txt 1. Enter command
2. Observation command output
3. Comparative Results
1. The program is not error
Command line "not up to the line"
3.routine.txt file does not exist or is empty
9 Search path error, lack of necessary parameters -o 1. Can run on the current testing system subway.exe -b Honghuli Fuxing Road -map subway.txt 1. Enter command
2. Observation command output
3. Comparative Results
1. The program is not error
2. command-line prompt "lack the necessary parameters -o"
10 Search path error, lack of necessary parameters, the output file path 1. Can run on the current testing system subway.exe -b Honghuli Fuxing Road -map subway.txt 1. Enter command
2. Observation command output
3. Comparative Results
1. The program is not error
2. Command Prompt "Missing output file path"

Experiences

//TODO:培训完后再补充心得体会。

Show results

Query line

Route Planning

Currently testing is not needed to optimize the full name and click Open GitHub project address

Guess you like

Origin www.cnblogs.com/harry240/p/11221315.html