Mutation rule supplementing method and device based on genetic algorithm

文档序号:1890461 发布日期:2021-11-26 浏览:21次 中文

阅读说明:本技术 基于遗传算法的变异规则补充方法及装置 (Mutation rule supplementing method and device based on genetic algorithm ) 是由 文弘扬 熊小庆 王睿 周朝信 于 2021-09-01 设计创作,主要内容包括:本发明公开了一种基于遗传算法的变异规则补充方法及装置,可用于金融领域或其他技术领域,该方法包括:获取原始变异规则种群,其中,所述原始变异规则种群包括:多个变异规则以及每个变异规则各自的预设执行状态;根据所述变异规则进行变异测试,得到每个所述变异规则各自的真实执行状态;根据适应度对所述原始变异规则种群中的变异规则进行筛选,得到筛选后的变异规则种群;进行遗传交叉,得到遗传交叉产生的变异规则;进行遗传变异,得到遗传变异产生的变异规则;将产生的变异规则加入到所述筛选后的变异规则种群中,得到遗传交叉变异后的变异规则种群。本发明有助于提高变异测试的充分性和完整性。(The invention discloses a mutation rule supplementing method and device based on a genetic algorithm, which can be used in the financial field or other technical fields, and the method comprises the following steps: obtaining an original variation rule population, wherein the original variation rule population comprises: a plurality of variation rules and a respective preset execution state of each variation rule; performing variation test according to the variation rule to obtain the respective real execution state of each variation rule; screening the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population; carrying out genetic crossing to obtain a variation rule generated by the genetic crossing; carrying out genetic variation to obtain variation rules generated by the genetic variation; and adding the generated variation rule into the screened variation rule population to obtain a variation rule population subjected to genetic cross variation. The invention is helpful for improving the sufficiency and completeness of the variation test.)

1. A mutation rule supplementing method based on a genetic algorithm is characterized by comprising the following steps:

obtaining an original variation rule population, wherein the original variation rule population comprises: a plurality of variation rules and a respective preset execution state of each variation rule;

performing variation test according to the variation rule to obtain the respective real execution state of each variation rule;

determining the fitness of each variation rule according to the preset execution state and the real execution state, and screening the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population;

performing genetic crossing on every two variation rules in the screened variation rule population based on a preset crossing probability to obtain variation rules generated by the genetic crossing;

carrying out genetic variation on a variation rule generated by genetic crossing based on a preset variation probability to obtain a variation rule generated by the genetic variation;

and adding the variation rule generated by genetic cross and the variation rule generated by genetic variation into the screened variation rule population to obtain the variation rule population subjected to genetic cross variation.

2. The genetic algorithm-based variation rule supplementing method according to claim 1, further comprising:

determining candidate variation factors according to the modification records of the program codes;

combining the candidate variation factors with variation factors in a preset initial variation factor library to generate variation rules;

adding the generated variation rule into a preset initial variation rule base;

and setting the preset execution state of the original variation rule in the initial variation rule base as pass, and setting the preset execution state of the variation rule newly added into the initial variation rule base as fail, so as to obtain an original variation rule population.

3. The genetic algorithm-based variation rule supplementing method according to claim 1, further comprising, after the obtaining of the population of variation rules after genetic cross variation:

executing n times of genetic cross variation steps to obtain a final variation rule population, wherein n is more than or equal to 1, determining an initial variation rule population when the genetic cross variation step is executed each time, performing variation test on the initial variation rule population to obtain a respective real execution state of each variation rule in the initial variation rule population, determining the fitness of each variation rule in the initial variation rule population according to the respective preset execution state and the real execution state of each variation rule in the initial variation rule population, screening the variation rules in the initial variation rule population according to the fitness to obtain a screened initial variation rule population, and performing pairwise genetic cross on the variation rules in the screened initial variation rule population based on the cross probability to obtain variation rules generated by genetic cross, and carrying out genetic variation on the variation rule generated by genetic crossing based on the variation probability to obtain the variation rule generated by the genetic variation, and adding the variation rule generated by the genetic crossing and the variation rule generated by the genetic variation into the screened initial variation rule population to obtain the variation rule population processed in the genetic crossing variation step.

4. The genetic algorithm-based variation rule supplementing method according to claim 3, wherein the determining of the initial variation rule population specifically comprises:

when the genetic cross variation step is executed for the first time, taking the variation rule population after the genetic cross variation as an initial variation rule population,

and when the genetic cross variation step is not executed for the first time, taking the processed variation rule population obtained by the last execution of the genetic cross variation step as an initial variation rule population.

5. The genetic algorithm-based variation rule supplementing method according to claim 1 or 3, further comprising:

and setting the preset execution states of the mutation rules generated by genetic crossing and the mutation rules generated by genetic mutation as failure.

6. The method of claim 2, wherein the combining the candidate mutation factors with the mutation factors in a predetermined initial mutation factor library to generate a mutation rule comprises:

determining a target variant factor from the initial variant factor library, wherein the target variant factor is a variant factor of the same type as the candidate variant factors;

and combining the candidate variation factors with each target variation factor respectively to generate variation rules.

7. A mutation rule supplementing apparatus based on a genetic algorithm, comprising:

an original variation rule population obtaining module, configured to obtain an original variation rule population, where the original variation rule population includes: a plurality of variation rules and a respective preset execution state of each variation rule;

the variation testing module is used for performing variation testing according to the variation rules to obtain the respective real execution state of each variation rule;

the population screening module is used for determining the fitness of each variation rule according to the preset execution state and the real execution state, and screening the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population;

the genetic crossing module is used for performing genetic crossing on every two variation rules in the screened variation rule population based on a preset crossing probability to obtain variation rules generated by genetic crossing;

the genetic variation module is used for carrying out genetic variation on a variation rule generated by genetic crossing based on a preset variation probability to obtain the variation rule generated by the genetic variation;

and the variant rule population generation module after genetic cross variation is used for adding the variant rules generated by genetic cross and the variant rules generated by genetic variation into the screened variant rule population to obtain the variant rule population after genetic cross variation.

8. The genetic algorithm-based variation rule supplementing apparatus according to claim 7, further comprising:

a candidate variation factor determining module for determining a candidate variation factor according to the modification record of the program code;

a variation rule generating module for combining the candidate variation factors with variation factors in a preset initial variation factor library to generate variation rules;

the variation rule adding module is used for adding the generated variation rule into a preset initial variation rule base;

and the original variation rule population generating module is used for setting the preset execution state of the original variation rule in the original variation rule base to pass, and setting the preset execution state of the variation rule newly added into the original variation rule base to fail to obtain an original variation rule population.

9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the method of any of claims 1 to 6 when executing the computer program.

10. A computer-readable storage medium, in which a computer program is stored which, when executed in a computer processor, implements the method of any one of claims 1 to 6.

Technical Field

The invention relates to the technical field of mutation testing, in particular to a mutation rule supplementing method and device based on a genetic algorithm.

Background

With the continuous emergence of internet science and technology products, the product quality directly determines the life cycle of the product, the test is used as the last threshold before the internet product enters production, the use limit of the product is directly determined by the comprehensiveness of the test, the service quality of software is verified to the maximum extent, constructive ideas and decisive instructions are provided for problem exposure, abnormal correction, improvement and debugging and the like of the product, and the software is ensured to perform stable, healthy and continuous high-quality service in a real production environment.

In the field of software testing, mutation testing is a mode of judging code effectiveness based on a mode of changing a source code, and data weakness or insufficient code function existing in unit testing is effectively revealed by modifying, adjusting and executing partial detail codes in a source program, so that the positioning and analyzing capability of developers on abnormal hidden problems of the codes is improved, and the production risk of products is reduced.

The mutation test is a test method based on code detail adjustment execution, mainly thought to be originated from the identification of instruction byte codes, and the modification and the adjustment are carried out according to the identified specific byte code identification, and the mutation test is completed by executing the mutated codes. In the conventional mutation test, a plurality of mutation rules, for example, startpath- > endith, are set to indicate that a keyword startpath in a code is modified to endith, and when performing the mutation test, a mutation test case is generated according to each mutation rule, and then each mutation test case is executed to perform the mutation test. It follows that the setting of mutation rules directly determines the sufficiency and completeness of mutation tests.

The existing mutation rules are often defined by the aid of rules, which results in a series of problems that the mutation rules in different code fields are poor in portability, relatively fixed in mutation types and the like in the existing mutation test. The problems that a mutation rule updating and expanding method is lacked and the existing mutation rule is large in limitation exist in the current mutation test, and the sufficiency and the completeness of the mutation test are difficult to guarantee by a mutation test case generated under the condition.

Disclosure of Invention

In order to solve the technical problems in the background art, the invention provides a mutation rule supplementing method and device based on a genetic algorithm.

In order to achieve the above object, according to an aspect of the present invention, there is provided a mutation rule supplementing method based on a genetic algorithm, the method including:

obtaining an original variation rule population, wherein the original variation rule population comprises: a plurality of variation rules and a respective preset execution state of each variation rule;

performing variation test according to the variation rule to obtain the respective real execution state of each variation rule;

determining the fitness of each variation rule according to the preset execution state and the real execution state, and screening the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population;

performing genetic crossing on every two variation rules in the screened variation rule population based on a preset crossing probability to obtain variation rules generated by the genetic crossing;

carrying out genetic variation on a variation rule generated by genetic crossing based on a preset variation probability to obtain a variation rule generated by the genetic variation;

and adding the variation rule generated by genetic cross and the variation rule generated by genetic variation into the screened variation rule population to obtain the variation rule population subjected to genetic cross variation.

Optionally, the genetic algorithm-based mutation rule supplementing method further includes:

determining candidate variation factors according to the modification records of the program codes;

combining the candidate variation factors with variation factors in a preset initial variation factor library to generate variation rules;

adding the generated variation rule into a preset initial variation rule base;

and setting the preset execution state of the original variation rule in the initial variation rule base as pass, and setting the preset execution state of the variation rule newly added into the initial variation rule base as fail, so as to obtain an original variation rule population.

Optionally, after obtaining the variation rule population after genetic cross variation, the method further comprises:

executing n times of genetic cross variation steps to obtain a final variation rule population, wherein n is more than or equal to 1, determining an initial variation rule population when the genetic cross variation step is executed each time, performing variation test on the initial variation rule population to obtain a respective real execution state of each variation rule in the initial variation rule population, determining the fitness of each variation rule in the initial variation rule population according to the respective preset execution state and the real execution state of each variation rule in the initial variation rule population, screening the variation rules in the initial variation rule population according to the fitness to obtain a screened initial variation rule population, and performing pairwise genetic cross on the variation rules in the screened initial variation rule population based on the cross probability to obtain variation rules generated by genetic cross, and carrying out genetic variation on the variation rule generated by genetic crossing based on the variation probability to obtain the variation rule generated by the genetic variation, and adding the variation rule generated by the genetic crossing and the variation rule generated by the genetic variation into the screened initial variation rule population to obtain the variation rule population processed in the genetic crossing variation step.

Optionally, the determining the initial variation rule population specifically includes:

when the genetic cross variation step is executed for the first time, taking the variation rule population after the genetic cross variation as an initial variation rule population;

and when the genetic cross variation step is not executed for the first time, taking the processed variation rule population obtained by the last execution of the genetic cross variation step as an initial variation rule population.

Optionally, the genetic algorithm-based mutation rule supplementing method further includes:

and setting the preset execution states of the mutation rules generated by genetic crossing and the mutation rules generated by genetic mutation as failure.

Optionally, the combining the candidate variation factors with variation factors in a preset initial variation factor library to generate a variation rule specifically includes:

determining a target variant factor from the initial variant factor library, wherein the target variant factor is a variant factor of the same type as the candidate variant factors;

and combining the candidate variation factors with each target variation factor respectively to generate variation rules.

In order to achieve the above object, according to another aspect of the present invention, there is provided a mutation rule complementing apparatus based on a genetic algorithm, the apparatus including:

an original variation rule population obtaining module, configured to obtain an original variation rule population, where the original variation rule population includes: a plurality of variation rules and a respective preset execution state of each variation rule;

the variation testing module is used for performing variation testing according to the variation rules to obtain the respective real execution state of each variation rule;

the population screening module is used for determining the fitness of each variation rule according to the preset execution state and the real execution state, and screening the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population;

the genetic crossing module is used for performing genetic crossing on every two variation rules in the screened variation rule population based on a preset crossing probability to obtain variation rules generated by genetic crossing;

the genetic variation module is used for carrying out genetic variation on a variation rule generated by genetic crossing based on a preset variation probability to obtain the variation rule generated by the genetic variation;

and the variant rule population generation module after genetic cross variation is used for adding the variant rules generated by genetic cross and the variant rules generated by genetic variation into the screened variant rule population to obtain the variant rule population after genetic cross variation.

Optionally, the mutation rule supplementing device based on the genetic algorithm further includes:

a candidate variation factor determining module for determining a candidate variation factor according to the modification record of the program code;

