January 25, 2009 - WinTask - The Triangle Test 2

One of the first books on testing that I ever read was "The Art of Software Testing" by Glenford J. Myers
The first paragraph of the book asks the reader to take a short self-test to help demonstrate the difficulty in developing adequate test cases for even a very simple program. The program is widely known as The Triangle Problem (from Gerald Weinberg) or The Triangle Test, and is reproduced here as a WinTask script.
If you compile this script to a .rob file, and give the new or prospective tester a copy of WinTask and the .rob file, she can try testing the program for herself, using test cases she has devised.
You may even choose to intentionally create a buggy version of this script, to see if the new tester can find all of the bugs.
This implementation of The Triangle Test asks the tester for the Expected Results, and keeps track of the correctness of each result.

' ' Triangle Test 2 - Demonstrates testing a simple application ' ' Author: Joe Strazzere ' ' Adapted from Gerald Weinberg and Glenford Myers ' ' This version asks for your expected results ' and indicates correctness in a MsgBox and the Log
Dim Answers$(1000) Dim List1$(3)
' ' The function which actually calculates the triangle type ' It is simple to introduce errors into this code if desired ' Function TriangleType$(side1$,side2$,side3$) s1=Val(side1$) s2=Val(side2$) s3=Val(side3$) If (Str$(s1) <> Ltrim$(Rtrim$(side1$))) or (Str$(s2) <> Ltrim$(Rtrim$(side2$))) or (Str$(s2) <> Ltrim$(Rtrim$(side2$))) Then TriangleType$="INVALID" Else If (s1 <= 0) or (s2 <= 0) or (s3 <= 0) Then TriangleType$="INVALID" Else If (s1 > s2) and (s1 > s3) and (s1 >= s2 + s3)Then TriangleType$="INVALID" Else If (s2 > s1) and (s2 > s3) and (s2 >= s1 + s3)Then TriangleType$="INVALID" Else If (s3 > s1) and (s3 > s2) and (s3 >= s1 + s2)Then TriangleType$="INVALID" Else If (s1 = s2) and (s2 = s3)Then TriangleType$="EQUILATERAL" Else If (s1 = s2) or (s2 = s3) or (s1 = s3) Then TriangleType$="ISOSCELES" Else TriangleType$="SCALENE" EndIf EndIf EndIf EndIf EndIf EndIf EndIf EndFunction
BEGINDIALOG Dialog 347, 362, 550, 317 CAPTION "Triangle Test 2" ICON "Question", 22, 27, 32, 32 TEXT "Enter the three sides and your expected results.", 125, 30 TEXT "Then click OK to analyze, or Cancel to quit.", 125, 50 EDITTEXT Edit1$, 137, 88, 70, 20 EDITTEXT Edit2$, 245, 89, 70, 20 EDITTEXT Edit3$, 346, 88, 70, 20 TEXT "Expected Results:", 137, 134 LISTBOX List1$(), 241, 129, 177, 75, SelList1$ TEXT Type1$, 137, 196 TEXT Type2$, 243, 196 DEFPUSHBUTTON "OK", btnOK, 355, 238, 75, 23 PUSHBUTTON "Cancel", btnCancel, 444, 238, 75, 23 ENDDIALOG
' ' Instructions ' Instr$="" Instr$=Instr$+"The program reads three integer values."+CRLF Instr$=Instr$+CRLF Instr$=Instr$+"The three values are interpreted as representing the sides of a triangle."+CRLF Instr$=Instr$+CRLF Instr$=Instr$+"The program displays a message that states whether the triangle is "+CRLF
Instr$=Instr$+"SCALENE, EQUILATERAL, ISOSCELES or INVALID"
MsgBox(Instr$,64,"Triangle Test 2")
' ' Initial Display ' List1$(0)="INVALID" List1$(1)="SCALENE" List1$(2)="EQUILATERAL" List1$(3)="ISOSCELES"
Type$="" In$=""
CallDialog Dialog,"Triangle Test 2"
' ' Subsequent Display ' Type1$="Type of Triangle: " i=0 Correct = 0 Incorrect = 0
While btnOK = 1 i=i+1 If i > 1000 Then Goto Answers EndIf In$="Input: ["+Edit1$+"] , ["+Edit2$+"] , ["+Edit3$+"]" Type2$=TriangleType$(Edit1$,Edit2$,Edit3$) If SelList1$ = Type2$ Then Correct = Correct + 1 Answers$(i)="CORRECT - "+In$+" Expected: "+SelList1$+" Actual: "+Type2$ Else Incorrect = Incorrect + 1 Answers$(i)="INCORRECT - "+In$+" Expected: "+SelList1$+" Actual: "+Type2$ Endif CallDialog Dialog,"Triangle Test 2" Wend
' ' Assessment of Answers ' Answers: Ans$="" Answers$(0) = "Correct = "+Str$(Correct)+", Incorrect = "+Str$(Incorrect)+CRLF+"--------------------------------" j=0 While Answers$(j) <> "" Ans$=Ans$+Answers$(j)+CRLF Comment(Answers$(j)) j=j+1 Wend
MsgBox(Ans$,64,"Triangle Test 2 - Your Answers")
Any comments on this article? Email Me
|