User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 2 of 2
  1. #1
    Moderator JakeBrake's Avatar
    Join Date
    Dec 2000
    St. Louis - Year 2025
    Post Thanks / Like
    0 Post(s)
    0 Thread(s)
    Total Downloaded

    ** UnitTest Lesson # 01

    <font color="red">For all members! </font>
    Identify Inputs For Unit Testing - Part I
    Please feel free to participate. This is a pilot run of interactive training. Please read all.
    So please do jump in here and provide your test cases along with why. I or someone will try to give review comments/questions once weekly along with a new lesson.

    <font color="blue">Purpose of this exercise: </font>Identify and list test cases.

    Source code is in blue along with code commentary. That does not mean it is starved of oxygen. [img]/images/graemlins/smile.gif[/img]
    <font class="small">Code:</font><hr /><pre>
    ' Begin COPY POINT
    <font color="blue">
    ' 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”
    ' Initializes 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 - True.

    Function IsEven( ValueIN)
    IsEven = FALSE
    If (ValueIN Mod 2) = 0 Then
    IsEven = TRUE
    End If
    End Function

    '----------------- MAIN ---------------------------------------------------
    ' Main program to call “IsEven” It’s only job is to do three things in one statement:
    ' 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
    msgbox IsEven (23) '' &lt;- Change this value to experiment
    '------------------ END MAIN --------------------------------------------------

    </pre><hr />
    '- Copy/paste from top Begin COPY POINT to END COPY POINT
    above, to a file and not beyond. See further below for filing instructions.
    ' Why VBScript? You can run it on your desktop and experiment
    ' How?
    ' 1. Copy/paste the code into a new text file
    ' 2. Change the name to MyUnitTestLesson1.vbs
    ' 3. Double-click the icon to execute
    ' 4. Right-mouse over the file icon – select edit to edit it.
    ' 5. Change the numeric value in the msgbox IsEven call
    ' 6. Save and re-run

    This assumes that “unit” means one tests to the visible source code. For
    Our purposes “unit” is the same as “module” or “component”. This type of
    testing is unit testing and is also known as white-box, glass-box, or clear-box.

    [] What are some test cases you can come up with?
    [] How would you prove that the function does what it suggests?
    [] How would you expose it’s defects?

    Hint! Since there are no hard requirements, might there be some
    implied requirements as suggested by the name and implementation?

    [] Might there be defects with respect to the implied requirements?

  2. #2
    Join Date
    Sep 2005
    Dublin, Ireland
    Post Thanks / Like
    0 Post(s)
    0 Thread(s)
    Total Downloaded

    ** UnitTest Lesson # 01

    Ok, to get the ball rolling, i threw a few obvious ones;


    and got the expected correct results with negatives. So next to range, i tried a couple of numbers around plus and minus 2^15 and 2^16 (two byte integers with and without sign bits)


    All works ok on 16 bit boundaries, how about 32 bit


    and out script crashes on -2147483649 and above, maybe a range check in our function is in order, and provision for throwing an exception or having a third return value for illegal input.

    Now onto implicit type conversion and rounding


    according to VBScript -0.49,-0.5,0.49 and 0.5 are even, whereas -0.51 and 0.51 are odd. Implicit conversions from floating point to 32 bit integer are converting 0.5 to 0 rather than 1, as per the IEEE standard to "go to the even number". Nothing wrong here, but possibly confusing to the newbie.


    Cool, our scripting language seems ok with implicit conversion of strings to integeres. Howabout any of these


    Nope, crashed out on all of the above with type mismatch errors.

    So we have established that our function appears to work correctly, albeit within the range of plus or minus two to the thiry-one, that it's implicit conversion of floating point numbers within this range uses IEEE rounding conventions, and that it will bomb out / throw an exception for out of range or mismatched data. IMO, given the simplicity of the function, there is no reason for a more thorough proof, although you could laboriously iterate through all the odd and even legal integer input values if desired. The requirements could be changed to state range and type limitations if you were unsure about the strength of your development team. It's interesting how you would approach this, some would specify exception handlers for the range and type errors. Personally, I use C++ rather than VBscript and adopt a programming by contract approach in which every function includes pre and post condition checks to verify the correctness of input and returned values.

    Lastly, on my twin screen workstation, VBScript left the message box on the screen after the application exited either normally or abnormally. Since this is a an error in the unit test code rather than function being tested, I'll put it down as being outside of the scope of the exercise [img]/images/graemlins/wink.gif[/img]



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 12.00%
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 08:25 PM.

Copyright BetaSoft Inc.