a variation rule generating module for combining the candidate variation factors with variation factors in a preset initial variation factor library to generate variation rules;

the variation rule adding module is used for adding the generated variation rule into a preset initial variation rule base;

and the original variation rule population generating module is used for setting the preset execution state of the original variation rule in the original variation rule base to pass, and setting the preset execution state of the variation rule newly added into the original variation rule base to fail to obtain an original variation rule population.

In order to achieve the above object, according to another aspect of the present invention, there is also provided a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the genetic algorithm based mutation rule supplementing method when executing the computer program.

In order to achieve the above object, according to another aspect of the present invention, there is also provided a computer-readable storage medium storing a computer program which, when executed in a computer processor, implements the steps in the above genetic algorithm-based mutation rule supplementing method.

The invention has the beneficial effects that:

according to the embodiment of the invention, the variation rules in the original variation rule population are screened through the fitness, and then the new variation rules are generated through genetic crossing and genetic variation to supplement the original variation rule population, so that the number of variation rules is effectively increased, and the sufficiency and integrity of variation tests are improved.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts. In the drawings:

FIG. 1 is a first flowchart of a mutation rule supplementing method based on a genetic algorithm according to an embodiment of the present invention;

FIG. 2 is a second flowchart of a mutation rule supplementing method based on genetic algorithm according to an embodiment of the present invention;

FIG. 3 is a flow chart of determining candidate variation factors according to an embodiment of the present invention;

FIG. 4 is a first block diagram of a mutation rule supplementing apparatus based on a genetic algorithm according to an embodiment of the present invention;

FIG. 5 is a second block diagram of a mutation rule complementing apparatus based on a genetic algorithm according to an embodiment of the present invention;

FIG. 6 is a schematic diagram of a computer device according to an embodiment of the present invention.

Detailed Description

In order to make the technical solutions of the present invention better understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.

It should be noted that the terms "comprises" and "comprising," and any variations thereof, in the description and claims of the present invention and the above-described drawings, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.

It should be noted that the embodiments and features of the embodiments may be combined with each other without conflict. The present invention will be described in detail below with reference to the embodiments with reference to the attached drawings.

It should be noted that the mutation rule supplementing method and device based on the genetic algorithm of the present invention can be applied to the financial field and can also be applied to other technical fields.

The invention provides a mutation rule supplementing method based on a genetic algorithm, which is mainly characterized in that a git code submitted by a developer is scanned, a modification part is scanned, positioned, analyzed and screened to obtain the position of a corresponding optimal mutation factor to be supplemented and information of a candidate mutation factor type, and the mutation rule is supplemented through the genetic algorithm, so that the updating and supplementing of the mutation rule in a customized mutation test of a project to be tested are automatically completed, and the comprehensiveness of the mutation test is improved.

Fig. 1 is a first flowchart of a genetic algorithm-based mutation rule complementing method according to an embodiment of the present invention, and as shown in fig. 1, the genetic algorithm-based mutation rule complementing method according to an embodiment of the present invention includes steps S101 to S106.

Step S101, obtaining an original variation rule population, wherein the original variation rule population includes: a plurality of variation rules and a respective predetermined execution state of each variation rule.

In an embodiment of the present invention, the specific generation process of the original variation rule population can be seen in steps S201 to S204.

In an embodiment of the invention, the predetermined execution state includes a pass (true) and a fail (false), the pass (true) indicates that the result of the mutation test corresponding to the mutation rule is a pass, and the fail (false) indicates that the result of the mutation test corresponding to the mutation rule is a fail.

In the invention, the mutation test is a test method based on code detail adjustment execution, mainly thought to be originated from the identification of instruction byte codes, and the adjustment and modification are carried out according to the identified specific byte code identification, and the mutation test is completed by executing the mutated codes. In the existing mutation test, setting a plurality of mutation rules, such as startpath- > endpath, indicates that the keyword startpath in the code is modified to endpath.

And step S102, performing variation test according to the variation rules to obtain respective real execution states of the variation rules.

In an embodiment of the present invention, during the mutation test, a mutation test case corresponding to each mutation rule is generated, and then each mutation test case is executed one by one to perform the mutation test, so as to obtain the real execution state of each mutation rule. The real execution state includes pass (true) and fail (false).

In an embodiment of the present invention, if the real execution state is consistent with the preset execution state, the variation is valid, and the threshold is set to be 0, otherwise, the variation is considered to be invalid, and the threshold is set to be 1, and the statistical dimension is used as the first dimension of the fitness calculation.

