# A Bioinspired Test Generation Method Using Discretized and Modified Bat Optimization Algorithm

^{1}

^{2}

^{3}

^{4}

^{5}

^{6}

^{7}

^{*}

## Abstract

**:**

## 1. Introduction

- Developing a bioinspired technique for automatically creating test data using the modified version of the BOA,
- Achieving more branch coverage at a faster convergence rate,
- Stable outcomes are produced by the suggested technique in different executions,
- Implementing an autonomous test generation system that is open source and free for software testers and engineers to use.

## 2. Related Work

## 3. Proposed Method

_{i}, there is a conjunctive predicate P

_{i}= C

_{1}∧ C

_{2}∧ … ∧ C

_{n}, whose conjuncts C

_{j}match the decision nodes along the test path P

_{i}. Given the path P

_{i}, the test generation method should find the test data X

_{k}which covers the P

_{i}by satisfying its predicates. The software test generation method evaluates the assignments and decision Booleans of the test path (P

_{i}). In this problem, A

_{k}is the number of assignments in P

_{i}and B

_{k}is the number of simple Booleans in the test path P

_{i}. Since test generation methods evaluate the decision expressions (assignments and decision Booleans) of the test path, the time complexity is proportional to A

_{k}+ B

_{k}. In the worst case, the problem of finding X

_{k}(test data) to Boolean satisfiability of P

_{k}can be considered an NP-complete problem [20]. Indeed, the satisfaction (coverage) of P

_{k}in the worst case is proportional to ${2}^{{B}_{k}}$.

#### 3.1. Program Source-Code Analysis

#### 3.2. Test Data Generation using BOA

Algorithm 1 Pseudocode of the suggested BOA for producing test data in program testing | |

1 | Function BAT_algorithm(n, A, fmin, fmax, alpha, gamma, fobj, maxIter) % output: [bestSolution, bestFitness] |

2 | Begin |

3 | n: Number of bats; |

4 | A: Loudness; |

5 | fmin, fmax: Frequency range; |

6 | alpha: Loudness decay; |

7 | gamma: Pulse rate; |

8 | fobj: Objective function handle; |

9 | maxIter: Maximum number of iterations; |

10 | Initialize the bat population; |

11 | Initialize the velocities; |

12 | Evaluate the initial solutions; |

13 | Find the initial best solution; |

14 | % Main loop |

15 | for iter = 1:maxIter % Update bat positions and frequencies |

16 | for i = 1:n |

17 | Update the bat frequency by Eq. (1); |

18 | Update the bat velocity by Eq. (2); |

19 | Update the bat position by Eq. (3); |

20 | % Apply the random walk with probability gamma |

21 | if rand() < gamma |

22 | bat(i) = bestSolution + randn(1, numel(fmin)) * alpha; |

23 | end |

24 | % Apply boundary constraints if necessary |

25 | bat(i) = max(bat(i), fmin); |

26 | bat(i) = min(bat(i), fmax); |

27 | Apply mutation operator on the best bat; |

28 | Evaluate new solution; |

29 | % Update best solution |

30 | if newFitness < bestFitness |

31 | bestFitness = newFitness; |

32 | bestSolution = bat(i); |

33 | end |

34 | end |

35 | % Update loudness |

36 | end |

37 | end |

_{i}speed in the X

_{i}location with the f

_{min}frequency and different wavelengths of λ and the sound loudness of A

_{i}. Sound loudness may vary from R

_{min}(the minimum amount) to R

_{max}(the maximum amount). The position of each bat indicates the input data (test data) of the program. Each bat includes position X

_{i}, pulse frequency f

_{i}, initial pulse r

_{i}, and sound loudness A

_{i}. Figure 3 shows how to encode the position of each bat in the TDG problem. The BOA typically involves several stages during each iteration. Initialization is the first stage of the BOA. In this stage, a population of bats with random positions in the search space is generated and their velocities and frequencies are randomly initialized. The fitness of each bat is evaluated using the objective function (i.e., Equation (8)). In the second stage, the bat with the best fitness value is selected as the best bat. After selecting the best bat, the velocities of bats based on their current positions and the global best solution are updated; then, the positions of bats based on their velocities are updated (using Equations (1)–(3)). In the third stage, a local solution (bat) is generated around the selected best solution. The fitness of the new bat is evaluated, and the best solution is compared to it. If the new Bat has better fitness than the current global best, the global best solution is updated. The loudness and pulse rate are updated.

