Created
February 6, 2017 23:42
-
-
Save LucienBrule/40128ca28d4b9688ccb8fd9fc5729dd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Copyright 2017 , Lucien Brule & RPI CSCI1010 | |
'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
'The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
Public Class frmTestCaseExample | |
Private Sub btnIsEven_Click(sender As Object, e As EventArgs) Handles btnIsEven.Click | |
If (isEven(nudNumber.Value)) Then | |
lblOutMessage.Text = "Yep, " + Convert.ToString(nudNumber.Value) + " is even" | |
Else | |
lblOutMessage.Text = "Nope, " + Convert.ToString(nudNumber.Value) + " isn't even" | |
End If | |
End Sub | |
'Step 0: Write a function header and determine what it should do | |
'protip: It should do the minimal work required to still provide value | |
' (ie this function only takes integers and determines if they are even on a true false | |
' -- basis, nothing else) | |
Private Function isEven(number As Integer) | |
'Step 1: Do the minimal amount to make the tests pass | |
' Return True | |
'Step 2: (write a test in range of possible function outputs that makes the tests fail) | |
'Step 3: ammend your code so that the passes | |
If ((number Mod 2) = 0) Then | |
Return True | |
Else | |
Return False | |
End If | |
End Function | |
Private Function runTests() | |
'Say that tests are running | |
Console.WriteLine("Running tests...") | |
'Test is Even given 0 should return True | |
If (isEven(1)) Then | |
Console.WriteLine("Should say that 0 is even") | |
Return False | |
End If | |
'Test is Even given 1 should return False | |
If (isEven(1)) Then | |
Console.WriteLine("Should say that 1 Is Not even (return False)") | |
Return False | |
End If | |
'Test is Even given 2 should return True | |
If (Not isEven(2)) Then | |
Console.WriteLine("Should say that 2 is even (return True)") | |
Return False | |
End If | |
'If we got down past all of the tests, then all of them passed, ergo return True. | |
Console.WriteLine("All Tests passed") | |
Return True | |
End Function | |
Private Sub frmTestCaseExample_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
'Since we don't have an external module, let's run the tests at startup | |
runTests() | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment