A method and system for adaptively generating random test data
Through the adaptive generation of random test data, the problem of single and low reliability of existing test data is solved, and the rapid, efficient and diverse test data generation is achieved, which improves the comprehensiveness and reliability of the test.
Patent Information
- Application Number
- CN202411228702.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-03
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2044-09-03
AI Technical Summary
The data constructed in existing test scripts are single, which is prone to duplication, resulting in low data reliability and inaccurate corresponding test results.
It provides a method to adaptively generate random test data. By obtaining the basic parameters of the data to be generated, defining the structure and rules of the data type, determining the probability of occurrence of each field value, and generating test data based on these probabilities, and dynamically adjusting the probability through verification results.
This greatly reduces the time of manual participation, generates test data faster, and has better randomness and range of data, improves the comprehensiveness and reliability of tests, and ensures the accuracy and effectiveness of test results.
Smart Images

Figure CN119025430B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a method, system, electronic device, and non-transient computer-readable storage medium for adaptively generating random test data. Background Art
[0002] Nowadays, with the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to financial technology, and the financial industry has high standards for security and real-time performance. In order to better simulate the real test environment, the financial technology field needs to overcome the shortcomings of existing practices when constructing the parameter data in the test script.
[0003] However, the data constructed in the current test scripts are often single and prone to duplicate data, resulting in low data reliability and inaccurate corresponding test results. Summary of the invention
[0004] In view of the technical problems existing in the prior art, the present invention provides a method, system, electronic device and non-transitory computer-readable storage medium for adaptively generating random test data, which can improve the accuracy and reliability of generated test data.
[0005] The technical solution of the present invention to solve the above technical problems is as follows:
[0006] The present invention provides a method for adaptively generating random test data, the method comprising:
[0007] Obtaining basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated;
[0008] Define the structure and rules for each of the data types described based on business requirements;
[0009] Determine the occurrence probability of each field value of the to-be-generated data of each data type;
[0010] Generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated;
[0011] Verifying the first test data to obtain a corresponding verification result, and adjusting the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight;
[0012] According to the fourth weight, each of the occurrence probabilities is updated to obtain an updated probability, and second test data corresponding to the data to be generated is generated according to the updated probability.
[0013] Optionally, determining the occurrence probability of each field value of the to-be-generated data of each data type includes:
[0014] Get the total number of all available values corresponding to each of the field values;
[0015] Obtaining a number and a first weight of each of the available values;
[0016] Constructing a randomness function according to the number of each of the available values;
[0017] Constructing a first random item according to the first constant, the second constant and the number of each of the available values;
[0018] The occurrence probability of each of the field values is determined according to the first weight, the randomness function and the first random term.
[0019] Optionally, the occurrence probability of the field value is expressed as:
[0020]
[0021] Among them, V i is the field value, P(V i ) is the probability of occurrence, i and j are number values, ω i is the first weight of the field value, f(i) is the randomness function, k and h are the first constant and the second constant respectively, n is the total number of all available values of the field value, sin(k·i) and cos(h·i) are the first random terms.
[0022] Optionally, the data type includes a unified social credit code; and generating first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated includes:
[0023] Obtain each part of the unified social credit code except the first verification code;
[0024] According to the value, number and second weight of each part of the unified social credit code;
[0025] constructing a second random item according to the third constant, the fourth constant and the number of each part of the unified social credit code;
[0026] Determine a first verification code of the unified social credit code according to the second random item, the value of each part of the unified social credit code, the number and the second weight;
[0027] The first test data corresponding to the unified social credit code is generated based on the first verification code and each part of the unified social credit code except the first verification code.
[0028] Optionally, the first verification code is expressed as:
[0029]
[0030] Among them, C is the first verification code of the unified social credit code, a i is the value of each part of the unified social credit code, p i is the second weight of each part of the unified social credit code, q and r are the third and fourth constants respectively, and sin(q·i) and cos(r·i) are the second random terms.
[0031] Optionally, the data type includes an identity card number; and generating first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated includes:
[0032] Obtain each part of the ID card number except the second verification code;
[0033] According to the value, number and third weight of each part of said identity card number;
[0034] Constructing a third random item according to the fifth constant, the sixth constant and the number of each part of the ID card number;
[0035] Determine a second verification code of the ID card number according to the third random item, the value of each part of the ID card number, the number and the third weight;
[0036] The first test data corresponding to the ID card number is generated according to the second verification code and each part of the ID card number except the second verification code.
[0037] Optionally, the second check code is expressed as:
[0038]
[0039] Where C′ is the second verification code of the ID card number; b j is the value of each part of the ID number; m j is the third weight of each part of the ID number; t and u are the fifth and sixth constants respectively, and exp(t·j) and log(u·j+1) are the third random terms.
[0040] Optionally, the adjusting the first weight used for calculating the occurrence probability in combination with the verification result to obtain a fourth weight includes:
[0041] Constructing a fourth random item according to the seventh constant, the eighth constant, and the serial number of each of the available values;
[0042] Obtaining an adjustment coefficient of the fourth random item;
[0043] The fourth weight is determined according to the fourth random term, the adjustment coefficient and the first weight.
[0044] Optionally, the fourth weight is expressed as:
[0045] ω′ i =ω i ×(1+δ·sin(v·i)+cos(z·i));
[0046] Among them, ω′ i is the adjusted fourth weight; ω i is the original first weight; δ is the adjustment coefficient; v and z are the seventh and eighth constants respectively, sin(v·i) and cos(z·i) are the fourth random terms
[0047] The present invention also provides a system for adaptively generating random test data, the system comprising:
[0048] A parameter acquisition module, used to acquire basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated;
[0049] A data type module is used to define the structure and rules of each data type according to business requirements;
[0050] A probability calculation module, used to determine the occurrence probability of each field value of the data to be generated of each data type;
[0051] A data generating module, used for generating first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated;
[0052] a data verification module, configured to verify the first test data to obtain a corresponding verification result, and adjust the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight;
[0053] The data optimization module is used to update each of the occurrence probabilities according to the fourth weight to obtain an updated probability, and generate second test data corresponding to the data to be generated according to the updated probability.
[0054] In addition, to achieve the above-mentioned purpose, the present invention also proposes an electronic device, comprising: a memory for storing a computer software program; a processor for reading and executing the computer software program, thereby implementing a method for adaptively generating random test data as described above.
[0055] In addition, to achieve the above-mentioned purpose, the present invention also proposes a non-transitory computer-readable storage medium, in which a computer software program is stored. When the computer software program is executed by a processor, a method for adaptively generating random test data as described above is implemented.
[0056] The beneficial effects of the present invention are:
[0057] (1) The present invention can greatly reduce the time of manual participation, thereby generating random test data within a limited range faster, saving a lot of time in generating data, and can better ensure the randomness of the data and absolutely guarantee the range of the generated data;
[0058] (2) The present invention can dynamically adjust the generation parameters according to the quality of the generated data and the test results, introduces dynamic adjustment coefficients and trigonometric function terms, optimizes the generation process according to the test feedback, improves the efficiency and quality of data generation, and reduces the time of manual intervention;
[0059] (3) The data generated by the present invention covers a wide range of business scenarios and simulates a real test environment. Through the diversity and authenticity of the data, the test can more comprehensively cover various business scenarios and abnormal situations, improving the comprehensiveness and reliability of the test. The real test data simulates real user behavior and business processes, ensuring the accuracy and effectiveness of the test results;
[0060] (4) The automated data generation tool of the present invention realizes the ability to quickly generate a large amount of high-quality test data. By configuring the type and amount of generated data, the tool can efficiently generate test data that meets business needs, saving the time and cost of manually generating data. At the same time, the automated adjustment function of the tool further reduces manual intervention and improves generation speed and quality;
[0061] (5) The parameters and formulas of the present invention are highly adaptable and flexible and can be adjusted according to specific business requirements and test scenarios. Different data types and formats can be generated by adjusting formulas and parameters to meet the needs of various business requirements and test scenarios. The adaptive adjustment function allows the solution to be continuously optimized to adapt to the ever-changing test requirements and business environment.
[0062] In summary, the present invention can realize the efficient generation of random test data, ensure the diversity, authenticity and effectiveness of the data, and greatly improve the comprehensiveness and reliability of the test. At the same time, the automated data generation tool greatly reduces the time of manual participation, saves the time and cost of generating data, has high adaptability and flexibility, and can meet various business needs and test scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1A scene diagram of a method for adaptively generating random test data provided by the present invention;
[0064] Figure 2 A flowchart of a method for adaptively generating random test data provided by the present invention;
[0065] Figure 3 A schematic diagram of the structure of a system for adaptively generating random test data provided by the present invention;
[0066] Figure 4 A schematic diagram of the hardware structure of a possible electronic device provided by the present invention;
[0067] Figure 5 A schematic diagram of the hardware structure of a possible computer-readable storage medium provided by the present invention. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0069] In the description of the present invention, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0070] In the description of the present invention, the term "for example" is used to mean "used as an example, illustration or explanation". Any embodiment described as "for example" in the present invention is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is given to enable any technician in the field to implement and use the present invention. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present invention can be implemented without using these specific details. In other examples, well-known structures and processes will not be elaborated in detail to avoid obscuring the description of the present invention with unnecessary details. Therefore, the present invention is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in the present invention.
[0071] See also Figure 1 , Figure 1A scene diagram of a method for adaptively generating random test data provided by the present invention. Figure 1 As shown, the terminal and the server are connected via a network, such as a wired or wireless network connection. The terminal may include but is not limited to portable terminals such as mobile phones and tablets installed with various network platform applications, as well as fixed terminals such as computers, query machines, and advertising machines. The server provides users with various business services, including service push servers, user recommendation servers, etc.
[0072] It should be noted that Figure 1 The scenario diagram of a method for adaptively generating random test data is only an example. The terminal, server and application scenario described in the embodiment of the present invention are intended to more clearly illustrate the technical solution of the embodiment of the present invention, and do not generate any limitation on the technical solution provided by the embodiment of the present invention. A person of ordinary skill in the art can know that with the evolution of the system and the emergence of new business scenarios, the technical solution provided by the embodiment of the present invention is also applicable to similar technical problems.
[0073] Among them, the terminal can be used for:
[0074] Obtaining basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated;
[0075] Define the structure and rules for each of the data types described based on business requirements;
[0076] Determine the occurrence probability of each field value of the to-be-generated data of each data type;
[0077] Generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated;
[0078] Verifying the first test data to obtain a corresponding verification result, and adjusting the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight;
[0079] According to the fourth weight, each of the occurrence probabilities is updated to obtain an updated probability, and second test data corresponding to the data to be generated is generated according to the updated probability.
[0080] It should be noted that when generating test data, the present invention adopts a random generation algorithm to avoid using real personal information, thereby protecting personal privacy and complying with the relevant requirements of the Personal Information Protection Law, the Cybersecurity Law, and the E-Commerce Law. The test data generated by the present invention is only used for testing and research and development purposes and is not used for illegal purposes or commercial profit, thereby ensuring the legality and compliance of data use.
[0081] See also Figure 2, provides a flow chart of a method for adaptively generating random test data of the present invention, comprising the following steps:
[0082] Step 201: Obtain basic parameters of the data to be generated.
[0083] The basic parameters may include the data type and the number of fields of the data to be generated.
[0084] In some embodiments, the data type may include a unified social credit code, an ID card number, and a mobile phone number, etc. It should be noted that although the unified social credit code is composed of 18 digits of Arabic data or uppercase English letters, including the first registration management department code, the second organization category code, the third to eighth registration management authority administrative division code, the ninth to seventeenth subject identification code (organization code), and the eighteenth check code, the present invention identifies it as five fields, the number of fields is 5, including the registration management department code, the organization category code, the registration management authority administrative division code, the subject identification code (organization code) and the check code, example: XXXXXXXXXXXXX XXXXX.
[0085] Similarly, the ID card number includes 4 fields, including the area code, date of birth code, sequence code and check code, and the number of fields is 4. The mobile phone number includes 2 fields, including the operator identification and user number, and the number of fields is 2.
[0086] Step 202: Define the structure and rules of each data type according to business requirements.
[0087] It can be understood that the data to be generated for each data type has its own structure and rules. Taking the unified social credit code as an example, the structure is: the first digit: registration management department code, the second digit: organization category code, the third to the eighth digit: registration management authority administrative division code, the ninth to the seventeenth digit: subject identification code (organization code), the eighteenth digit: check code.
[0088] The rules corresponding to each field are as follows: Registration management department code: indicates the registration management department of the enterprise, such as the State Administration for Industry and Commerce, which is represented by the number "1". Organization category code: indicates the type of enterprise, such as company, partnership, etc. Administrative division code: generated according to national standards, corresponding to the administrative division where the enterprise is located. Entity identification code: the unique identifier of the enterprise, which can be generated based on information such as the organization code. Verification code: calculated based on the first 17 digits or letters through a specific algorithm to ensure the uniqueness and correctness of the enterprise credit code.
[0089] Taking the ID card number as an example, the structure is: 1st to 6th digits: area code, 7th to 14th digits: date of birth code (format is YYYYMMDD), 15th to 17th digits: sequence code, 18th digit: check code. The corresponding rules are: Area code: generated according to the national administrative division code, indicating the registered place of the ID card holder. Date of birth code: generated according to the holder's date of birth. Sequence code: indicates the order of people with the same date of birth in the same region, odd numbers are males, and even numbers are females. Check code: calculated based on the first 17 digits through a specific algorithm to ensure the uniqueness and correctness of the ID card number.
[0090] Step 203: Determine the occurrence probability of each field value of the to-be-generated data of each data type.
[0091] The occurrence probability of each field value may be a value between 0 and 1, such as 0.1, 0.2, 10%, 20%, etc. For example, the probability that the field value of the field is 1 is 10%.
[0092] In some embodiments, step 203 may include:
[0093] Get the total number of all available values corresponding to each of the field values;
[0094] Obtaining a number and a first weight of each of the available values;
[0095] Constructing a randomness function according to the number of each of the available values;
[0096] Constructing a first random item according to the first constant, the second constant and the number of each of the available values;
[0097] The occurrence probability of each of the field values is determined according to the first weight, the randomness function and the first random term.
[0098] In some embodiments, the probability of occurrence of a field value is expressed as:
[0099]
[0100] Among them, V i is the field value, P(V i ) is the probability of occurrence, i and j are number values, ω i is the first weight of the field value, f(i) is the randomness function, k and h are the first constant and the second constant respectively, n is the total number of all available values of the field value, sin(k·i) and cos(h·i) are the first random terms.
[0101] In the specific implementation, V iIt is a field value, such as a specific value in a company's credit code or a part of an ID number;
[0102] i and j are number values;
[0103] ω i It is the first weight of the field value, which is used to adjust its importance when generating data;
[0104] f(i) is a randomness function, which is used to introduce additional randomness. Different functions can be selected according to specific circumstances, such as linear function, exponential function, etc.;
[0105] k and h are the first and second constants, respectively, used to adjust the shape of the probability distribution and affect the degree of randomness;
[0106] n is the total number of possible values of the field, which is used to normalize the probability value.
[0107] In the specific implementation, ω i f(i) sin(k i) + cos(h i) represents the field value V i The weighted randomness of , where sin(k·j) and cos(h·j) introduce randomness. The denominator is the sum of the probabilities of all possible values, the purpose is to normalize and ensure that the sum of all probability values is 1.
[0108] In summary, the function of this formula is to calculate the weight ω according to the i , randomness function f(i) and constants k and h are used to calculate the probability of occurrence of each field value, thereby achieving a more flexible and realistic data generation process.
[0109] For example, suppose that the probability distribution of the region code of the enterprise credit code is to be generated. Assume that the region code has 10 possible values, numbered from 1 to 10. The weight ω of each region code can be set i As follows: ω1=0.1, ω2=0.2, ω3=0.15, ω4=0.05, ω5=0.12, ω6=0.08, ω7=0.1, ω8=0.07, ω9=0.1, ω10=0.03.
[0110] The randomness function f(i) selects a simple linear function f(i)=i, and the constants k and h are taken as k=0.5 and h=1.0.
[0111] Now we can calculate the area code V i The probability P(V i ), we can substitute i from 1 to 10 into the formula to calculate the probability P(V i ), and then normalized to ensure that the sum of all probabilities is 1.
[0112] Step 204: Generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated.
[0113] In some embodiments, the data type may include a unified social credit code, and step 204 may include:
[0114] Obtain each part of the unified social credit code except the first verification code;
[0115] According to the value, number and second weight of each part of the unified social credit code;
[0116] constructing a second random item according to the third constant, the fourth constant and the number of each part of the unified social credit code;
[0117] Determine a first verification code of the unified social credit code according to the second random item, the value of each part of the unified social credit code, the number and the second weight;
[0118] The first test data corresponding to the unified social credit code is generated based on the first verification code and each part of the unified social credit code except the first verification code.
[0119] In some embodiments, the first check code is represented by:
[0120]
[0121] Among them, C is the first verification code of the unified social credit code, a i is the value of each part of the unified social credit code, p i is the second weight of each part of the unified social credit code, q and r are the third and fourth constants respectively, and sin(q·i) and cos(r·i) are the second random terms.
[0122] In some embodiments, the field value with the highest probability of occurrence can be determined as the value of each part other than the check code based on the probability of occurrence of each field value of the data to be generated. For example, for the first field, the field value with the highest probability of occurrence is 1, then the field value of the first field can be determined to be 1.
[0123] In the specific implementation, C is the first verification code of the unified social credit code, which is used to verify the accuracy of the code;
[0124] a i It is the value of each part of the unified social credit code, such as the region code, institution category code, etc.
[0125] p iIt is the second weight of each part of the unified social credit code, which is used to adjust the importance of different parts;
[0126] q and r are the third and fourth constants respectively, which are used to adjust the calculation method of the check code and increase its complexity and randomness;
[0127] In the specific implementation, according to the formula, firstly, each part a of the unified social credit code i Perform weighted summation, where the weight p i It is used to adjust the importance of different parts. Then, the weighted summation result is adjusted by the sine function sin(q·i) and the cosine function cos(r·i) to increase the randomness of the check code. Finally, the adjusted result is modulo 1111 to obtain the final check code C.
[0128] The function of this formula is to generate a verification code through a complex calculation process based on the values of each part of the unified social credit code and the corresponding weights to ensure the accuracy and uniqueness of the generated code. The selection of constants q and r can be adjusted according to specific needs and security considerations to increase the security and unpredictability of the verification code.
[0129] For example, assuming that the value of each part of the unified social credit code is a i are: a1 = 1, a2 = 2, a3 = 3, a4 = 4. The second weight pi of each part is: p1 = 1, p2 = 2, p3 = 3, p4 = 4. The constants q = 0.5 and r = 1.0.
[0130] In some embodiments, it is possible to first calculate
[0131] Finally, the result is subjected to a modulo operation (mod11) to obtain the final check code C = 25.8128mod11. Only the integer part is considered in the modulo operation, so the final check code C of the 18th digit of the unified social credit code is 3.
[0132] It should be noted that, although the unified social credit code is composed of 18 digits of Arabic data or uppercase English letters, including the first registration management department code, the second institution category code, the third to eighth registration management authority administrative division code, the ninth to seventeenth subject identification code (organization code), and the eighteenth check code, the present invention recognizes it as four fields, including five fields including the registration management department code, the institution category code, the registration management authority administrative division code, the subject identification code (organization code) and the check code.
[0133] In the specific implementation, the six-digit value can be summed, and then the sum result can be modulo to map it to a value. For the sake of example, assuming that the administrative division code of the registration management authority from the 3rd to the 8th digit is 123456, the mapped single digit is:
[0134] (1+2+3+4+5+6)mod10=3;
[0135] Therefore, the present invention can map the 3rd to 8th digits of the administrative division code of the registration management authority to 3, and subsequently the mapped single digit can be used to calculate the check code C.
[0136] In some embodiments, the data type may include an ID number, and step 204 may include:
[0137] Obtain each part of the ID card number except the second verification code;
[0138] According to the value, number and third weight of each part of said identity card number;
[0139] Constructing a third random item according to the fifth constant, the sixth constant and the number of each part of the ID card number;
[0140] Determine a second verification code of the ID card number according to the third random item, the value of each part of the ID card number, the number and the third weight;
[0141] The first test data corresponding to the ID card number is generated according to the second verification code and each part of the ID card number except the second verification code.
[0142] In some embodiments, the second check code is expressed as:
[0143]
[0144] Where C′ is the second verification code of the ID card number; b j is the value of each part of the ID number; m j is the third weight of each part of the ID number; t and u are the fifth and sixth constants respectively, and exp(t·j) and log(u·j+1) are the third random terms.
[0145] In the specific implementation, C′ is the second verification code of the ID card number;
[0146] b j is the value of each part of the ID number;
[0147] m j is the third weight of each part of the ID number;
[0148] t and u are the fifth and sixth constants respectively.
[0149] In the specific implementation, for each ID card part b j , represents a number or letter in the ID number. For example, b1 represents the first character of the ID number, b2 represents the second character, and so on, until b 18 Represents the last character of the ID number.
[0150] For each part, the third weight m j , indicating the importance or weight of each part of the ID number in the calculation. These weights can be determined based on historical data or other rules.
[0151] exp(t·j) represents the natural logarithm (i.e., exponential function) with t·j as the exponent. Here, t is a constant, and j is a number value indicating the position of the current part, such as the first position, the second position, etc.
[0152] log(u·j+1) represents the natural logarithm of u·j+1. Here, u is a constant and j represents the position of the current part.
[0153] Finally, the values of all parts are weighted and summed, and the result is subjected to a modulo operation (mod10) to obtain the final second check code C′.
[0154] Through this formula, the second verification code can be calculated according to the various parts of the ID card number and the corresponding weights to ensure the validity and accuracy of the ID card number. It should be noted that the specific process of calculating the verification code C' can refer to the process of calculating the verification code C of the unified social credit code above, which will not be repeated here.
[0155] Step 205: verify the first test data to obtain a corresponding verification result, and adjust the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight.
[0156] In some embodiments, step 205 may include:
[0157] Constructing a fourth random item according to the seventh constant, the eighth constant, and the serial number of each of the available values;
[0158] Obtaining an adjustment coefficient of the fourth random item;
[0159] The fourth weight is determined according to the fourth random term, the adjustment coefficient and the first weight.
[0160] In some embodiments, the fourth weight is expressed as:
[0161] ω′i =ω i ×(1+δ·sin(v·i)+cos(z·i));
[0162] Among them, ω′ i is the adjusted fourth weight; ω i is the original first weight; δ is the adjustment coefficient; v and z are the seventh and eighth constants respectively, and sin(v·i) and cos(z·i) are the fourth random terms.
[0163] In the specific implementation, ω′ i is the adjusted fourth weight;
[0164] ω i is the original first weight;
[0165] δ is the adjustment coefficient, which can be adjusted as needed;
[0166] v and z are the seventh and eighth constants respectively.
[0167] In the specific implementation, ω i It is the original first weight, representing the importance or weight of each part in the calculation, which can be determined based on historical data, experience or other rules.
[0168] δ·sin(v·i)+cos(z·i) is an adjustment term that can dynamically adjust the fourth weight according to demand. Among them, δ is the adjustment coefficient, which can control the magnitude of the adjustment; v and z are two constants used to introduce additional randomness and complexity.
[0169] 1+δ·sin(v·i)+cos(z·i) is a factor that increases or decreases the original fourth weight ω i Adjusted to new values that are more appropriate for the current situation.
[0170] Through this formula, the fourth weight can be dynamically adjusted according to the current situation and needs to optimize the process and results of data generation.
[0171] Exemplarily, it is assumed that the first weights are: ω1=0.5, ω2=0.7, ω3=0.6, the adjustment coefficient δ=0.2, the constants v=0.8 and z=0.5.
[0172] In some embodiments, the adjusted fourth weight ω′ of each part may be calculated in turn. i :
[0173] ω'1=0.5×(1+0.2·sin(0.8×1)+cos(0.5×1))=1.01;
[0174] ω'2=0.7×(1+0.2*sin(0.8×2)+cos(0.5×2))=1.21786;
[0175] ω'3=0.6×(1+0.2·sin(0.8×3)+cos(0.5×3))=0.723.
[0176] Step 206: Update each of the occurrence probabilities to obtain updated probabilities according to the fourth weight, and generate second test data corresponding to the data to be generated according to the updated probabilities.
[0177] In some embodiments, assuming that the initial first weight ω i =[0.2, 0.3, 0.25, 0.25], assuming δ = 0.1, v = 2, z = 1, then the updated fourth weight is:
[0178] ω′ i =ω i ×(1+δ·sin(v·i)+cos(z·i))=ω i ×(1+0.1·sin(2·i)+cos(1·i)).
[0179] In some embodiments, ω′ is calculated for each field. i , similarly ω′ j It is also based on ω j Calculated in this way, ω′ i and ω′ j Substitute into the calculation P(V i Finally, the method of the present invention is combined with the update probability to generate each part other than the check code and the check code to obtain the second test data.
[0180] The test data generated by the method of the present invention is now given an example. For example, the generated test data may be an ID card number: 331023202002129180. After verification, the identity region is displayed as "Tiantai County, Taizhou City, Zhejiang Province" and the age is "4 years old".
[0181] See also Figure 3 , Figure 3 A schematic diagram of the structure of a system for adaptively generating random test data provided by the present invention.
[0182] like Figure 3 As shown, a system for adaptively generating random test data proposed in an embodiment of the present invention includes:
[0183] The parameter acquisition module 301 is used to acquire basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated;
[0184] A data type module 302, used to define the structure and rules of each data type according to business requirements;
[0185] A probability calculation module 303 is used to determine the occurrence probability of each field value of the to-be-generated data of each data type;
[0186] A data generating module 304 is used to generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated;
[0187] A data verification module 305 is used to verify the first test data to obtain a corresponding verification result, and adjust the first weight used to calculate the occurrence probability based on the verification result to obtain a fourth weight;
[0188] The data optimization module 306 is used to update each of the occurrence probabilities according to the fourth weight to obtain an updated probability, and generate second test data corresponding to the data to be generated according to the updated probability.
[0189] See also Figure 4 , Figure 4 Schematic diagram of an electronic device provided by an embodiment of the present invention. Figure 4 As shown, an embodiment of the present invention provides an electronic device 400, including a memory 410, a processor 420, and a computer program 411 stored in the memory 410 and executable on the processor 420. When the processor 420 executes the computer program 411, the following steps are implemented:
[0190] Obtaining basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated;
[0191] Define the structure and rules for each of the data types described based on business requirements;
[0192] Determine the occurrence probability of each field value of the to-be-generated data of each data type;
[0193] Generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated;
[0194] Verifying the first test data to obtain a corresponding verification result, and adjusting the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight;
[0195] According to the fourth weight, each of the occurrence probabilities is updated to obtain an updated probability, and second test data corresponding to the data to be generated is generated according to the updated probability.
[0196] See also Figure 5 , Figure 5 A schematic diagram of an embodiment of a computer-readable storage medium provided in an embodiment of the present invention. Figure 5 As shown, this embodiment provides a computer-readable storage medium 500, on which a computer program 411 is stored. When the computer program 411 is executed by a processor, the following steps are implemented:
[0197] Obtaining basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated;
[0198] Define the structure and rules for each of the data types described based on business requirements;
[0199] Determine the occurrence probability of each field value of the to-be-generated data of each data type;
[0200] Generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated;
[0201] Verifying the first test data to obtain a corresponding verification result, and adjusting the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight;
[0202] According to the fourth weight, each of the occurrence probabilities is updated to obtain an updated probability, and second test data corresponding to the data to be generated is generated according to the updated probability.
[0203] It should be noted that in the above embodiments, the description of each embodiment has its own emphasis, and for parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0204] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0205] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded computer, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A system that specifies the functions of a box or multiple boxes.
[0206] These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a product including an instruction system, which is implemented in the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0207] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0208] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0209] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A method for adaptively generating random test data, characterized in that: The method comprises: Obtaining basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated; Define the structure and rules for each of the data types described based on business requirements; Determine the occurrence probability of each field value of the to-be-generated data of each data type; Generate first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated; Verifying the first test data to obtain a corresponding verification result, and adjusting the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight; According to the fourth weight, updating each of the occurrence probabilities to obtain updated probabilities, and generating second test data corresponding to the data to be generated according to the updated probabilities; The determining the occurrence probability of each field value of the to-be-generated data of each data type includes: Get the total number of all available values corresponding to each of the field values; Obtaining a number and a first weight of each of the available values; Constructing a randomness function according to the number of each of the available values; Constructing a first random item according to the first constant, the second constant and the number of each of the available values; Determine the occurrence probability of each of the field values according to the first weight, the randomness function and the first random item; The occurrence probability of the field value is expressed as: Among them, V i is the field value, P(V i ) is the probability of occurrence, i and j are number values, ω i is the first weight of the field value, f(i) is the randomness function, k and h are the first constant and the second constant respectively, n is the total number of all available values of the field value, sin(k·i) and cos(h·i) are the first random terms.
2. The method for adaptively generating random test data according to claim 1, characterized in that: The data types include unified social credit code; The step of generating first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated includes: Obtain each part of the unified social credit code except the first verification code; According to the value, number and second weight of each part of the unified social credit code; constructing a second random item according to the third constant, the fourth constant and the number of each part of the unified social credit code; Determine a first verification code of the unified social credit code according to the second random item, the value of each part of the unified social credit code, the number and the second weight; The first test data corresponding to the unified social credit code is generated based on the first verification code and each part of the unified social credit code except the first verification code.
3. The method for adaptively generating random test data according to claim 2, characterized in that: The first check code is expressed as: Among them, C is the first verification code of the unified social credit code, a i is the value of each part of the unified social credit code, p i is the second weight of each part of the unified social credit code, q and r are the third and fourth constants respectively, and sin(q·i) and cos(r·i) are the second random terms.
4. The method for adaptively generating random test data according to claim 3, characterized in that: The data type includes an identity card number; and generating first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated includes: Obtain each part of the ID card number except the second verification code; According to the value, number and third weight of each part of said identity card number; Constructing a third random item according to the fifth constant, the sixth constant and the number of each part of the ID card number; Determine a second verification code of the ID card number according to the third random item, the value of each part of the ID card number, the number and the third weight; The first test data corresponding to the ID card number is generated according to the second verification code and each part of the ID card number except the second verification code.
5. The method for adaptively generating random test data according to claim 4, characterized in that: The second check code is expressed as: Where C′ is the second verification code of the ID card number; b j is the value of each part of the ID number; m j is the third weight of each part of the ID number; t and u are the fifth and sixth constants respectively, and exp(t·j) and log(u·j+1) are the third random terms.
6. The method for adaptively generating random test data according to claim 5, characterized in that: The adjusting the first weight used for calculating the occurrence probability in combination with the verification result to obtain a fourth weight includes: Constructing a fourth random item according to the seventh constant, the eighth constant, and the number of each of the available values; Obtaining an adjustment coefficient of the fourth random item; The fourth weight is determined according to the fourth random term, the adjustment coefficient and the first weight.
7. The method for adaptively generating random test data according to claim 6, characterized in that: The fourth weight is expressed as: oh' i =ω i ×(1+δ sin(v i)+cos(z i)) Among them, ω′ i is the adjusted fourth weight; ω i is the original first weight; δ is the adjustment coefficient; v and z are the seventh and eighth constants respectively, and sin(v·i) and cos(z·i) are the fourth random terms.
8. A system for adaptively generating random test data, characterized in that: The system comprises: A parameter acquisition module, used to acquire basic parameters of the data to be generated; the basic parameters include the data type and the number of fields of the data to be generated; A data type module is used to define the structure and rules of each data type according to business requirements; A probability calculation module, used to determine the occurrence probability of each field value of the data to be generated of each data type; A data generating module, used for generating first test data corresponding to the data to be generated according to the occurrence probability of each field value of the data to be generated; a data verification module, configured to verify the first test data to obtain a corresponding verification result, and adjust the first weight used to calculate the occurrence probability in combination with the verification result to obtain a fourth weight; A data optimization module, configured to update each of the occurrence probabilities to obtain updated probabilities according to the fourth weight, and generate second test data corresponding to the data to be generated according to the updated probabilities; The determining the occurrence probability of each field value of the to-be-generated data of each data type includes: Get the total number of all available values corresponding to each of the field values; Obtaining a number and a first weight of each of the available values; Constructing a randomness function according to the number of each of the available values; Constructing a first random item according to the first constant, the second constant and the number of each of the available values; Determine the occurrence probability of each of the field values according to the first weight, the randomness function and the first random item; The occurrence probability of the field value is expressed as: Among them, V i is the field value, P(V i ) is the probability of occurrence, i and j are number values, ω i is the first weight of the field value, f(i) is the randomness function, k and h are the first constant and the second constant respectively, n is the total number of all available values of the field value, sin(k·i) and cos(h·i) are the first random terms.
Citation Information
Patent Citations
Test data generation method and device and electronic equipment
CN112073709A
Method, device and equipment for determining test data model and generating test data
CN112231232A