_{i}and pulse rate r

_{i}. Moreover, the global optimal solution is simultaneously updated. The location of the bat (as an array) is encoded as the test data. New solutions (test data) are generated by adjusting frequency based on a fitness function, speed, and location; they are updated by using Equations (1)–(3). Here, β is considered as a random number between 0 and 1 with uniform distribution. Equation (4) was used to implement the local search stage; the location of the current best bat is modified using direct exploitation (random walk). In Equation (4), $\epsilon $ is a random number with uniform distribution from [−1, 1].

^{t}indicates the average loudness of bats’ sounds within iteration t. The sound loudness and the pulse rate within each iteration are updated by using Equations (5)–(7). Moreover, α and $y$ are used as a constant coefficient parameter, ($y>0$).

#### 3.3. Fitness Function

_{i}, the program’s several branches are selected. In this study, TS indicates a test suite that includes a set of generated test data. An input data is indicated by the variable X

_{k}$\in $ TS (1 < k < m) if there are exactly m inputs. Equation (8) is used for calculating the fitness function of test data:

_{i}) is the coefficient of the distance function (f) in Equation (9). The weight of the branch in the branch instruction is indicated by variable w

_{i}. The branch weight of a branch instruction is the summation of its nesting level and its predicate weight and is calculated using Equation (10), where w

_{i}denotes the weight of the ith branch and λ indicates the equilibrium coefficient. In the experiments, $\lambda $ is set to 0.5 [10]. The branch weight is the function of the following factors:

- Branch level (nesting level)
- Expression weigh

_{min}designates the program’s lowest branch level, which is 1 in this case. In the program, the highest branch level is indicated by the variable nl

_{max}. Each branch instruction’s level is normalized using Equation (12).

_{i}denotes the ith branch ($1\le i\le s$). The variable h indicates the number of available predicates in the respective branch. Here, c

_{j}indicates the jth conditional predicate ($1\le j\le h$) in the respective branch. The variable w

_{r}denotes the weight of an operator in the predicate whose value is determined using Table 3. The operators that could be present in the various predicates are listed in this table.

## 4. Experiment System and Results

#### 4.1. Experiment System

- Average coverage: this criterion shows the branch coverage of the created test set. The efficacy increases with the value of this criteria.
- Average generation: It represents the typical number of iterations needed for the particular method to cover all program branches. The suggested method performs better the smaller the value of this criteria is.
- Average execution time (ATE): It speaks of the typical time needed to cover every program branch. Milliseconds are used to measure this criterion (ms). The performance of the corresponding approach is inversely correlated with the value of this metric.
- Success rate (SR): It shows the ability of the algorithm to cover all branches of the program.

#### 4.2. Results and Discussion

#### 4.3. Parameter Calibration and Statistical Analysis

## 5. Conclusions

## Author Contributions

## Funding

## Data Availability Statement

## Conflicts of Interest

## References

- Khamprapai, W.; Tsai, C.-F.; Wang, P.; Tsai, C.-E. Performance of Enhanced Multiple-Searching Genetic Algorithm for Test Case Generation in Software Testing. Mathematics
**2021**, 9, 1779. [Google Scholar] [CrossRef] - Khurma, R.A.; Alsawalqah, H.; Aljarah, I.; Elaziz, M.A.; Damaševičius, R. An Enhanced Evolutionary Software Defect Prediction Method Using Island Moth Flame Optimization. Mathematics
**2021**, 9, 1722. [Google Scholar] [CrossRef] - Khari, M.; Kumar, P. An extensive evaluation of search-based software testing: A review. Soft Comput.
**2019**, 23, 1933–1946. [Google Scholar] [CrossRef] - Khoshniat, N.; Jamarani, A.; Ahmadzadeh, A.; Kashani, M.H.; Mahdipour, E. Nature-inspired metaheuristic methods in software testing. Soft Comput.
**2023**. [Google Scholar] [CrossRef] - Aleti, A.; Moser, I.; Grunske, L. Analysing the fitness landscape of search-based software testing problems. Autom. Softw. Eng.
**2017**, 24, 603–621. [Google Scholar] [CrossRef] - Khatun, S.; Rabbi, K.F.; Yaakub, C.Y.; Klaib, M.F.J. A Random search based effective algorithm for pairwise test data generation. In Proceedings of the International Conference on Electrical, Control and Computer Engineering 2011 (InECCE), Kuantan, Malaysia, 21–22 June 2011; pp. 293–297. [Google Scholar] [CrossRef]
- Cohen, M.B.; Colbourn, C.J.; Ling, A.C.H. Augmenting Simulated Annealing to Build Interaction Test Suites. In Proceedings of the Fourteenth International Symposium on Software Reliability Engineering (ISSRE’03), Denver, CO, USA, 17–20 November 2003; pp. 394–405. [Google Scholar]
- Sharma, C.; Sabharwal, S.; Sibal, R. A Survey on Software Testing Techniques using Genetic Algorithm. Int. J. Comput. Sci.
**2014**, 10, 381–393. [Google Scholar] - Lin, J.C.; Yeh, P.L. Automatic Test Data Generation for Path Testing using Gas. J. Inf. Sci.
**2001**, 131, 47–64. [Google Scholar] [CrossRef] - Mao, C.; Xiao, L.; Yu, X.; Chen, J. Adapting Ant Colony Optimization to Generate Test Data for Software Structural Testing. J. Swarm Evol. Comput.
**2015**, 20, 23–36. [Google Scholar] [CrossRef] - Mao, C. Generating Test Data for Software Structural Testing Based on Particle Swarm Optimization. Arab. J. Sci. Eng.
**2014**, 39, 4593–4607. [Google Scholar] [CrossRef] - Sahoo, R.K.; Ojha, D.; Mohapatra, D.P.; Patra, M.R. Automatic Generation and Optimization of Test Data Using Harmony Search Algorithm. Comput. Sci. Inf. Technol. Conf. Proc.
**2016**, 6, 23–32. [Google Scholar] [CrossRef] - Aghdam, Z.K.; Arasteh, B. An Efficient Method to Generate Test Data for Software Structural Testing Using Artificial Bee Colony Optimization Algorithm. Int. J. Softw. Eng. Knowl. Eng.
**2017**, 27, 951–966. [Google Scholar] [CrossRef] - Ghaemi, A.; Arasteh, B. SFLA-based heuristic method to generate software structural test data. J. Softw. Evol. Proc.
**2020**, 32, e2228. [Google Scholar] [CrossRef] - Arasteh, B.; Hosseini, S.M.J. Traxtor: An Automatic Software Test Suit Generation Method Inspired by Imperialist Competitive Optimization Algorithms. J. Electron. Test.
**2022**, 38, 205–215. [Google Scholar] [CrossRef] - Martou, P.; Mens, K.; Duhoux, B.; Legay, A. Test scenario generation for feature-based context-oriented software systems. J. Syst. Softw.
**2023**, 197, 111570. [Google Scholar] [CrossRef] - Sulaiman, R.A.; Jawawi, D.N.; Halim, S.A. Cost-effective test case generation with the hyper-heuristic for software product line testing. Adv. Eng. Softw.
**2023**, 175, 103335. [Google Scholar] [CrossRef] - Yang, X.; Gandomi, A. Bat Algorithm: A Novel Approach for Global Engineering Optimization. Engineering Computations. Eng. Comput.
**2012**, 29, 464–483. [Google Scholar] [CrossRef] - Yang, X.S. A New Metaheuristic Bat-Inspired Algorithm, in: Nature Inspired Cooperative Strategies for Optimization (NISCO 2010). Stud. Comput. Intell.
**2010**, 284, 65–74. [Google Scholar] - Alachtey, M.; Young, P. An Introduction to the General Theory of Algorithms; Elsevier: North-Holland, NY, USA, 1978. [Google Scholar]
- Arasteh, B.; Bouyer, A.; Ghanbarzadeh, R.; Rouhi, A.; Mehrabani, M.N.; Tirkolaee, E.B. Data replication in distributed systems using olympiad optimization algorithm. Facta Univ. Ser. Mech. Eng.
**2023**, 21, 501–527. [Google Scholar] [CrossRef] - Wang, L.; Cao, Q.; Zhang, Z.; Mirjalili, S.; Zhao, W. Artificial rabbits optimization: A new bio-inspired meta-heuristic algorithm for solving engineering optimization problems. Eng. Appl. Artif. Intell.
**2022**, 114, 105082. [Google Scholar] [CrossRef] - Agushaka, J.O.; Ezugwu, A.E.; Abualigah, L. Gazelle optimization algorithm: A novel nature-inspired metaheuristic optimizer. Neural Comput. Appl.
**2023**, 35, 4099–4131. [Google Scholar] [CrossRef] - Singh, N.; Houssein, E.H.; Mirjalili, S.; Cao, Y.; Selvachandran, G. An efficient improved African vultures optimization algorithm with dimension learning hunting for traveling salesman and large-scale optimization applications. Int. J. Intell. Syst.
**2022**, 37, 12367–12421. [Google Scholar] [CrossRef] - Zarate, O.; Zaldívar, D.; Cuevas, E.; Perez, M. Enhancing Pneumonia Segmentation in Lung Radiographs: A Jellyfish Search Optimizer Approach. Mathematics
**2023**, 11, 4363. [Google Scholar] [CrossRef]

**Figure 2.**Static analysis of the input program for extracting the structure of the input data and creating the bat array that includes the input parameters.

**Figure 3.**Population structure and the representation of the bat position as an array in TDG problem.

**Figure 7.**Average number of iterations that is required for generating the test data with maximum coverage by the different algorithms.

Method | Merits | Demerits |
---|---|---|

Modified GA [1] | Higher Performance and Coverage | Lower success rate |

Random search [6] | Simplicity of implementation | Lack of fitness function |

SA algorithm [7] | faster than a random search | Falling into the local optimum |

GA algorithm [8,9] | Enhanced coverage and parallel implementation | High runtime |

PSO algorithm [11] | High implementation speed and simplicity | Diverse reactions in different executions and applications |

ACO algorithm [10] | Considering the branch weights | Results with high runtime and volatility |

Harmony search [12] | More coverage | Varied outcomes for various uses |

ABC algorithm [13] | Higher coverage and Higher speed | Different results for different applications |

SFLA algorithm [14] | Higher coverage, higher stability, success rate, and Higher speed | The complexity of implementation and maintenance |

ICA algorithm [15] | Higher coverage and speed | Low stability |

Scenario-based Method [16] | Higher scenario coverage | Mainly for design testing, not for source-code testing |

Hyper Heuristic Model-based Testing [17] | Higher program state coverage and lower execution time | The tradeoff between cost and test effectiveness has not been taken into account |

No. | Predicate | $\mathbf{Branch}\mathbf{Distance}\mathbf{Function}\mathit{f}({\mathit{b}\mathit{c}\mathit{h}}_{\mathit{i}}$) |
---|---|---|

1 | Boolean | If true then 0 else δ |

2 | $~a$ | $\mathrm{Negation}\mathrm{is}\mathrm{propagated}\mathrm{over}a$ |

3 | $a=b$ | $\mathrm{If}\left(\mathrm{a}\mathrm{b}\mathrm{s}\right(a-b)=0$$)\mathrm{then}0\mathrm{else}(\mathrm{a}\mathrm{b}\mathrm{s}(a-b)+\delta $) |

4 | $a\ne b$ | $\mathrm{If}\left(\mathrm{a}\mathrm{b}\mathrm{s}\right(a-b)=0$) then 0 else δ |

5 | $a<b$ | $\mathrm{If}(a-b0$$)\mathrm{then}0\mathrm{else}(\mathrm{a}\mathrm{b}\mathrm{s}(a-b)+\delta $) |

6 | $a\le b$ | $\mathrm{If}(a-b\le 0$$)\mathrm{then}0\mathrm{else}(\mathrm{a}\mathrm{b}\mathrm{s}(a-b)+\delta $) |

7 | $a>b$ | $\mathrm{If}(b-a0$$)\mathrm{then}0\mathrm{else}(\mathrm{a}\mathrm{b}\mathrm{s}(b-a)+\delta $) |

8 | $a\ge b$ | $\mathrm{If}(b-a\ge 0$$)\mathrm{then}0\mathrm{else}(\mathrm{a}\mathrm{b}\mathrm{s}(b-a)+\delta $) |

9 | $a\mathrm{a}\mathrm{n}\mathrm{d}b$ | $(f(a)+f(b)$) |

10 | $a\mathrm{o}\mathrm{r}b$ | $\mathrm{min}(f(a),f(b)$) |

**Table 3.**Weight of the operators into the predicate of conditional expressions [10].

Operator in Expresion | Weight of Operator (w_{r}) |
---|---|

= = | 0.9 |

<, <=, >, >= | 0.6 |

Boolean | 0.5 |

! = | 0.2 |

= = | 0.9 |

Program | #Arg | #Arg.Type | LOC | Description |
---|---|---|---|---|

triangleType | 3 | Integer | 31 | Triangle type categorization |

calDay | 3 | Integer | 72 | Create a weekday calculator |

IsValidDate | 3 | Integer | 41 | Verify whether a date is current |

cal | 6 | Integer | 26 | Calculate the number of days between the two dates |

remainder | 2 | Integer | 7 | Find the remainder when dividing an integer |

printCalender | 2 | Integer | 124 | Print a calendar using the year and month inputs |

No. | Program | SA [7] | GA [1] | PSO [11] | ACO [10] | BOA | Best Method |
---|---|---|---|---|---|---|---|

1 | triangleType | 91.86 | 95.00 | 99.94 | 100.00 | 100.00 | ACO, BOA |

2 | calDay | 96.12 | 96.31 | 100.00 | 100.00 | 99.93 | ACO, PSO, BOA |

3 | isValidDate | 95.37 | 99.95 | 100.00 | 99.98 | 99.99 | PSO, BOA |

4 | Cal | 97.00 | 99.02 | 100.00 | 100.00 | 100.00 | PSO, ACO, BOA |

5 | Reminder | 95.02 | 94.07 | 100.00 | 100.00 | 100.00 | PSO, ACO, BOA |

7 | printCalender | 95.26 | 95.06 | 99.72 | 99.85 | 99.78 | ACO, PSO, BOA |

No. | Program | GA [1] | PSO [11] | ACO [10] | BOA | Best Method |
---|---|---|---|---|---|---|

1 | triangleType | 13.79 | 5.36 | 5.76 | 1.12 | BOA |

2 | calDay | 35.80 | 10.37 | 9.51 | 11.13 | ACO |

3 | isValidDate | 21.69 | 11.90 | 15.16 | 3.72 | BOA |

4 | Cal | 15.24 | 8.33 | 9.58 | 1.75 | BOA |

5 | Reminder | 16.31 | 5.35 | 2.01 | 1.30 | BOA |

7 | printCalender | 42.03 | 12.59 | 17.42 | 9.20 | BOA |

No. | Program | GA [1] | PSO [11] | ACO [10] | BOA | Best Method |
---|---|---|---|---|---|---|

1 | triangleType | 10.83 | 0.19 | 6.22 | 0.06 | BOA, PSO |

2 | calDay | 35.73 | 0.35 | 12.84 | 0.19 | PSO, BOA |

3 | isValidDate | 11.68 | 0.54 | 19.94 | 0.14 | PSO, BOA |

4 | Cal | 11.41 | 0.50 | 11.18 | 0.14 | PSO, BOA |

5 | Reminder | 6.09 | 0.17 | 10.49 | 0.09 | BOA |

7 | printCalender | 35.48 | 1.41 | 96.27 | 10.00 | PSO |

No. | Program | SA [7] | GA [1] | PSO [11] | ACO [10] | BOA | Best Method |
---|---|---|---|---|---|---|---|

1 | triangleType | 73.51 | 76.40 | 99.80 | 100.00 | 100.00 | ACO, BOA |

2 | calDay | 70.29 | 65.00 | 100.00 | 100.00 | 99.90 | PSO, ACO, BOA |

3 | isValidDate | 84.13 | 99.40 | 100.00 | 99.80 | 99.92 | PSO, BOA |

