To see the whole version, go to the End and see HTML version on Github.com.
Development BlogContentsPSP FormIdeas of Problem-solvingDesign and Implement ProcessesCode Descriptionmain.pycommon.pyspecific_c.pyUnit TestScreenshots and DescriptionTest DataResultCoverage OptimizationPerformance TestingSummaryEnd
Process Stages | Estimated Time(min) | Actual Time(min) |
---|---|---|
Analyze Problem | 10 | 5 |
Planning Development | 10 | 5 |
Modelling Project | 30 | 15 |
Design Basic Framework | 20 | 20 |
Design & Develop Assistant Tools | 30 | 120 |
Review Assistant Tools | 10 | 30 |
Develop Prototype working on 1st Level | 30 | 40 |
Review & Fortify Program | 10 | 30 |
Design 2nd Level Program | 30 | 40 |
Develop & Review 2nd Level Program | 30 | 200 |
Design 3rd Level Program | 30 | 20 |
Design 4th Level Program | 40 | 80 |
Develop & Review 3rd & 4th Level Program | 80 | 200 |
Refine Details | 20 | 5 |
Final Test | 20 | 10 |
Reporting | 40 | 70 |
Summarizing | 30 | 10 |
Total Time | 470 | 900 |
Problem is given in four level and that's good for Incremental model.
Idea of develop solution:
Solution steps:
My project used many to assist the development process. But those do nothing with problem-solving, so I will not explain them here.
Here is key codes and their explanation:
This is the entrance of whole program. This file contains and leads to the rest.
xxxxxxxxxx
101# Open File Preparation
2 f = None
3 try:
4 # get the file name
5 fileName = sys.argv[1]
6 except IndexError as ie:
7 estr = OINFOHEADER + f'No file input, no first parameter given. {ie}'
8 raise IndexError(estr)
9 # get the program directory
10 programDir = osp.dirname(sys.argv[0])
xxxxxxxxxx
41# Check ext
2 fileExt: common.ExtClass = common.ExtClass()
3 # determine ext
4 fileExt.extSelect(fileName)
xxxxxxxxxx
61# open file
2 try:
3 f = open(fileName)
4 except FileNotFoundError as fe:
5 estr = OINFOHEADER + f'{fe}'
6 raise FileNotFoundError(estr)
xxxxxxxxxx
101# read keywords
2 keys = []
3 try:
4 with open(osp.join(programDir, f'keywords_{fileExt.ext}.txt')) as fkey:
5 # with open(programDir + dirsep + f'keywords_{fileExt.ext}.txt') as fkey:
6 t = fkey.read()
7 keys = t.split()
8 except FileNotFoundError as fe:
9 estr = OINFOHEADER + f'{fe}'
10 raise FileNotFoundError(estr)
xxxxxxxxxx
21# read file data
2 strs = f.readlines()
xxxxxxxxxx
31# work of 1st level
2 keycnt, moreinfo = common.countKw(keys, strs)
3 print('total num: ', keycnt)
xxxxxxxxxx
61# language-specific part of solution's entrance (of .c file)
2 speMDic = {
3 'c': specific_c,
4 'cpp': specific_cpp
5 }
6 speMDic[fileExt.ext].entrance(keys, strs, moreinfo)
This file contains the common parts of codes, i.e. the public codes for all modules.
xxxxxxxxxx
201# Class and method for storing and determining ext
2class ExtClass():
3
4 ext = None
5 exti = 0
6 mode: DevMode = sampleModeCommon
7
8 def __init__(self, mode: DevMode=None):
9 ...
10
11 def extSelect(self, fileName:str=''):
12 # debug code
13 ...
14
15 # set ext
16 t1 = fileName.rsplit(sep='.', maxsplit=3)
17 self.ext = t1[-1]
18
19 ...
20
xxxxxxxxxx
251# This function count keywords in strings from the file.
2def countKw(keys, strs:list):
3 ...
4
5 for i in strs:
6 cnt1 = 0
7 for j in keys:
8 i: str
9 a = k = 0
10 while True:
11 a = i.find(j,a)
12 if a == -1:
13 break
14 a += keylength[j]
15 if i[a].isalpha() is False:
16 # found a keyword here
17 k += 1
18 # pairs of location prepared for more operation
19 p = [idi, a - keylength[j], j]
20 locations.append(p)
21 cnt1 += k
22
23 cnt2 += cnt1
24 idi += 1
25 return cnt2, locations
Contains part of solutions for c language.
xxxxxxxxxx
271# addon entrance
2def entrance(pkeys, pstrs, pmoreinfo=None):
3 ...
4
5 locations = extractWordsBraces(strs, wordLocation)
6
7 # process switch-case
8 locations_SwCsBraces = extractSwCsBraces(locations)
9 SwCnt_Group = countSwCs(locations_SwCsBraces)
10
11 # output SwCs
12 print(f'switch num: ', SwCnt_Group.__len__())
13 print('case num: ', end='')
14 for i in SwCnt_Group:
15 print(i, end=' ')
16 print('')
17
18 # process if-else, if-elseif-else
19 # these codes are only designed for cases with entire braces attached to keywords.
20 locations_IfEsBraces = extractIfEsBraces(locations)
21 cnt_IfEs, cnt_IfEsifEs = countIfEs(locations_IfEsBraces)
22 cntIFES = [cnt_IfEs, cnt_IfEsifEs]
23
24 # output IFES
25 print(f'if-else num: ', cnt_IfEs)
26 print(f'if-elseif-else num: ', cnt_IfEsifEs)
27
xxxxxxxxxx
321# This function count 'switch's and each group's 'case's. Support nested structure.
2def countSwCs(plocations_SwCsBraces):
3 ...
4
5 i = 0
6 while i < length:
7 # find a 'switch', do iteration
8 if plocations_SwCsBraces[i][2]=='switch':
9 ...
10 interval = [i, endBrace+1]
11 intervals.append(interval)
12 # iterate
13 CsCntItr = countSwCs(plocations_SwCsBraces[i+1:endBrace+1])
14 SwCnt_Group.extend(CsCntItr)
15 # print(SwCnt_Group)
16 i = endBrace
17 i += 1
18
19 ...
20
21 # count 'case's of given strings
22 i = 0
23 while i < length:
24 ...
25
26 if plocations_SwCsBraces[i][2]=='case':
27 CsCnt += 1
28 i += 1
29 if CsCnt!=0:
30 SwCnt_Group.append(CsCnt)
31 return SwCnt_Group
32
xxxxxxxxxx
361# This function figures the answers of sol.3. Support nested structure.
2def countIfEs(plocations_IfEsBraces):
3 ...
4 while i < length:
5 # find a/an 'if'/'else', do iteration
6 if plocations_IfEsBraces[i][2] == 'if' or \
7 (plocations_IfEsBraces[i][2] == 'else' and plocations_IfEsBraces[i+1 if i+1 <length else i][2] != 'if'):
8 ...
9 interval = [i + 2, endBrace]
10 intervals.append(interval)
11 # iterate
12 retv = countIfEs(plocations_IfEsBraces[i + 1:endBrace + 1])
13 ...
14 cnt_IfEs += retv[0]
15 cnt_IfEsifEs += retv[1]
16 i = endBrace
17 i += 1
18
19 ...
20
21 # count cases of 'if-else' and 'if-elseif-else' of given strings
22 i = 0
23 tlength = tpifesloclist.__len__()
24 while i < tlength:
25 if tpifesloclist[i][2] == 'else':
26 if tpifesloclist[i+1 if i+1<tlength else i][2] == 'if':
27 cnt_IfEsifEs += 1
28 while i < tlength:
29 if tpifesloclist[i][2] == 'else' and tpifesloclist[i+1 if i+1<tlength else i][2] != 'if':
30 break
31 i += 1
32 elif tpifesloclist[i+1 if i+1<tlength else i][2] == '{':
33 cnt_IfEs += 1
34 i += 1
35 cntIFES = [cnt_IfEs, cnt_IfEsifEs]
36 return cntIFES
my_unit_test.py
Test file, , is copied from website. See the website at the End.
Picture shown below tells that of 4th level, i.e. the ultimate requirement. It goes to expectation.
Comment useless codes.
% ->%
In this program, I used lots of new knowledge. Software Engineering is truly a systematic engineering. Methodology is really important.
The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
The Aim of This Assignment | Note the development processes. |
MU STU ID and FZU STU ID | 20123850_832001217 |
Project on Github.com: https://github.com/LiuJiewenTT/ee308fz_lab1
URL on github.com of this passage(download): https://liujiewentt.github.io/ee308fz_lab1/development%20blog.md
URL on github.com of this passage(view with Github md): https://github.com/LiuJiewenTT/ee308fz_lab1/tree/main/development%20blog.md
URL on github.com of this passage(view as html): https://liujiewentt.github.io/ee308fz_lab1/development%20blog.html
URL on csdn.net of this passage(view as html): https://bbs.csdn.net/topics/608838406