Step S103, determining the fitness of each variation rule according to the preset execution state and the real execution state, and screening the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population.

In an embodiment of the invention, after each mutation test is executed, the position of the mutation point is stored, the history information executed by different mutation points is stored in a queue stack pressing mode, the history information is stored in a stack pressing table, fitness statistics is carried out after all the execution is finished, and the fitness value of each mutation rule in the current population is calculated.

In one embodiment of the invention, the fitness may be calculated by the following fitness function:

wherein f (x) is fitness, x is default execution state, y is true execution state, count (z) is the number of variant rules that exist in the stack,for attenuation over-parameters, 0.8 may be set.

And S104, performing genetic crossing on every two variation rules in the screened variation rule population based on a preset crossing probability to obtain the variation rules generated by the genetic crossing.

In one embodiment of the invention, the variation rules in the screened variation rule population are equally divided into two groups, namely a parent chain and a parent chain. And further carrying out pairwise crossing treatment on the variation rules in the parent chain and the parent chain to obtain the variation rules generated by genetic crossing.

In one embodiment of the invention, the cross probability k is set to be 0.8, the invention carries out the crossing of the parent chain and the parent chain in a random number mode if the generated random number is larger than the value of k, and the cross point is selected as a random node in an execution program. Otherwise, no crossover is performed.

Step S105, performing genetic variation on the variation rule generated by genetic crossing based on the preset variation probability to obtain the variation rule generated by the genetic variation.

In an embodiment of the present invention, after genetic crossing is completed, the present invention judges the total number of variation rules one by one, sets the variation probability u to be 0.8, performs variation processing on the variation rule when u is greater than u by means of a random number generation method, selects any candidate variation point existing in the current program for the variation point, and selects any value of the same type in the variation list for replacement by the variation value to complete the variation. Otherwise, the mutation rule is retained and no mutation processing is performed.

And step S106, adding the variation rule generated by genetic cross and the variation rule generated by genetic variation into the screened variation rule population to obtain the variation rule population subjected to genetic cross variation.

In one embodiment of the present invention, the present invention further sets the mutation rules generated by genetic crossover and the preset execution states of the mutation rules generated by genetic mutation as failures when generating the mutation rule population after genetic crossover mutation.

In an embodiment of the present invention, the present invention may iteratively execute the steps S102 to S106 for a plurality of times to obtain a final variation rule population.

Specifically, the method executes n times of genetic cross variation steps to obtain a final variation rule population, wherein n is more than or equal to 1, when the genetic cross variation step is executed each time, an initial variation rule population is determined, the initial variation rule population is subjected to variation test to obtain the respective real execution state of each variation rule in the initial variation rule population, the fitness of each variation rule in the initial variation rule population is determined according to the respective preset execution state and the real execution state of each variation rule in the initial variation rule population, the variation rules in the initial variation rule population are screened according to the fitness to obtain a screened initial variation rule population, and genetic cross is performed on every two variation rules in the screened initial variation rule population based on the cross probability, and obtaining a variation rule generated by genetic crossing, performing genetic variation on the variation rule generated by the genetic crossing based on the variation probability to obtain a variation rule generated by the genetic variation, and adding the variation rule generated by the genetic crossing and the variation rule generated by the genetic variation into the screened initial variation rule population to obtain the variation rule population processed by the genetic crossing variation step.

In an embodiment of the present invention, when the mutation rule generated by genetic crossover and the mutation rule generated by genetic variation are added to the initial mutation rule population after screening, the present invention further sets the preset execution states of the mutation rule generated by genetic crossover and the mutation rule generated by genetic variation as failure.

In an embodiment of the present invention, the determining the initial variation rule population specifically includes:

when the genetic cross variation step is executed for the first time, taking the variation rule population after the genetic cross variation as an initial variation rule population;

and when the genetic cross variation step is not executed for the first time, taking the processed variation rule population obtained by the last execution of the genetic cross variation step as an initial variation rule population.

Fig. 2 is a second flowchart of a mutation rule supplementing method based on a genetic algorithm according to an embodiment of the present invention, as shown in fig. 2, in an embodiment of the present invention, the original mutation rule population in step S101 is generated through steps S201 to S204.

In step S201, candidate mutation factors are determined according to the modified record of the program code.

In a specific embodiment of the invention, the method can pull developers from the Git warehouse to submit code information, so that each submission is developed as a unit dimension, and records submitted twice continuously under the unit dimension are collected as a single candidate variation factor extraction basis. And then carrying out similarity comparison on the records of two continuous times, executing a behavior standard by unit, and after the records submitted twice are compared, only the unit content correction part in the submitted records of the row is used as a mutation factor to be candidate.

For example, "if (0,6)). equals ('202006')," if (0,6) in the double commit record, startWith ('202006'), "this part is a unit fix, the corrected part is a keyword equals, and the keyword is replaced with the startWith, the corresponding mutation rule is startWith- > equals, and the startWith is used as a candidate mutation factor.

Step S202, combining the candidate variation factors with the variation factors in the preset initial variation factor library to generate a variation rule.

In one embodiment, the initial variant factor library comprises a plurality of variant factors. The present invention combines candidate variants with variants in the initial variant pool to generate a plurality of new variant rules.

In an embodiment of the present invention, the step specifically includes:

determining a target variant factor from the initial variant factor library, wherein the target variant factor is a variant factor of the same type as the candidate variant factors; and combining the candidate variation factors with each target variation factor respectively to generate variation rules.

In one embodiment of the present invention, the candidate variation factors are matched with the variation factors of the same type in the existing initial variation factor library, that is, the initial variation factor library is initialized as a parameter, and two-dimensional mapping processing is performed.

For example, the candidate mutation factor is startpath, the initial mutation factor library contains the mutation factors endpath, polypeptides and the like of the same type, and the present invention generates new mutation rules such as startpath- > endpath, startpath- > polypeptides and the like by mapping.

Step S203, adding the generated mutation rule into a preset initial mutation rule base.

In an embodiment of the present invention, the initial variation rule base includes a plurality of variation rules, and the initial variation rule base is established according to each variation factor in the initial variation factor base.

Step S204, setting the preset execution state of the original variation rule in the initial variation rule base as pass, and setting the preset execution state of the variation rule newly added to the initial variation rule base as fail, to obtain an original variation rule population.

In the process of developing the programmed factory mode, code development, sharing, updating and other operations are carried out on source codes through Git, corresponding submitted code change lines and corresponding line numbers can be obtained through Git diff commands and the like, and differential submitted data are obtained by screening change lines submitted each time in history. And comparing the code single sentence by taking two continuous submitted records as a unit, and screening the lowest modification unit, wherein if the code submitted for the first time is as follows:

Map<String,Object>featureMap=extractFeatures(seedCase,ignoreConf);

the second submission of the modified code is:

Map<String,Object>featureMap=extractAttentionFeatures(seedCase,ignoreConf);

after comparison, the developer in the two groups of codes changes by using the initialized function, and the corresponding mutation rule is ExtractationFatures () - > ExtractFeatures (), namely, the newly added candidate mutation factor ExtractationFaturesThe change is a call function change, and when the change factor is added, the type of the parameter in the function needs to be confirmed, and the type of the parameter needs to be expanded.

FIG. 3 is a screening process of new variation candidate factors in the functional part, in which the non-functional alteration part can be directly added into the existing variation factor library and used as a part of the new variation factors, and then further expanded in the genetic algorithm.

The function part judges that the parameter mode is changed, the change part can also be directly added into a variation library, and the part without the parameter increasing and decreasing mode needs to judge whether the parameter is changed, because Git is used for code inspection, any slight change, such as newly added space sum is formed; "etc. will trigger the gitdiff command to scan out, so only the part of the function where the parameter input value is adjusted is kept, each group of parameter types is scanned and added into the candidate mutation factor library, and the further mutation factor supplement processing is completed through the subsequent genetic algorithm.

In one embodiment of the invention, because the inheritance, crossing and mutation processes are all based on the change line (number) of the Git pull code, the original program line cannot be subjected to gene coding in a binary coding mode.

The genetic algorithm of the invention is mainly based on 4 steps, firstly, an original variation rule population is needed to be generated, 2-dimensional mapping is carried out on the candidate variation factors and the similar type variation factors in the original variation factor library aiming at the original variation factor library, and only one candidate variation factor is adjusted in each newly-increased variation rule. If there are 2 types of candidate variation factors, namely integer (int) and String (String), respectively, wherein there are 5 groups of variable items in the integer variable list and 3 groups of variable items in the String type variation category, then there are 8 variation rules in total generated by 5+3 according to that each variation test case has only one group of factor variation requirements. And presetting the execution preset result of the generated mutation rule as failure.

