SlideShare a Scribd company logo
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.docx
andreecapon
 
java programming cheatsheet
java programming cheatsheetjava programming cheatsheet
java programming cheatsheet
BD AB
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
Quratulain Naqvi
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
Coding Assignment Help
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
Vincent Pradeilles
 
Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
SasidharaRaoMarrapu
 
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.docx
davinci54
 
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
optokunal1
 
Operators
OperatorsOperators
Operators
vvpadhu
 
SeneJug java_8_prez_122015
SeneJug java_8_prez_122015SeneJug java_8_prez_122015
SeneJug java_8_prez_122015
senejug
 
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
bradburgess22840
 
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.pdf
arihantmum
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
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
aroramobiles1
 
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
Ganesh 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.pdf
hanumanparsadhsr
 

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.pdf
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 
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
adityknits
 

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

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 

Recently uploaded (20)

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 

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