Thanks:  0
Likes:  0
Dislikes:  0

# Thread: ** UnitTest Lesson # 02

1. ## ** UnitTest Lesson # 02

This is for anyone!

Assignment:
First, Read the Unit Test Lessons Overview - under this link. The overview contains important instructions and other pertinent information.

For this lesson:
<font color="blue">Primary Goal:</font>
List cases to prove that the code to determine if a number is Even or Odd is correct.
SPECIFICATION:
This unit shall determine whether an input value is even or odd.

<font color="blue">Secondary Goals:</font>

Determine and list test cases plus any reasons for your test cases - to validate the following unit specifications. Note that you may ask for specification clarification and even note spec defects, gaps, etc.
<font color="blue">

IT SHALL:
1. It shall prompt the user for input
2. It shall exit silently if input is canceled.
3. It shall reject any non-numeric data and reprompt
4. It shall popup a window with the results - odd or even, and
5. It shall supply/echo the value originally input
6. It shall give the user the option of inputting another value or quitting. The program shall behave accordingly.
7. It shall on input error - include the error in the reprompt.

ASSUMPTIONS:
Assume that this will work safely within the range -32,767 to + 32,767.

</font>

<font class="small">Code:</font><hr /><pre>
'- Copy/paste from this point to the indicated point at the end of the post.
' This VBScript function tests to see if a value passed is an even value.
' It returns the result of the value test in the name of the function
' itself = “IsEven”
' More… we initialize the value of “IsEven” to Boolean FALSE (Zero)
' This is intended to simplify the IF / END IF Block
' The MOD operator simply says Divide ValueIN by the value to the
' right of MOD (2) and capture the remainder. If the remainder is Zero
' we can assume an even number.
' The Abs function forces the absolute value of a number to be evaluated
'-----------------------------------------------------------------------------------
<font color="blue">Function IsEven( ValueIN )
Dim tmpMODResult

IsEven = FALSE
On Error Resume Next
Err.Clear
tmpMODResult = Abs(ValueIN) Mod 2
If Err.Number &gt; 0 Then
tmpMODResult = Err.Number
End If
If (tmpMODResult) = 0 Then
IsEven = TRUE
End If
End Function
'---------------------------------------------------------------------------------
'----------------- BEGIN MAIN -------------------------------------------------
' All variables within are implicit for this lesson.
' 1. Put up a message box, after
' 2. Passing a value to “IsEven”, and
' 3. Capturing the result of the call to the “IsEven” function

Again = vbYes
FailureMessage = ""
Do
Do

RePrompt = False
testCase =InputBox("Test Case Capture" &amp; Chr(10) &amp; chr(13) &amp; FailureMessage,"Input Test Case: ")
If IsNumeric(testCase) = False Then
RePrompt = True
FailureMessage = "Failed on Non-numeric input '" &amp; testCase &amp; "' Try again."
End If
Loop While RePrompt = True