And population adaptive screening, namely generating a variation test case according to each variation rule in the original variation rule population, calling and running the generated test cases in an automatic test case execution mode, performing statistical calculation on the running result and the execution condition of each group through a fitness function, performing genetic screening on the calculated result in a roulette mode, and reserving an adaptive gene population (variation rule population) as high as possible.

And (3) genetic crossing, after one round of fitness screening, equally dividing all gene chains, generating two groups of a parent chain and a parent chain by taking each mutation rule as one gene chain, crossing every two groups, setting the crossing probability k to be 0.8, crossing the parent chain and the parent chain in a random number mode if the generated random number is greater than the value k, and selecting the crossing point as a random node in an execution program. Otherwise, no crossover is performed.

And (3) genetic variation, after the crossing is finished, judging the total number of gene chains one by one, setting the variation probability u to be 0.8, performing variation treatment on the gene chains when the variation rule is greater than u in a random number generation mode, selecting any candidate variation point existing in the current program by the variation point, and replacing any value of the same type in a variation list by the variation value to finish the variation. Otherwise, the gene chain is reserved and not subjected to mutation treatment.

It can be seen from the above embodiments that, in order to reduce the labor overhead and time cost for updating the variation factors and the variation rules in the variation test, improve the efficiency of the variation test, and supplement the sufficiency of the test, the present invention provides a method for supplementing the variation rules based on the genetic algorithm, which can effectively improve the updating efficiency of the variation factors, and specifically achieve the following beneficial effects:

1. the method directly submits the records by the developers in the scanning Git, scans each group of change records, analyzes and obtains the difference information, fully considers the full change details involved in the program development, and supplements the variation characteristics of different programs in a personalized way.

2. The mutation rule is supplemented and updated by using the automatic preferred screening mutation rule, the high-value mutation characteristic is searched to the greatest extent, the random mutation characteristic of the mutation test is fully combined in the genetic mutation process, and the test efficiency of the mutation test is improved.

3. The updating processing of the invention can increase the iteration mode, and the mutation rule can be supplemented by setting the timing or setting the quantitative times submitting mode, so that the mutation rule can be continuously learned and supplemented, the labor cost is reduced, and the efficiency is improved.

It should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer-executable instructions and that, although a logical order is illustrated in the flowcharts, in some cases, the steps illustrated or described may be performed in an order different than presented herein.

Based on the same inventive concept, the embodiment of the present invention further provides a mutation rule supplementing device based on a genetic algorithm, which can be used to implement the mutation rule supplementing method based on a genetic algorithm described in the above embodiments, as described in the following embodiments. Because the principle of solving the problem of the mutation rule supplementing device based on the genetic algorithm is similar to that of the mutation rule supplementing method based on the genetic algorithm, the embodiment of the mutation rule supplementing device based on the genetic algorithm can be referred to as the embodiment of the mutation rule supplementing method based on the genetic algorithm, and repeated parts are not described again. As used hereinafter, the term "unit" or "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.

Fig. 4 is a first block diagram of a mutation rule complementing device based on a genetic algorithm according to an embodiment of the present invention, as shown in fig. 4, in an embodiment of the present invention, the mutation rule complementing device based on a genetic algorithm according to an embodiment of the present invention includes:

an original variation rule population obtaining module 1, configured to obtain an original variation rule population, where the original variation rule population includes: a plurality of variation rules and a respective preset execution state of each variation rule;

a variation testing module 2, configured to perform a variation test according to the variation rule to obtain a respective real execution state of each variation rule;

the population screening module 3 is configured to determine fitness of each variation rule according to the preset execution state and the real execution state, and screen the variation rules in the original variation rule population according to the fitness to obtain a screened variation rule population;

the genetic crossing module 4 is used for performing genetic crossing on every two mutation rules in the screened mutation rule population based on a preset crossing probability to obtain mutation rules generated by genetic crossing;

a genetic variation module 5, configured to perform genetic variation on a variation rule generated by genetic crossing based on a preset variation probability to obtain a variation rule generated by genetic variation;

and a variant rule population generation module 6 after genetic cross variation, configured to add the variant rule generated by genetic cross and the variant rule generated by genetic variation to the screened variant rule population to obtain a variant rule population after genetic cross variation.

Fig. 5 is a second block diagram of a mutation rule complementing device based on genetic algorithm according to an embodiment of the present invention, as shown in fig. 5, in an embodiment of the present invention, the mutation rule complementing device based on genetic algorithm further includes:

a candidate variation factor determining module 7, configured to determine a candidate variation factor according to the modification record of the program code;

a variation rule generating module 8, configured to combine the candidate variation factors with variation factors in a preset initial variation factor library to generate a variation rule;

a variation rule adding module 9, configured to add the generated variation rule to a preset initial variation rule base;

and an original variation rule population generating module 10, configured to set a preset execution state of an original variation rule in the initial variation rule base as pass, and set a preset execution state of a variation rule newly added to the initial variation rule base as fail, so as to obtain an original variation rule population.

In an embodiment of the present invention, the mutation rule supplementing apparatus based on genetic algorithm further includes:

an iteration execution module, configured to execute n times of genetic cross variation steps to obtain a final variation rule population, where n is greater than or equal to 1, where each time a genetic cross variation step is executed, an initial variation rule population is determined, a variation test is performed on the initial variation rule population to obtain a true execution state of each variation rule in the initial variation rule population, a fitness of each variation rule in the initial variation rule population is determined according to a preset execution state of each variation rule in the initial variation rule population and the true execution state, the variation rules in the initial variation rule population are screened according to the fitness to obtain a screened initial variation rule population, and genetic cross is performed on two variation rules in the screened initial variation rule population based on the cross probability, and obtaining a variation rule generated by genetic crossing, performing genetic variation on the variation rule generated by the genetic crossing based on the variation probability to obtain a variation rule generated by the genetic variation, and adding the variation rule generated by the genetic crossing and the variation rule generated by the genetic variation into the screened initial variation rule population to obtain the variation rule population processed by the genetic crossing variation step.

In an embodiment of the present invention, the iteration executing module is specifically configured to:

when the genetic cross variation step is executed for the first time, taking the variation rule population after the genetic cross variation as an initial variation rule population;

and when the genetic cross variation step is not executed for the first time, taking the processed variation rule population obtained by the last execution of the genetic cross variation step as an initial variation rule population.

In an embodiment of the present invention, the mutation rule supplementing apparatus based on genetic algorithm further includes:

and the preset execution state setting module is used for setting the preset execution states of the variation rule generated by the genetic crossover and the variation rule generated by the genetic variation as failures.

In an embodiment of the present invention, the mutation rule generating module 8 includes:

a same-type variation factor determining unit, configured to determine a target variation factor from the initial variation factor library, where the target variation factor is a variation factor of the same type as the candidate variation factors;

and a generation unit configured to generate a mutation rule by combining the candidate mutation factors with each of the target mutation factors.

To achieve the above object, according to another aspect of the present application, there is also provided a computer apparatus. As shown in fig. 6, the computer device comprises a memory, a processor, a communication interface and a communication bus, wherein a computer program that can be run on the processor is stored in the memory, and the steps of the method of the above embodiment are realized when the processor executes the computer program.

The processor may be a Central Processing Unit (CPU). The Processor may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, or a combination thereof.

The memory, which is a non-transitory computer readable storage medium, may be used to store non-transitory software programs, non-transitory computer executable programs, and units, such as the corresponding program units in the above-described method embodiments of the present invention. The processor executes various functional applications of the processor and the processing of the work data by executing the non-transitory software programs, instructions and modules stored in the memory, that is, the method in the above method embodiment is realized.

The memory may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created by the processor, and the like. Further, the memory may include high speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid state storage device. In some embodiments, the memory optionally includes memory located remotely from the processor, and such remote memory may be coupled to the processor via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.

The one or more units are stored in the memory and when executed by the processor perform the method of the above embodiments.

The specific details of the computer device may be understood by referring to the corresponding related descriptions and effects in the above embodiments, and are not described herein again.

In order to achieve the above object, according to another aspect of the present application, there is also provided a computer-readable storage medium storing a computer program which, when executed in a computer processor, implements the steps in the above genetic algorithm-based mutation rule supplementing method. It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic Disk, an optical Disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a Flash Memory (Flash Memory), a Hard Disk (Hard Disk Drive, abbreviated as HDD) or a Solid State Drive (SSD), etc.; the storage medium may also comprise a combination of memories of the kind described above.

It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and they may alternatively be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, or fabricated separately as individual integrated circuit modules, or fabricated as a single integrated circuit module from multiple modules or steps. Thus, the present invention is not limited to any specific combination of hardware and software.

The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

19页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:基于依据池的知识管理方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!