Perera 10449314 Csi3105 1
Perera 10449314 Csi3105 1
Perera 10449314 Csi3105 1
The information on this coversheet will be included in Turnitin’s similarity analysis; however, your lecturers are
aware of this and will disregard it.
Student Details
Student Number 1 0 4 4 9 3 1 4
Unit Details
Manual Submission
If handing in an assignment in a paper or other physical form, sign here to indicate that you have read this form, filled it in
completely and that you certify as above.
Electronic Submission
OR, if submitting this paper electronically as per instructions for the unit, place an ‘X’ in the box below to
indicate that you have read this form and filled it in completely and that you certify as above. Please
include this page with your submission. Any responses to this submission will be sent to your ECU
email address.
21/May/2018
Agreement select check box Date
For procedures and penalties on late assignments please refer to the University Admission, Enrolment and Academic Progress
Rules - rule 24, and the ECU Course and Unit Delivery and Assessment Policy
The information on this coversheet will be included in Turnitin’s similarity analysis; however, your lecturers
are aware of this and will disregard it.
The ECU English Language Proficiency Measure (Feb 2014)
Levels of proficiency Low proficiency Developing Moderate proficiency High proficiency
proficiency
Incorrect or inappropriate Aspects of writing are Aspects of writing are
aspects of writing Incorrect or inappropriate mostly accurate. appropriate and
Aspects of writing obscure meaning in aspects of writing Mistakes rarely affect optimally constructed,
(Indicate with an X main area(s) many places. obscure meaning in clarity of meaning. allowing clarity of
needing improvement) some places. Minor editing needed to meaning.
Significant editing needed clarify the meaning, Meaning is clear and
to clarify the meaning, Some editing needed to along with careful needs only a light
along with extensive clarify the meaning, proofreading to correct proofread to correct
proofreading to correct along with extensive technical errors. technical errors.
technical errors. proofreading to correct
technical errors.
Sentence structure
1. sentence completeness
2. sentence length
3. phrase/clause order
4. use of conjunctions
5. word order
6. punctuation
Word use
7. word choice
8. word form
9. word omission/redundancy
11. spelling
12. apostrophes
1. Sentence completeness: sentence includes subject, verb a 7. Word choice: words are correct and appropriate for
complete thought. the context.
2. Sentence length: length is appropriate to context or 8. Word form: correct part of speech is used, e.g., [to]
disciple affect / [the] effect.
9. Word omission/redundancy: words should not be
3. Phrase/clause order: parts of the sentence (phrases and
missing or be unnecessarily repetitive.
clauses) are ordered logically.
10. Verb tense/agreement: correct use of verbs that
4. Use of conjunctions: linking words are used correctly to
indicate time and correct word forms that agree
show the relationship between ideas.
grammatically with other words in the sentence.
5. Word order: words are ordered correctly in a sentence.
11. Spelling: correct spelling is used.
6. Punctuation: the correct use of full stops, commas,
12. Apostrophes: indicate ownership or contraction.
semicolons, colons and capitals.
MATHEMATICAL CONCEPTS,
BLACK-BOX TESTING & JUNIT
Assessment 01
Minor Assessment 01
Table of Contents
Task A: Mathematical Preliminaries ..........................................................................................1
1. Truth Values ...................................................................................................................1
2. Boolean Expression (leap year)......................................................................................1
3. Boolean Expression (variable x) .....................................................................................1
4. Regular Expression .........................................................................................................1
Task B: Control Flow Graph........................................................................................................1
1. List all Paths ...................................................................................................................1
2. Control Flow Graph ........................................................................................................1
2.1. Description of basis path .........................................................................................2
2.2. List of the set of basis path ......................................................................................2
Task C: Black-box Testing and Junit ...........................................................................................3
1. Payroll Program using Eclipse ........................................................................................3
2. Testing ............................................................................................................................7
2.1. Equivalence Partitioning (EP): .................................................................................7
2.1.1. Input Domain....................................................................................................7
2.1.2. Equivalence Classing ........................................................................................8
2.1.3. Combine Equivalence Classes ..........................................................................9
2.1.4. Infeasible Equivalence Classes .........................................................................9
2.1.5. Weak / Strong Equivalence Class Testing.........................................................9
2.2. Boundary Value Analysis (BVA) .............................................................................11
2.2.1. Hours Worked ................................................................................................11
2.2.2. Hourly Rate for Employee Type C ..................................................................11
2.2.3. Hourly Rate for Employee Type P ..................................................................12
2.2.4. Hourly Rate for Employee Type F...................................................................12
2.3. Test Cases ..............................................................................................................13
2.3.1. Function to be tested: validateEmpID ...........................................................13
2.3.2. Function to be tested: validateEmpType .......................................................14
2.3.3. Function to be tested: validateHourlyRate for Employee Type C..................15
2.3.4. Function to be tested: validateHourlyRate for Employee Type P ..................16
2.3.5. Function to be tested: validateHourlyRate for Employee Type F ..................17
2.3.6. Function to be tested: validateHrsWorked ....................................................18
2.4. JUnit .......................................................................................................................19
2.4.1. Employee ID Test ............................................................................................19
2.4.2. Employee Type Test .......................................................................................20
2.4.3. Hourly Rate Test .............................................................................................20
2.4.4. Hours Worked Test.........................................................................................22
Appendix ..................................................................................................................................23
1. Screenshots ..................................................................................................................23
1.1. JUnit .......................................................................................................................23
1.2. Employee ID ...........................................................................................................25
10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 01
Tables of Figures
Figure 1: Control Flow Graph .....................................................................................................1
Figure 2: BVA of hours worked ................................................................................................11
Figure 3: BVP of hourly rate - type C........................................................................................11
Figure 4: BVP of hourly rate - type P........................................................................................12
Figure 5: BVP of hourly rate - type F ........................................................................................12
Figure 6: JUnit Tests Screenshot ..............................................................................................23
Figure 7: JUnit execution on All Tests ......................................................................................24
Table of Tables
Table 1: List of set of basis path .................................................................................................2
Table 2: Input Domain ...............................................................................................................7
Table 3: Equivalence Classing ....................................................................................................8
Table 4: Infeasible Equivalence Classes .....................................................................................9
Table 5: Weak Equivalence Class ...............................................................................................9
Table 6: Strong Equivalence Class ............................................................................................10
Table 7: Test case for Employee ID ..........................................................................................13
Table 8: Test case for Employee Type .....................................................................................14
Table 9: Test case for hourly rate - type C ...............................................................................15
Table 10: Test case for hourly rate - type P .............................................................................16
Table 11: Test case for hourly rate - type F .............................................................................17
Table 12: Test case for hours worked ......................................................................................18
10449314 Page |2
CSI3105 SOFTWARE TESTING – Minor 01
a) P(81) - True
b) P(27) - False
c) P(121) - False
d) P(225) - True
4. Regular Expression
a) True
b) True
c) True
d) False
10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 01
P1 = [ 1 – 2 – 3 – 5 – 7 ]
P2 = [ 1 – 2 – 3 – 5 – 6 – 7 ]
P3 = [ 1 – 3 – 4 – 7 ]
P4 = [ 1 – 3 – 5 – 7 ]
P5 = [ 1 – 3 – 5 – 6 – 7 ]
Total: 5 Paths
Assumptions:
Assuming that will have to get the file first in order to run the while loop, I have
added a statement at the beginning of the code to get the file. X: Get the File
10449314 Page |1
CSI3105 SOFTWARE TESTING – Minor 01
Basis path includes one or more linearly independent complete paths through a given CGF of a particular
program and each path is known as basis path. It is used for testing which is based on a white box method
in order to create test cases and it involves execution of all possible blocks in a program and obtains
maximum path coverage with least number of test cases. The test cases are based on the flows or logical
path taken from the program.
A basis path is also known as basis set, where the objective is to evaluate the CFG to define a set of linearly
independent paths of execution and it covers all the nodes and edges. Number of basis path is equal to
the cyclomatic complexity, according to the above CFG diagram in Figure 1 the cyclomatic complexity is
equal to:
V(G) = Edges – Nodes + 2
= 11 – 9 + 2 = 4
The following lists all the paths of CFG drawn in Figure 1 above:
E = { (Start, A), (A, B), (A, J), (B, D), (B, C), (C, A), (C, H), (D, F), (D, E), (F, G), (E, G), (G, H), (H, J), (J, End) }
P1 = [ A – J ]
P2 = [ A – B – D – F – G – H – J ]
P3 = [ A – B – D – E – G – H – J ]
P4 = [ A – B – C – H – J ]
Total Paths: 4 paths
10449314 Page |2
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Student Name: Bernedette Perera
* Student ID : 10449314
* Unit : Software Testing | CSI3105
*/
import javax.swing.*;
import java.text.DecimalFormat;
/**
* Employee ID and Employee Type
*/
String empID = "",
empType = "";
/**
* Hours Worked for the week
*/
int hrsWorked = 0;
/**
* Hourly Rate and Total Wages
*/
double hourlyRate = 0,
totalWages = 0;
/**
* Validation Check on
* Employee ID, Employee Type, Hours Worked, Hourly Rate
*/
boolean isValidEmpID = false,
isValidEmpType = false,
isValidHrsWorked = false,
isValidHourlyRate = false;
/**
* Input for Employee ID
*/
do {
String temp = JOptionPane.showInputDialog("Enter your Employee ID:");
empID = validateEmpID(temp);
if (empID != "0") {
isValidEmpID = true;
}
}while (!isValidEmpID);
10449314 Page |3
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Input for Employee Type
*/
do {
String temp = JOptionPane.showInputDialog("Enter your Employee Type:");
empType = validateEmpType(temp.toUpperCase());
if (empType != "0") {
isValidEmpType = true;
}
}while (!isValidEmpType);
/**
* Input for Hourly Rate
*/
do {
String temp = JOptionPane.showInputDialog("Enter your hourly rate:");
hourlyRate = validateHourlyRate(empType, temp);
if (hourlyRate != 0) {
isValidHourlyRate = true;
}
}while (!isValidHourlyRate);
/**
* Input for Hours Worked
*/
do {
String temp = JOptionPane.showInputDialog("Enter your worked
hours for this week:");
hrsWorked = validateHrsWorked(temp);
if (hrsWorked != 0) {
isValidHrsWorked = true;
}
}while (!isValidHrsWorked);
/**
* Get Total Wages for the week
*/
totalWages = calculateWages(hourlyRate, hrsWorked);
/**
* Output of the Payroll Program
*/
JOptionPane.showMessageDialog
(null,
"Employee ID: " + empID + "\n" +
"Employee Type: " + empType + "\n" +
"Hours Worked: " + hrsWorked + " hours" + "\n" +
"Weekly Gross Pay: " + "$" + totalWages
);
}
10449314 Page |4
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Validate Employee ID
* @param id
* @return String
*/
public static String validateEmpID(String id) {
int empID;
if (id.length() == 5) {
try {
empID = Integer.valueOf(id);
}catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "Error: Employee ID must
contain only numbers!");
return "0";
}
id = Integer.toString(empID);
/**
* Validate Employee Type
* @param type
* @return String
*/
public static String validateEmpType(String type) {
10449314 Page |5
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Validate Hourly Rate for Employee Type C, P, F
* @param hrs
* @param type
* @return double
*/
public static double validateHourlyRate(String type, String rate) {
double hourlyRate;
try {
hourlyRate = Double.parseDouble(rate);
}catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error: Hourly Rate must
be numeric!");
return 0;
}
if (type.equals("C") && !(hourlyRate >= 20 && hourlyRate <= 35)) {
JOptionPane.showMessageDialog(null, "Employee Type " + type +
" do not match the hourly rate");
return 0;
}else {
return hourlyRate;
}
}
/**
* Validate Hours Worked
* @param hrs
* @return int
*/
public static int validateHrsWorked(String hrs) {
int hrsWorked;
try {
hrsWorked = Integer.parseInt(hrs);
}catch(NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Error: Hours Worked must
be numeric!");
return 0;
}
if (hrsWorked < 20 || hrsWorked > 60) {
JOptionPane.showMessageDialog(null, "Error: Enter a valid
number for Hours Worked!");
return 0;
}
else {
return hrsWorked;
}
}
10449314 Page |6
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Calculate Weekly Gross Pay
* @param rate
* @param hrs
* @return double
*/
public static double calculateWages(double rate, int hrs) {
}
}
2. Testing
empType String { C }, { P }, { F }
10449314 Page |7
CSI3105 SOFTWARE TESTING – Minor 01
Variables Partition
{
{ empID >= 00000 },
{ 00000 <= empID <= 99999 },
empID
{ empID <= 99999 },
{ invalid_1 }
}
{
empType { C }, { P }, { F }, { invalid_2 }
}
{
{ hrsWorked >= 20 },
{ 20 <= hrsWorked <= 60 },
hrsWorked
{ hrsWorked <= 60 }
{ invalid_3 }
}
{
{
{ hourlyRate >= 20 },
{ 20 <= hourlyRate <= 35 },
{ hourlyRate <= 35 }
},
{
{ hourlyRate >= 30 },
{ 30 <= hourlyRate <= 45 },
hourlyRate { hourlyRate <= 45 }
},
{
{ hourlyRate >= 35},
{ 35 <= hourlyRate <= 50},
{ hourlyRate <= 50}
},
{ invalid_4 }
}
Table 3: Equivalence Classing
10449314 Page |8
CSI3105 SOFTWARE TESTING – Minor 01
Employee Hours
Test Case Employee ID Hourly Rate Output
Type Worked
WECT1 00000 C 20.0 19 Output results
WECT2 99999 P 45.0 20 Output results
WECT3 1234 F 50.0 60 Invalid input
WECT4 a4bc03 X 35.1 61 Invalid input
Table 5: Weak Equivalence Class
10449314 Page |9
CSI3105 SOFTWARE TESTING – Minor 01
10449314 P a g e | 10
CSI3105 SOFTWARE TESTING – Minor 01
10449314 P a g e | 11
CSI3105 SOFTWARE TESTING – Minor 01
10449314 P a g e | 12
CSI3105 SOFTWARE TESTING – Minor 01
Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Invalid Employee ID
A-06 EP a4bc0 Display error message:
[When a string is entered]
“Error: Employee ID must contain
only numbers!”
Table 7: Test case for Employee ID
10449314 P a g e | 13
CSI3105 SOFTWARE TESTING – Minor 01
Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
10449314 P a g e | 14
CSI3105 SOFTWARE TESTING – Minor 01
Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Method returns false.
Invalid value of hourly rate.
[Lowest boundary value near
C-01 BVP 19.9 Displays error message:
boundary value (20) is
“Error: Employee Type C do not
entered]
match the hourly rate“
Given that Employee type is C
Valid range of hourly rate is Method returns true and
Displays a dialog box
C-02 $20.00 and $35.00. BVP 20.0
“Enter your worked hours for this
[First boundary value of hourly
week:”
rate is 20]
Valid value of hourly rate. Method returns true and
[Highest boundary value near Displays a dialog box
C-03 BVP 20.1
boundary value (20) is “Enter your worked hours for this
entered] week:”
10449314 P a g e | 15
CSI3105 SOFTWARE TESTING – Minor 01
Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Method returns false.
Invalid value of hourly rate.
[Lowest boundary value near
C-08 BVP 29.9 Displays error message:
boundary value (30) is
“Error: Employee Type P do not
entered]
match the hourly rate”
Given that Employee type is P
Valid range of hourly rate is Method returns true and
Displays a dialog box
C-09 $30.00 and $45.00. BVP 30.0
“Enter your worked hours for this
[First boundary value of hourly
week:”
rate is 30]
Valid value of hourly rate. Method returns true and
[Highest boundary value near Displays a dialog box
C-10 BVP 30.1
boundary value (30) is “Enter your worked hours for this
entered] week:”
10449314 P a g e | 16
CSI3105 SOFTWARE TESTING – Minor 01
Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVP)
Method returns false.
Invalid value of hourly rate.
[Lowest boundary value near
C-15 BVP 34.9 Displays error message:
boundary value (35) is
“Error: Employee Type F do not
entered]
match the hourly rate”
Given that Employee type is F
Valid range of hourly rate is Method returns true and
Displays a dialog box
C-16 $35.00 and $50.00. BVP 35.0
“Enter your worked hours for this
[First boundary value of hourly
week:”
rate is 35]
Valid value of hourly rate. Method returns true and
[Highest boundary value near Displays a dialog box
C-17 BVP 35.1
boundary value (35) is “Enter your worked hours for this
entered] week:”
10449314 P a g e | 17
CSI3105 SOFTWARE TESTING – Minor 01
Technique
Test Test Objective/Evaluation Expected
Employed Expected Outcome
ID Criteria Input
(EP, BVA)
Method returns false.
Invalid value of hours worked.
[Lowest boundary value near
D-01 BVA 19 Displays error message:
boundary value (20) is
“Error: Enter a valid number for
entered]
Hours Worked!”
Valid range of hours worked is Method returns true.
20 and 60 hours.
D-02 BVA 20 At the end of the program -
[First boundary value of hours
Displays Output of Hours Worked:
worked is 20] “Hours Worked: 20 hours”
Method returns true.
Valid value of hours worked.
D-03 [Highest boundary value near BVA 21 At the end of the program -
boundary value is entered] Displays Output of Hours Worked:
“Hours Worked: 21 hours”
Method returns true.
Valid value of hours worked.
D-04 [Any value within the range is EP 46 At the end of the program -
entered] Displays Output of Hours Worked:
“Hours Worked: 46 hours”
Valid value of hours worked. Method returns true.
[Lowest boundary value near
D-05 BVA 59 At the end of the program -
boundary value (60) is
Displays Output of Hours Worked:
entered] “Hours Worked: 59 hours”
Method returns true.
Valid value of hours worked.
D-06 [Second boundary value of BVA 60 At the end of the program -
hours worked is 60] Displays Output of Hours Worked:
“Hours Worked: 60 hours”
Method returns false.
Invalid value of hours worked.
[Highest boundary value near
D-07 BVA 61 Displays error message:
boundary value (60) is
“Error: Enter a valid number for
entered]
Hours Worked!”
Method returns false.
Displays error message:
D-08 Invalid value of hours worked. E 25.6
“Error: Hours Worked must be a
real number!”
Table 12: Test case for hours worked
10449314 P a g e | 18
CSI3105 SOFTWARE TESTING – Minor 01
2.4. JUnit
JUnit is an open source testing framework created for the purpose of writing and running
tests in the Java programming language and one of the features of JUnit is that it provides
assertions for testing expected results and also provides annotations to identify test methods.
As for the Payroll Program, the following are the tests for the methods of Employee ID,
Employee Type, Hourly Rate (Types C,P,F), Hours Worked:
/**
* Test values in Employee Id
*/
@Test
public void testEmpIDPass() {
@Test
public void testEmpIDFail() {
/**
* Test Employee Id's data type
*/
@Test
public void testEmpIDInvalid() {
10449314 P a g e | 19
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Test Employee Types of C, P, F
*/
@Test
public void testEmpTypePass() {
assertEquals("error in EmpType()", "C", PayrollProgram.validateEmpType("C")); // B-01
assertEquals("error in EmpType()", "P", PayrollProgram.validateEmpType("P")); // B-02
assertEquals("error in EmpType()", "F", PayrollProgram.validateEmpType("F")); // B-03
}
@Test
public void testEmpTypeFail() {
assertNotEquals("Invalid Emp Type", "X", PayrollProgram.validateEmpType("X")); // B-04
}
}
/**
* Test hrly rate for Employee Type C between $20.0 - $35.0
*/
@Test
public void testPassTypeC() {
@Test
public void testFailTypeC() {
10449314 P a g e | 20
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Test hourly rate for Employee Type P between $30.0 - $45.0
*/
@Test
public void testPassTypeP() {
@Test
public void testFailTypeP() {
/**
* Test hourly rate for Employee Type F between $35.0 - $50.0
*/
@Test
public void testPassTypeF() {
@Test
public void testFailTypeF() {
/**
* Test hourly rate data type
*/
@Test
public void testHrlyRateInvalid() {
10449314 P a g e | 21
CSI3105 SOFTWARE TESTING – Minor 01
/**
* Test values for hours worked between 20 - 60 hours
*/
@Test
public void testHrsWrkPass() {
@Test
public void testHrsWrkFail() {
/**
* Test hours worked data type
*/
@Test
public void testHrsWrkInvalid() {
10449314 P a g e | 22
CSI3105 SOFTWARE TESTING – Minor 01
Appendix
1. Screenshots
1.1. JUnit
10449314 P a g e | 23
CSI3105 SOFTWARE TESTING – Minor 01
10449314 P a g e | 24
CSI3105 SOFTWARE TESTING – Minor 01
1.2. Employee ID
10449314 P a g e | 25
CSI3105 SOFTWARE TESTING – Minor 01
10449314 P a g e | 26
CSI3105 SOFTWARE TESTING – Minor 01
10449314 P a g e | 27