SlideShare a Scribd company logo
1 of 3
Download to read offline
UserInputHandler.java
package midterm2023;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class UserInputHandler {
public static List<String> readUserInput() {
List<String> userData = new ArrayList<>();
System.out.println("Please enter your data below: (send 'bye' to exit) ");
Scanner input = new Scanner(System.in);
while (true) {
String line = input.nextLine();
if ("bye".equalsIgnoreCase(line)) {
break;
}
userData.add(line);
}
return userData;
}
public static void main(String[] args) {
List<String> userData = readUserInput();
System.out.printf("User Input Data:n%s", String.join("n", userData));
}
}
UserInputHandlerUnitTest.java
package midterm2023;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
public class UserInputHandlerUnitTest {
//@Test
void testByMakeUpDataInSystemIn() {
String[] inputLines = new String[]{
"The first line.",
"The second line.",
"bye",
"The last line.",
"anything after 'bye' will be ignored"
};
String[] expectedLines = Arrays.copyOf(inputLines, inputLines.length - 2);
List<String> expected = Arrays.stream(expectedLines).collect(Collectors.toList());
InputStream stdin = System.in;
try {
System.setIn(new ByteArrayInputStream(String.join("n", inputLines).getBytes()));
List<String> actual = UserInputHandler.readUserInput();
assertThat(actual).isEqualTo(expected);
} finally {
System.setIn(stdin);
}
}
}
QuickSort.java
package coen352.ch07;
public class QuickSort {
public static <E extends Comparable<? super E>> void sort(E[] A) {
qsort(A, 0, A.length-1);}
static <E extends Comparable<? super E>>
void qsort(E[] A, int i, int j) { // Quicksort
int pivotindex = findpivot(A, i, j); // Pick a pivot
DSutil.swap(A, pivotindex, j); // Stick pivot at end
// k will be the first position in the right subarray
int k = partition(A, i-1, j, A[j]);
DSutil.swap(A, k, j); // Put pivot in place
if ((k-i) > 1) qsort(A, i, k-1); // Sort left partition
if ((j-k) > 1) qsort(A, k+1, j); // Sort right partition
}
static <E extends Comparable<? super E>>
int partition(E[] A, int l, int r, E pivot) {
do {// Move bounds inward until they meet
while (A[++l].compareTo(pivot)<0);
while ((r!=0) && (A[--r].compareTo(pivot)>0));
DSutil.swap(A, l, r); // Swap out-of-place values
} while (l < r); // Stop when they cross
DSutil.swap(A, l, r); // Reverse last, wasted swap
return l; // Return first position in right partition
}
static <E extends Comparable<? super E>>
int findpivot(E[] A, int i, int j)
{ return (i+j)/2; }
}
In this assignment, we aim to practise white box testing and coverage strategies to produce unit
test cases. Problem 1 (30 MARKS) The UserInputHandler program code is provided in the
attachment. It is a simple function that stores the user's input until a certain terminating token is
typed. The original code applies the token 'bye' to terminate. Now please revise the program to
make the options with token 'bye' or 'quit' or 'exit'. 1.1. Develop CFG of the revised program and
compute the CC value (5 MARKS). 1.2. Based on the CC value, derive the basic paths. (5
MARKS) 1.3. Analyze the program's code structure and estimate the number of test cases needed
for condition coverage and decision coverage respectively. (5MARKS) 1.4. Generate test cases
for 100% basic path coverage, condition coverage and

More Related Content

Similar to UserInputHandlerjava package midterm2023 import javautil.pdf

META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxandreecapon
 
java programming cheatsheet
java programming cheatsheetjava programming cheatsheet
java programming cheatsheetBD AB
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flowSasidharaRaoMarrapu
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanChinmay Chauhan
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docxdavinci54
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfoptokunal1
 
Operators
OperatorsOperators
Operatorsvvpadhu
 
SeneJug java_8_prez_122015
SeneJug java_8_prez_122015SeneJug java_8_prez_122015
SeneJug java_8_prez_122015senejug
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxbradburgess22840
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Sunil Kumar Gunasekaran
 
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfWrite the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfarihantmum
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Please help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfPlease help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfaroramobiles1
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesGanesh Samarthyam
 
- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdfhanumanparsadhsr
 

Similar to UserInputHandlerjava package midterm2023 import javautil.pdf (20)

META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docxMETA-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
META-INFMANIFEST.MFManifest-Version 1.0.classpath.docx
 
java programming cheatsheet
java programming cheatsheetjava programming cheatsheet
java programming cheatsheet
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Operators
OperatorsOperators
Operators
 
SeneJug java_8_prez_122015
SeneJug java_8_prez_122015SeneJug java_8_prez_122015
SeneJug java_8_prez_122015
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdfWrite the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
Write the code above and the ones below in netbeans IDE 8.13. (Eli.pdf
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Please help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfPlease help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdf
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf- the modification will be done in Main class- first, asks the use.pdf
- the modification will be done in Main class- first, asks the use.pdf
 

More from adityknits

Using best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdfUsing best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdfadityknits
 
Using Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdfUsing Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdfadityknits
 
User Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdfUser Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdfadityknits
 
Using a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdfUsing a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdfadityknits
 
used below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdfused below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdfadityknits
 
Use to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdfUse to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdfadityknits
 
Use this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdfUse this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdfadityknits
 
Use the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdfUse the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdfadityknits
 
Use the spreadsheet extract to answer the questions Requir.pdf
Use the spreadsheet extract to answer the questions   Requir.pdfUse the spreadsheet extract to answer the questions   Requir.pdf
Use the spreadsheet extract to answer the questions Requir.pdfadityknits
 
Use the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdfUse the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdfadityknits
 
Use the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdfUse the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdfadityknits
 
Use the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdfUse the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdfadityknits
 
Use the following code for the tasks public class Animal .pdf
Use the following code for the tasks  public class Animal .pdfUse the following code for the tasks  public class Animal .pdf
Use the following code for the tasks public class Animal .pdfadityknits
 
Use the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdfUse the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdfadityknits
 
Use the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdfUse the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdfadityknits
 
Use the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdfUse the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdfadityknits
 
Use the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdfUse the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdfadityknits
 
Use the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdfUse the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdfadityknits
 
Use the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdfUse the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdfadityknits
 
Use the following scenario to respond to items 10 and 11 T.pdf
Use the following scenario to respond to items 10 and 11  T.pdfUse the following scenario to respond to items 10 and 11  T.pdf
Use the following scenario to respond to items 10 and 11 T.pdfadityknits
 

More from adityknits (20)

Using best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdfUsing best responses to evaluate this matrix Find all the s.pdf
Using best responses to evaluate this matrix Find all the s.pdf
 
Using Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdfUsing Bankers algorithm answer the following questions i.pdf
Using Bankers algorithm answer the following questions i.pdf
 
User Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdfUser Requirements Event handlers are often called event list.pdf
User Requirements Event handlers are often called event list.pdf
 
Using a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdfUsing a company that you know or fictitious company briefly .pdf
Using a company that you know or fictitious company briefly .pdf
 
used below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdfused below format to complete Write your code in the incompl.pdf
used below format to complete Write your code in the incompl.pdf
 
Use to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdfUse to answer the following questions Match the letters wit.pdf
Use to answer the following questions Match the letters wit.pdf
 
Use this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdfUse this list of terms to complete the sentences that follow.pdf
Use this list of terms to complete the sentences that follow.pdf
 
Use the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdfUse the Web to find as many examples as you can of open sour.pdf
Use the Web to find as many examples as you can of open sour.pdf
 
Use the spreadsheet extract to answer the questions Requir.pdf
Use the spreadsheet extract to answer the questions   Requir.pdfUse the spreadsheet extract to answer the questions   Requir.pdf
Use the spreadsheet extract to answer the questions Requir.pdf
 
Use the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdfUse the scenario to come up with the metabolic pathways requ.pdf
Use the scenario to come up with the metabolic pathways requ.pdf
 
Use the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdfUse the RTL design process to create an alarm system that se.pdf
Use the RTL design process to create an alarm system that se.pdf
 
Use the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdfUse the micrograph of the Gram stain to draw conclusions and.pdf
Use the micrograph of the Gram stain to draw conclusions and.pdf
 
Use the following code for the tasks public class Animal .pdf
Use the following code for the tasks  public class Animal .pdfUse the following code for the tasks  public class Animal .pdf
Use the following code for the tasks public class Animal .pdf
 
Use the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdfUse the Internet to identify and compare three different mob.pdf
Use the Internet to identify and compare three different mob.pdf
 
Use the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdfUse the graph below to answer questions 1012 10 Highlight .pdf
Use the graph below to answer questions 1012 10 Highlight .pdf
 
Use the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdfUse the grey point star symbol to indicate the competitive.pdf
Use the grey point star symbol to indicate the competitive.pdf
 
Use the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdfUse the following information for the Exercises below The .pdf
Use the following information for the Exercises below The .pdf
 
Use the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdfUse the images from the wild type cell shown below to answer.pdf
Use the images from the wild type cell shown below to answer.pdf
 
Use the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdfUse the given information to find the indicated probability.pdf
Use the given information to find the indicated probability.pdf
 
Use the following scenario to respond to items 10 and 11 T.pdf
Use the following scenario to respond to items 10 and 11  T.pdfUse the following scenario to respond to items 10 and 11  T.pdf
Use the following scenario to respond to items 10 and 11 T.pdf
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

UserInputHandlerjava package midterm2023 import javautil.pdf

  • 1. UserInputHandler.java package midterm2023; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class UserInputHandler { public static List<String> readUserInput() { List<String> userData = new ArrayList<>(); System.out.println("Please enter your data below: (send 'bye' to exit) "); Scanner input = new Scanner(System.in); while (true) { String line = input.nextLine(); if ("bye".equalsIgnoreCase(line)) { break; } userData.add(line); } return userData; } public static void main(String[] args) { List<String> userData = readUserInput(); System.out.printf("User Input Data:n%s", String.join("n", userData)); } } UserInputHandlerUnitTest.java package midterm2023; import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; public class UserInputHandlerUnitTest { //@Test void testByMakeUpDataInSystemIn() { String[] inputLines = new String[]{ "The first line.", "The second line.", "bye", "The last line.", "anything after 'bye' will be ignored"
  • 2. }; String[] expectedLines = Arrays.copyOf(inputLines, inputLines.length - 2); List<String> expected = Arrays.stream(expectedLines).collect(Collectors.toList()); InputStream stdin = System.in; try { System.setIn(new ByteArrayInputStream(String.join("n", inputLines).getBytes())); List<String> actual = UserInputHandler.readUserInput(); assertThat(actual).isEqualTo(expected); } finally { System.setIn(stdin); } } } QuickSort.java package coen352.ch07; public class QuickSort { public static <E extends Comparable<? super E>> void sort(E[] A) { qsort(A, 0, A.length-1);} static <E extends Comparable<? super E>> void qsort(E[] A, int i, int j) { // Quicksort int pivotindex = findpivot(A, i, j); // Pick a pivot DSutil.swap(A, pivotindex, j); // Stick pivot at end // k will be the first position in the right subarray int k = partition(A, i-1, j, A[j]); DSutil.swap(A, k, j); // Put pivot in place if ((k-i) > 1) qsort(A, i, k-1); // Sort left partition if ((j-k) > 1) qsort(A, k+1, j); // Sort right partition } static <E extends Comparable<? super E>> int partition(E[] A, int l, int r, E pivot) { do {// Move bounds inward until they meet while (A[++l].compareTo(pivot)<0); while ((r!=0) && (A[--r].compareTo(pivot)>0));
  • 3. DSutil.swap(A, l, r); // Swap out-of-place values } while (l < r); // Stop when they cross DSutil.swap(A, l, r); // Reverse last, wasted swap return l; // Return first position in right partition } static <E extends Comparable<? super E>> int findpivot(E[] A, int i, int j) { return (i+j)/2; } } In this assignment, we aim to practise white box testing and coverage strategies to produce unit test cases. Problem 1 (30 MARKS) The UserInputHandler program code is provided in the attachment. It is a simple function that stores the user's input until a certain terminating token is typed. The original code applies the token 'bye' to terminate. Now please revise the program to make the options with token 'bye' or 'quit' or 'exit'. 1.1. Develop CFG of the revised program and compute the CC value (5 MARKS). 1.2. Based on the CC value, derive the basic paths. (5 MARKS) 1.3. Analyze the program's code structure and estimate the number of test cases needed for condition coverage and decision coverage respectively. (5MARKS) 1.4. Generate test cases for 100% basic path coverage, condition coverage and