4 | Cal | 91.13 | 98.70 | 100.00 | 100.00 | 100.00 | PSO, ACO, BOA |

5 | Reminder | 70.03 | 82.50 | 100.00 | 100.00 | 100.00 | PSO, ACO, BOA |

7 | printCalender | 74.51 | 61.60 | 99.100 | 99.20 | 99.31 | ACO |

Criteria | GA [1] | PSO [11] | ACO [10] | BOA | Best Method |
---|---|---|---|---|---|

Standard deviation of the average convergence criterion for the 10 times executions | 0.37 | 0.11 | 0.21 | 0.09 | BAT |

Symbol | Parameter |
---|---|

A | Sound loudness |

r | Sound pulse rate |

α | The sound loudness reduction coefficient |

$y$ | Sound pulse reduction coefficient |

Q_{min} | Lowest sound frequency |

Q_{max} | Highest sound frequency |

Benchmark | Population | A | r | α | y | Q_{min} | Q_{max} |
---|---|---|---|---|---|---|---|

triangleType | 40 | 0.7 | 0.8 | 0.99 | 0.01 | 0 | 0.3 |

CalDay | 40 | 0.7 | 0.8 | 0.99 | 0.01 | 0 | 0.3 |

isValidDate | 70 | 0.7 | 0.8 | 0.99 | 0.01 | 0 | 0.3 |

Cal | 40 | 0.7 | 0.8 | 0.99 | 0.01 | 0 | 0.3 |

Reminder | 70 | 0.07 | 0.8 | 0.99 | 0.01 | 0 | 0.3 |

printCalender | 40 | 0.1 | 0.2 | 0.99 | 0.01 | 0 | 0.3 |

Source | SS | df | MS | |
---|---|---|---|---|

Between-treatments | 128.5435 | 4 | 32.1359 | F = 18.3167 |

Within-treatments | 43.8614 | 25 | 1.7545 | p < 0.00001 |

Total | 172.4049 | 29 |

Program | triangleType | calDay | isValidDate | Cal | Reminder | printCalendar |

Mutation Score | 98.52% | 92.20% | 98.72% | 98.20% | 93.80 | 99.70 |

#Test Data | Input 1 | Input 2 | Input 3 |
---|---|---|---|

1 | 25 | 26 | 79 |

2 | 0 | 68 | 44 |

3 | 14 | 84 | 91 |

4 | 9 | 5 | 90 |

5 | 57 | 95 | 82 |

6 | 8 | 15 | 25 |

7 | 49 | 10 | 77 |

8 | 79 | 37 | 39 |

9 | 69 | 61 | 78 |

10 | 31 | 17 | 72 |

11 | 15 | 75 | 75 |

12 | 11 | 90 | 94 |

13 | 77 | 47 | 71 |

14 | 26 | 26 | 97 |

15 | 36 | 44 | 65 |

16 | 54 | 48 | 54 |

17 | 25 | 78 | 15 |

18 | 9 | 19 | 18 |

19 | 33 | 33 | 10 |

20 | 33 | 89 | 66 |

Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |

© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Arasteh, B.; Arasteh, K.; Kiani, F.; Sefati, S.S.; Fratu, O.; Halunga, S.; Tirkolaee, E.B.
A Bioinspired Test Generation Method Using Discretized and Modified Bat Optimization Algorithm. *Mathematics* **2024**, *12*, 186.
https://doi.org/10.3390/math12020186

**AMA Style**

Arasteh B, Arasteh K, Kiani F, Sefati SS, Fratu O, Halunga S, Tirkolaee EB.
A Bioinspired Test Generation Method Using Discretized and Modified Bat Optimization Algorithm. *Mathematics*. 2024; 12(2):186.
https://doi.org/10.3390/math12020186

**Chicago/Turabian Style**

Arasteh, Bahman, Keyvan Arasteh, Farzad Kiani, Seyed Salar Sefati, Octavian Fratu, Simona Halunga, and Erfan Babaee Tirkolaee.
2024. "A Bioinspired Test Generation Method Using Discretized and Modified Bat Optimization Algorithm" *Mathematics* 12, no. 2: 186.
https://doi.org/10.3390/math12020186