# Basics and Applications

Hello Habr. If you were worried that math won't be useful in the future, then this article is for you. Let's take a look at testers' tasks from the point of view of formulas and mathematical logic. In the modern world of software development, product quality plays a key role. To ensure a high level of quality, not only technical knowledge is required, but also the use of mathematical methods. Algebra, as one of the main branches of mathematics, can significantly help in this process. In this article we will look at the basic concepts of algebra and their application in the work of a QA engineer.

Let's briefly remember.

Algebra is a branch of mathematics that studies operations and their properties. Algebra is based on the concepts of variables and expressions, equations and inequalities. In the work of a QA engineer, these concepts can be used to build and analyze test scenarios.

Let's say you want to test a function that performs different actions depending on the values ​​of three variables xxx, yyy and zzz. For each possible value of these variables, an equation can be created that will determine the number of tests needed to fully cover all conditions.

Formula: T=n3T = n^3T=n3 where TTT is the number of tests, and nnn is the number of possible values ​​for each variable.

If each variable can take on three possible values ​​(for example, 0, 1 and 2). Then the total number of tests will be 33=273^3 = 2733=27.

But this is not the end, now let's reduce this unconscionably large number of tests.

#### An example of reducing tests using pairwise testing:

Using a pairwise test generation tool (such as Microsoft's PICT), we can obtain the following set of tests:

No.

xxx

yyy

zzz

1

0

0

0

2

0

1

1

3

0

2

2

4

1

0

1

5

1

1

2

6

1

2

0

7

2

0

2

8

2

1

0

9

2

2

1

Thus, instead of 27 tests, we get 9 tests that cover all possible pairs of values.

#### Algebraic structures and their application in QA

In QA, it is important to understand sets and their operations as it helps in grouping and analyzing data. Mappings and functions allow you to model various processes and relationships in software, and matrices and their properties are used to process large amounts of data and analyze test results.

Matrix multiplication is an operation in which two matrices are combined to create a new matrix. The resulting matrix is ​​created by multiplying the row elements of the first matrix with the column elements of the second matrix and summing these products.

### Using matrices to manage large data sets in testing

Let's say we have a complex system and we need to test several different modules. We can use matrices to manage and analyze test data. Let's look at an example where we have two test data matrices:

Matrix A: Test results for various inputs Matrix B: Expected results for those inputs

A = | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 |

B = | 0 | 1 | 0 | | 1 | 0 | 1 | | 0 | 1 | 0 |

Multiplying matrices will allow us to compare the results and identify discrepancies:

C=A*B

Formula for matrix multiplication:

c_ij = Σ(a_ik * b_kj)

### Designations:

• AAA – the first matrix of size m×nm \times nm×n (m rows and n columns)

• BBB – second matrix of size n×pn \times pn×p (n rows and p columns)

• CCC – resulting matrix of size m×pm \times pm×p (m rows and p columns)

• aika_{ik}aik​ – element at the intersection of the i-th row and k-th column of the AAA matrix

• bkjb_{kj}bkj​ – element at the intersection of the k-th row and j-th column of the BBB matrix

• cijc_{ij}cij​ – element at the intersection of the i-th row and j-th column of the CCC matrix

#### Algebra of logic in testing

Logical operations and expressions play an important role in writing tests. Boolean algebra allows you to formalize and optimize testing conditions, which increases the efficiency of the QA engineer. Examples of logical expressions show how algebra can be applied in practice to create accurate and efficient tests.

Using Boolean expressions in testing has several advantages:

1. Formalization of conditions: Boolean expressions clearly formalize conditions, making them easier to test and analyze.

2. Test optimization: Boolean expressions help identify and eliminate redundant tests, focusing only on the necessary tests.

3. Test automation: Boolean expressions can be used in automated tests to check execution conditions.

### Example: Creating Boolean Expressions to Test Complex Conditions

Let's assume we have an authentication system that allows login under the following conditions:

Boolean expressions for this case:

#### Example test scripts

1. Test scenario 1: Checking successful authentication with the correct login and password

• Input data: correct_login = true, correct_password = true, two_factor_auth = false

• Expected Result: login_success = true

2. Test scenario 2: Verifying successful authentication when using two-factor authentication

• Input data: correct_login = false, correct_password = false, two_factor_auth = true

• Expected Result: login_success = true

3. Test scenario 3: Check for failed authentication with incorrect login and password without two-factor authentication

• Input data: correct_login = false, correct_password = false, two_factor_auth = false

• Expected Result: login_success = false

#### Using algebra in test case development

The use of algebraic expressions helps determine testing conditions and construct optimal test scenarios. This allows you to reduce the time for writing tests and improve their quality.

### Example: Using algebraic expressions to construct tests for equivalent classes

Equivalence Partitioning is a test design technique that involves dividing input data into groups or classes in which the data is considered equivalent and processed in the same way. Thus, instead of testing every possible value, one value from each class is selected.

#### Real example: Testing the user registration system

Consider a user registration system that accepts age data ranging from 1 to 100 years. We can divide the range into equivalent classes as follows:

• Class 1: 1-17 (minors)

• Class 3: 60-100 (elderly)

We then select one value from each class to test. For example, for classes 1, 2 and 3 these could be 10, 30 and 70 respectively.

#### Step by step process

1. Defining Ranges and Classes:

• The registration system accepts ages from 1 to 100 years.

• Let's divide the range into three equivalent classes: 1-17, 18-59, 60-100.

2. Selecting Representative Values:

3. Creating test scripts:

#### Sample test scripts

1. Test scenario 1: Age input check 10 (Class 1 – minors)

• Input data: Age = 10

• Expected Result: The system should handle age 10 correctly and provide appropriate notifications for minors.

2. Test scenario 2: Age input check 30 (Class 2 – adults)

• Input data: Age = 30

• Expected Result: The system should correctly handle age 30 and provide access to registration functions for adults.

3. Test scenario 3: Age input check 70 (Class 3 – elderly)

• Input data: Age = 70

• Expected Result: The system should correctly handle age 70 and provide appropriate notifications and features for the elderly.

#### Conclusion

The use of algebraic structures and methods in QA is an opportunity to formalize and optimize testing processes, analyze data and improve product quality. The use of such methods opens up new horizons for the specialist himself in understanding his high-level actions.

The article provides fairly simple examples. In my opinion, this is a useful basis without overload. I hope you found the article interesting.

#### Literature and Articles for Further Study

1. Books:

• Kline, Morris. “Mathematics: loss of certainty.” – An excellent overview of mathematics in general.

• Lewis, Harry. “Elements of mathematical logic.” — an introductory book on mathematical logic and its applications.

2. Articles:

• “Using Algebra in Test Case Design” (TechBeacon)

• “Matrix Methods for Analyzing Test Results” (IEEE Transactions on Software Engineering)

• “Boolean Algebra and Its Application in Software Testing” (Journal of Software Testing, Verification & Reliability)

3. Online resources: