Вы находитесь на странице: 1из 11

CSC 532:

SOFTWARE TESTING ASSIGNMENT


OSINUGA OLUWASEUN
090805049

LECTURER: PROF. C.O UWADIA

1a. PROGRAM LISTING


Imports System.Data.OleDb
Public Class exam
Dim rdr As OleDbDataReader = Nothing
Dim con As OleDbConnection = Nothing
Dim cmd As OleDbCommand = Nothing
Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=c:\Users\Admin2\exam.accdb;Persist Security Info=False;"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim score As Integer = 0
Dim percent As Integer = 0
Dim a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 As String
Dim result As String
Dim sid As String
'Validate that
there is no empty column when inputting the student id
Try
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or
TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = "" Or
TextBox9.Text = "" Then
MessageBox.Show("Please enter a valid student ID", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
TextBox1.Focus()
Exit Sub
End If
'Validate that answers inputted are either "A" or "B" or "C" or "D" or "E" in caps.
'Comparing the ascii code of each letter
If Asc(CStr(TextBox10.Text)) < 65 Or Asc(CStr(TextBox10.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox11.Text)) < 65 Or Asc(CStr(TextBox11.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox12.Text)) < 65 Or Asc(CStr(TextBox12.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox13.Text)) < 65 Or Asc(CStr(TextBox13.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox14.Text)) < 65 Or Asc(CStr(TextBox14.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)

Exit Sub
End If
If Asc(CStr(TextBox15.Text)) < 65 Or Asc(CStr(TextBox16.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox17.Text)) < 65 Or Asc(CStr(TextBox18.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox18.Text)) < 65 Or Asc(CStr(TextBox18.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If Asc(CStr(TextBox19.Text)) < 65 Or Asc(CStr(TextBox19.Text)) > 69 Then
MessageBox.Show("Answers should either be A, B, C, D or E (IN CAPS)", "Input Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
'Give a zero score for any blank answer
If TextBox10.Text = "" Or TextBox11.Text = "" Or TextBox12.Text = "" Or TextBox13.Text =
"" Or TextBox14.Text = "" Or TextBox15.Text = "" Or TextBox16.Text = "" Or TextBox17.Text = ""
Or TextBox18.Text = "" Or TextBox19.Text = "" Then
score = 0
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Try
'Fetch correct answer key from database
'The answer key is the first record in the database
con = New OleDbConnection(cs)
con.Open()
Dim ct As String = "select q1, q2, q3, q4, q5, q6, q7, q8, q9, q10 from score where id = 1"
cmd = New OleDbCommand(ct, con)
rdr = cmd.ExecuteReader()
If rdr.Read Then
'aasigns correct answer keys to variables
a1 = rdr.GetString(0)
a2 = rdr.GetString(1)
a3 = rdr.GetString(2)
a4 = rdr.GetString(3)
a5 = rdr.GetString(4)
a6 = rdr.GetString(5)
a7 = rdr.GetString(6)
a8 = rdr.GetString(7)
a9 = rdr.GetString(8)
a10 = rdr.GetString(9)
End If

Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
con.Close()
'Increments score by 1 if student's response equals correct answers in the database
If TextBox10.Text = a1 Then
score = score + 1
End If
If TextBox11.Text = a2 Then
score = score + 1
End If
If TextBox12.Text = a3 Then
score = score + 1
End If
If TextBox13.Text = a4 Then
score = score + 1
End If
If TextBox14.Text = a5 Then
score = score + 1
End If
If TextBox15.Text = a6 Then
score = score + 1
End If
If TextBox16.Text = a7 Then
score = score + 1
End If
If TextBox17.Text = a8 Then
score = score + 1
End If
If TextBox18.Text = a9 Then
score = score + 1
End If
If TextBox19.Text = a10 Then
score = score + 1
End If
percent = (score / 10) * 100
TextBox20.Text = score
TextBox21.Text = percent
Try
'stores students id, score and percentage into the database
con = New OleDbConnection(cs)
con.Open()
Dim cb As String = "insert into
score(1,2,3,4,5,6,7,8,9,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,m,p) values(@d1, @d2, @d3, @d4, @d5,
@d6, @d7, @d8, @d9, @d10, @d11, @d12, @d13, @d14, @d15, @d16, @d17, @d18, @d19,
@d20, @d21)"

cmd = New OleDbCommand(cb, con)


cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New
cmd.Parameters.Add(New

OleDbParameter("@d1", OleDbType.VarChar, 10, "1"))


OleDbParameter("@d2", OleDbType.VarChar, 10, "2"))
OleDbParameter("@d3", OleDbType.VarChar, 10, "3"))
OleDbParameter("@d4", OleDbType.VarChar, 10, "4"))
OleDbParameter("@d5", OleDbType.VarChar, 10, "5"))
OleDbParameter("@d6", OleDbType.VarChar, 10, "6"))
OleDbParameter("@d7", OleDbType.VarChar, 10, "7"))
OleDbParameter("@d8", OleDbType.VarChar, 10, "8"))
OleDbParameter("@d9", OleDbType.VarChar, 10, "9"))
OleDbParameter("@d10", OleDbType.Char, 10, "q1"))
OleDbParameter("@d11", OleDbType.Char, 10, "q2"))
OleDbParameter("@d12", OleDbType.Char, 10, "q3"))
OleDbParameter("@d13", OleDbType.Char, 10, "q4"))
OleDbParameter("@d14", OleDbType.Char, 10, "q5"))
OleDbParameter("@d15", OleDbType.Char, 10, "q6"))
OleDbParameter("@d16", OleDbType.Char, 10, "q7"))
OleDbParameter("@d17", OleDbType.Char, 10, "q8"))
OleDbParameter("@d18", OleDbType.Char, 10, "q9"))
OleDbParameter("@d19", OleDbType.Char, 10, "q10"))
OleDbParameter("@d20", OleDbType.VarChar, 10, "m"))
OleDbParameter("@d21", OleDbType.VarChar, 10, "p"))

cmd.Parameters("@d1").Value = TextBox1.Text
cmd.Parameters("@d2").Value = TextBox2.Text
cmd.Parameters("@d3").Value = TextBox3.Text
cmd.Parameters("@d4").Value = TextBox4.Text
cmd.Parameters("@d5").Value = TextBox5.Text
cmd.Parameters("@d6").Value = TextBox6.Text
cmd.Parameters("@d7").Value = TextBox7.Text
cmd.Parameters("@d8").Value = TextBox8.Text
cmd.Parameters("@d9").Value = TextBox9.Text
cmd.Parameters("@d10").Value = TextBox10.Text
cmd.Parameters("@d11").Value = TextBox11.Text
cmd.Parameters("@d12").Value = TextBox12.Text
cmd.Parameters("@d13").Value = TextBox13.Text
cmd.Parameters("@d14").Value = TextBox14.Text
cmd.Parameters("@d15").Value = TextBox15.Text
cmd.Parameters("@d16").Value = TextBox16.Text
cmd.Parameters("@d17").Value = TextBox17.Text
cmd.Parameters("@d18").Value = TextBox19.Text
cmd.Parameters("@d19").Value = TextBox19.Text
cmd.Parameters("@d20").Value = score
cmd.Parameters("@d21").Value = percent
cmd.ExecuteReader()
MessageBox.Show("Successfully saved", "Student Score", MessageBoxButtons.OK,
MessageBoxIcon.Information)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'Displays the students id, score and percentage on the screen
sid = TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text + TextBox5.Text +
TextBox6.Text + TextBox7.Text + TextBox8.Text + TextBox9.Text
result = sid & vbTab & TextBox20.Text & vbTab & TextBox21.Text & vbCrLf
ListBox1.Items.Add(result)

End Sub
End Class

1b. OUTPUT

WHITE BOX TESTING


(Control Flow Graph)

CY
CLOMATIC COMPLEXITY

1. V(G) = 5 regions
2. V(G) = 20 Edges 17 Nodes + 2 = 5
3. V(G) = 4 Predicate Nodes + 1 = 5

BASIS PATHS
P1: 1-2-4-6-8-9-10-12-13-14-15-16-17
P2: 1-2-4-6-7-8-9-10-12-13-14-15-16-17
P3: 1-2-4-6-7-8-9-10-12-13-14-15-16-17
P4: 1-2-3-1-
P5: 1-2-4-5-1-.

CREATING TESTS:
(E.g. Assume key answers to be

A D A B E C C D B E)

Path 1 test case: Valid and non-empty responses but has wrong answers
Value (Path 1) = 090805049ADABEECDBE
Expected Result: Correct output of score and percentage. Score is Zero for
every wrong answer

Path 2 test case: Valid answers which consists of blank responses


Value (Path 2) = 090805049,,,ADAEEBE
(Where , is a blank answer)
Expected Result: Score is zero for every blank response

Path 3 test case: Valid, non-empty responses and correct answers


Value (Path 3) = 090805049ADABEECDBE
Expected Result: Correct output of score and percentage.

Path 4 test case: Empty students ID


Value (Path 4) =,,,,,,,,, ADABEECDBE
(Where , represent a blank id)
Expected Result: Error Message

Path 5 test case: Responses aside A, B, C, D, E


090805049ADABGHABBB
Expected Result: Error Message

EQUIVALENT PARTITIONING TECHNIQUES


1. Student ID:
Input Condition: non-empty 9 digit length
Chosen Values: 090805049, 090805008
2. Answers:
Input Condition:
a. Boolean: An answer may or may not be present
b. Set: An answer must be either A or B or C or D or E
c. Range: input must be between 0 and 10 answers
Chosen Values: ADDADADDAA
ADD DAA AA

Вам также может понравиться