If testCase = "" Then Exit Do End If
Result = IsEven (testCase) ''' This is the call to the IsEven Function
If Result Then
Detail = "' is an Even Number"
Else
Detail = "' is an Odd Number"
End If
Msgbox "It is determined that '" &amp; testCase &amp; Detail, vbOKOnly, "Results of Odd/Even Evaluation"
Again = Msgbox ("Another case?", vbYesNo, "Continue?")
Loop While Again = vbYes

'------------------ END MAIN --------------------------------------------------
</font>
'- Copy/paste from top to this point to a file and not beyond.
</pre><hr />

<font color="blue">Upcoming Lessons: </font>
== Truth tables
== Explore Stubs and drivers

2. ## ** UnitTest Lesson # 02

Let us focus on the general specification:

"This unit shall determine whether an input value is even or odd."

What values or data would you input? Bear in mind the assumption: "Assume that this will work safely within the range -32,767 to + 32,767."
.
.
Anyone?

3. ## Re: ** UnitTest Lesson # 02

Okay, I'm very new at this so forgive me if this is too much:
----------------------------------
TC1:
Input: 2, Ok
Expected Output:
-A window must pop up indicating if the input is even. (See Open Point #1)
Result: Pass
Reason: Smoke test to verify that it even works.

TC2:
Input: 3, Ok
Expected Output:
-A window must pop up indicating if the input is odd.
Result: Pass
Reason: testing the alternate path

TC3:
Input: 1.000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000555, Ok
Expected Output:
- the number "1.00000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000555" is echoed on the output.
Result: Pass
Reason: verifying the requirement and verifying that the box can wrap around without problems.

TC4:
Input: no input, Ok
Expected Output: See Open Point #2:
Result: Failed on Non-Numeric Input '' Try Again. (see Open Point #2)
Reason: testing blank value

TC5:
Input: Any input, Cancel
Expected Output: The program exits gracefully with no warnings or errors
Result: Pass
Reason: verifying Cancel function

TC6:
Input: AOQA, Ok
Expected Output: Program rejects and reprompts, supplying the error (See Open Point #4)
Result: Pass
Reason: verifying that alpha content is rejected

TC7:
Input5.5 x 10^2), Ok
Expected Output: See Open Point #3
Reason: checking latent functionality

TC8:
Input:Any numeric input, Ok
Expected Output:
After the message, the user is given the option of inputting another value or quitting.
Result: Pass
Reason: Testing requirement

TC9:
Input: 00000001.000010000
Expected Output: A window must pop up indicating if the input is odd.
Result: Pass (See Open point #5)
Reason: testing "non-numeric numbers"

TC10:
Input: Any numeric input, Ok, user selects to input another value
Expected Output: User is prompted for another value.
Result: Fail - the box prompt includes the text from the most recent error and is not a "fresh" prompt. (See Open Point #6)
Reason: testing requirement

TC11:
Input: Any numeric input, Ok, user selects not to input another value
Expected Output: Program exits gracefully with no warnings or errors
Result: Pass
Reason: Testing requirement

TC12:
Input: -222222, Ok
Expected Output: A window must pop up indicating if the input is even.
Result: Pass
Reason: testing negative numbers

Open points:
1.The language of the responses was not specified.
2. Behavior for blank input is not specified - right now it is treated like a non-numeric value. Is this okay?
3. Formulas are rejected as non-numeric. Is this okay?
4. The language of the errors was not specified.
5. Trailing and leading zeroes are not trimmed. Is this okay?
6. Should the user be prompted with a different message on test cases after a successful case?

4. ## Re: ** UnitTest Lesson # 02

Clint, I can respond tonight about 9pm CDT.

<font color="red"> Postponed due to bridge collapse in MSP. </font>

Anyone else wish to evaluate Clint's material?

5. ## Re: ** UnitTest Lesson # 02

Clint,

All good stuff, apart from for TC12 which is actually passing a number outside of the stated working range for the sub-routine in question, i.e. -222,222 where input of -32,767 to + 32,767 is expected. In this case, I would suggest that the sub-routine should pop-up an 'input out of range' warning and continue onto the next input. Test cases using -32767,-32768,32767 and 32768 are possibly useful additions to your suite. I would also consider -0.5 and 0.5 to determine how implicit conversion of floating point to integers is handled.

Jim,

Should the assumptions either state that the input should be an signed integer, or state how rounding / truncation occurs? Should the code perform range checks on the input based on stated assumptions and report out of range input values? In C style languages I would add 'assert' derived statements to validate the input value and returned results.

6. ## ** UnitTest Lesson # 02

Shane, thank you! Re assumptions...
Would this do it?

"Assume that this will work with integers only in the range -32,767 to + 32,767."

7. ## Re: ** UnitTest Lesson # 02

Hey I just saw this thread. Pretty cool. Like smacl had pointed out I would have added cases specifically for right at the range limit and exceeded by one. I would have also added a TC for just "zero". I would have added a test case for a numeric value starting with a space and one ending with a space. I would have added several more to attempt to "get out" of the statement (if that makes sense). such as apostrophes, backslashes, ampersands, and quotation marks.

TC13:
Input: 0, Ok
Expected Output: A window must pop up indicating if the input is even.
Result: Pass
Reason: testing zero

TC14:
Input: -0, Ok
Expected Output: A window must pop up indicating if the input is even.
Result: Pass
Reason: testing zero

TC15:
Input: 0123, Ok
Expected Output: A window must pop up indicating the input is odd.
Result: Pass
Reason: testing zero padding

TC16:
Input: '5', Ok
Expected Output: A window must pop up indicating the value is not numeric.
Result: Pass
Reason: attempting to exit statement

TC17:
Input: /5, Ok
Expected Output: A window must pop up indicating the value is not numeric.
Result: Pass
Reason: attempting to exit statement

TC18:
Input: &amp;5, Ok
Expected Output: A window must pop up indicating the value is not numeric.
Result: Failed, window indicated string was odd number.
Reason: attempting to exit statement

TC19:
Input: "5", Ok
Expected Output: A window must pop up indicating the value is not numeric.
Result: Pass
Reason: attempting to exit statement

What do you think? Would all of these cases fall under "Unit testing"?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.34%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:12 AM.