Software testing Technology (IV.)--Leap year judgment + Int. How to resolve a parse error

Source: Internet
Author: User

Target Program

This test of the target program is a leap year judgment, we know that the general period of time is divisible by 4 can be, but if you encounter a century, but also need to be divisible by 400, so there is the following logical judgment:

<textarea class="js" name="code" rows="15" cols="100">bool Isrunnian = false;if (Year > 0) {if (year% = = 0 && Year% 400 = = 0) | | (Year% + = 0 && Year% 4 = = 0)) {Isrunnian = true; }}</textarea>

Test Method Introduction-syntax-based Testing

BFF Paradigm--the Backus paradigm, is a language used to represent context-independent grammars, and context-independent grammars describe a class of formal languages. It is a set of symbols introduced first by John Bacos (John Backus) and Peter Nore (Peter Naur) to describe computer language syntax. (From Wikipedia)

It is somewhat similar to the regular grammar we have learned, but the regular grammar corresponds to the Chomsky hierarchy of Type 3 grammar, also called the formal grammar, corresponding to the finite state automata. The BFF paradigm is a Type 2 grammar, also called context-independent grammar. We know that the 0-3 grammar has one more constraint per layer, and it's simpler. I also search for information, BFF paradigm is more applied to research, regular grammar is a variety of languages have done library functions, can be easily called to write grammar, string matching.

With the grammar, we can make a judgment of the input string. As the book says, "One of the interesting things that grammars does is describe. The author proposes 3 coverage criteria: MC, MOC, MPC

(1) Mutation Coverage (MC): For each mutant m∈m, T R contains exactly one requirement, to kill M.

(2) Mutation Operator Coverage (MOC): For each mutation operator, TR contains exactly one requirement, to create a mutated string m so is derived using the MU Tation operator.

(3) Mutation Production Coverage (MPC): For each mutation operator, and each production the operator can is applied to, T R contains the requirement to creat e a mutated string from the that production.

P.S here mutant operator means a rule that can be applied to a certain change in the string that this grammar is capable of producing. Mutant is a string that is generated by applying mutant operator. The original meaning of Kill was given a mutant m m for a derivation D and a test T, T was said to kill M if and only if the output of T in D is different from the output of T on m . My understanding is that for Test T and Mutant M, the output of the two is different then this test case T will kill the original mutant M.

In this procedure, if you do not pre-process, directly assume that the input is legitimate, then use Int. Parse is prone to errors, such as entering ab400, which can occur:

So, I used the regular expression to enter the judgment, the code is as follows:

<textarea class="js" name="code" rows="15" cols="100">Regex reg = new Regex ("^[1-9]+[0-9]*$"); Regex reg1 = new Regex ("^-[1-9]+[0-9]*$"), if (Reg. IsMatch (TextBox1.Text) ==false) && (REG1. IsMatch (TextBox1.Text) ==false) {if (textBox1.Text.Length <=1) {TextBox1.Text = ""; } else {TextBox1.Text = TextBox1.Text.Remove (textbox1.text.length-1); } label2. Text = "Please enter a valid year, such as-1 or 2015"; Label2. ForeColor = color.red;}</textarea>

The function is to make certain corrections when the input is not valid. To make sure that int. Parse () does not make an error. For example, when you enter ABC, it appears:

So the shape such as 3, 2015, 300 are legal input, shape such as 0, ABC is illegal input, a little application of divergent thinking and MPC rules to think of some invalid mutation formation of the test cases are as follows.

Test Cases

Number

Input

Expected output

Actual output

0

4

4 years is a leap year

4 years is a leap year

1

-1

1 BC is a leap year

1 BC is a leap year

2

5

5 years is not a leap year

5 years is not a leap year

3

400

400 years is not a leap year

400 years is not a leap year

4

ab400

Please enter a valid year, such as 1 or 2015

Please enter a valid year, such as 1 or 2015

5

#%$

Please enter a valid year, such as 1 or 2015

Please enter a valid year, such as 1 or 2015

6

0

Please enter a valid year, such as 1 or 2015

Please enter a valid year, such as 1 or 2015

Software testing Technology (IV.)--Leap year judgment + Int. How to resolve a parse error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.