SlideShare a Scribd company logo
This is a Java Code, you are only creating unit test for Validate and ConvertToBinary methods.
Please create at least 2 test for each method and check to see if they are successful. I have
inserted some example unit test as well.
CONVERT SERVICE CLASS:
public class ConvertService {
private Boolean isValid;
private long intValue;
private String hexValue;
private String binaryValue;
public ConvertService(String binaryValue) {
this.binaryValue = binaryValue;
Validate(binaryValue);
if (this.isValid) {
ConvertToInt(binaryValue);
ConvertToHex(binaryValue);
}
}
public ConvertService(long intValue) {
this.intValue = intValue;
Validate(intValue);
if (this.isValid) {
ConvertToBinary(intValue);
ConvertToHex(this.binaryValue);
}
}
public boolean IsValid() {
return isValid;
}
public String BinaryValue() {
return binaryValue;
}
public long IntegerValue() {
return intValue;
}
public String HexadecimalValue() {
return hexValue;
}
/*
* Used when the ConvertService(String binaryValue) constructor is used.
* Validate that the input value is not blank, and less than 32 characters long.
* Validate that the input value is only 1s and 0s.
*/
private void Validate (String value) {
Boolean isValid = true;
if (!is1sAnd0sOnly(value)) {
isValid = false;
}
if (!isProperLength(value)) {
isValid = false;
}
this.isValid = isValid;
}
/*
* Used when the ConvertService(long intvalue) constructor is used.
* Validate that the input value positive and less than 4294967295L
* Note: 4294967295L = FFFFFFFF
*/
//we have to test this
private void Validate (long value) {
Boolean isValid = true;
if (value < 0 || value > 4294967295L)
isValid = false;
this.isValid = isValid;
}
private boolean is1sAnd0sOnly (String str) {
if (str.matches("^[01]+$")) {
return true;
}
return false;
}
private boolean isNullEmptyBlank(String str){
if (str == null || str.equals("") || str.trim().equals(""))
return true;
return false;
}
private boolean isProperLength (String str) {
if (isNullEmptyBlank(str) ||
str.length() <= 32 ) {
return true;
}
return false;
}
private void ConvertToInt(String value) {
long iValue = 0L;
for (int i=0; i<value.length(); i++) {
long multiplier = (long)Math.pow(2, value.length() - 1 - i);
if (value.charAt(i) == '1') {
iValue += multiplier;
}
}
this.intValue = iValue;
}
private void ConvertToHex(String value) {
String hexValue = "";
//Fill the left size of the value with 0's so the length is a multiple of four.
int leftover = value.length() % 4;
if (leftover != 0) {
for (int i=0; i< (4-leftover); i++) {
value = "0" + value;
}
}
for (int i=0; i < value.length() / 4; i++) {
//a nibble is 4 bits
String nibble = value.substring(i*4, (i*4)+4);
if (nibble.equals("0000")) {
hexValue = hexValue + "0";
} else if (nibble.equals("0001")) {
hexValue = hexValue + "1";
} else if (nibble.equals("0010")) {
hexValue = hexValue + "2";
} else if (nibble.equals("0011")) {
hexValue = hexValue + "3";
} else if (nibble.equals("0100")) {
hexValue = hexValue + "4";
} else if (nibble.equals("0101")) {
hexValue = hexValue + "5";
} else if (nibble.equals("0110")) {
hexValue = hexValue + "6";
} else if (nibble.equals("0111")) {
hexValue = hexValue + "7";
} else if (nibble.equals("1000")) {
hexValue = hexValue + "8";
} else if (nibble.equals("1001")) {
hexValue = hexValue + "9";
} else if (nibble.equals("1010")) {
hexValue = hexValue + "A";
} else if (nibble.equals("1011")) {
hexValue = hexValue + "B";
} else if (nibble.equals("1100")) {
hexValue = hexValue + "C";
} else if (nibble.equals("1101")) {
hexValue = hexValue + "D";
} else if (nibble.equals("1110")) {
hexValue = hexValue + "E";
} else if (nibble.equals("1111")) {
hexValue = hexValue + "F";
}
}
this.hexValue = hexValue;
}
// we have to include this
void ConvertToBinary(long value) {
String bValue = "";
for (int i=32; i>0; i--) {
long multiplier = (long)Math.pow(2, i);
if (value > multiplier) {
bValue = bValue + "1";
value = value - multiplier;
} else {
bValue = bValue + "0";
}
}
this.binaryValue = bValue;
}
}
CONVERT TO SERVICE TEST Class:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class ConvertServiceTest {
@Test
public void ConvertService_SuccessTest() {
String val = "1010";
ConvertService bs = new ConvertService(val);
assertEquals(true, bs.IsValid());
assertEquals(val, bs.BinaryValue());
assertEquals(10, bs.IntegerValue());
assertEquals("A", bs.HexadecimalValue());
}
@Test
public void ConvertService_Success_Short_0() {
String val = "0";
ConvertService bs = new ConvertService(val);
assertEquals(true, bs.IsValid());
assertEquals(val, bs.BinaryValue());
assertEquals(0, bs.IntegerValue());
assertEquals("0", bs.HexadecimalValue());
}
@Test
public void ConvertService_Success_32Bits_AllHexValues1() {
//Test all the values from 0 to 7
String val = "00000001001000110100010101100111";
ConvertService bs = new ConvertService(val);
assertEquals(val, bs.BinaryValue());
assertEquals(19088743, bs.IntegerValue());
assertEquals("01234567", bs.HexadecimalValue());
}
@Test
public void ConvertService_Success_32Bits_AllHexValues2() {
//Test all the values from 8 to 15
String val = "10001001101010111100110111101111";
ConvertService bs = new ConvertService(val);
assertEquals(val, bs.BinaryValue());
assertEquals(2309737967L, bs.IntegerValue());
assertEquals("89ABCDEF", bs.HexadecimalValue());
}
}
App Class:
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
ConvertService binaryService = new ConvertService("10000000");
System.out.println(binaryService.HexadecimalValue());
ConvertService binaryTest = new ConvertService("10000000");
System.out.println(binaryTest.IntegerValue());
}
}
Purpose: Use your unit testing and debugging skills to figure out if this code is working. Steps:
binary string and the binary string is used to convert the hexadecimal value. 1. Look at the new
constructor and follow the logic. Does it make sense? Verify the new Validate method is correct.
Verify the order of the logic is correct. First it will call ConvertToBinary, then it will call
ConvertToHex, 1s this correct? 3. Create some unit tests for this new constructor to evaluate if
the code is working or not. for validate long and convert to binary ConvertToBinary method.
Lab6-Florin-Ryan). If you work with someone else to complete this Lab, provide a note when
submitted. Only 1 person needs to submit. How will this be graded? lines in validate(long) and
ConvertToBinary(long). You do not need to provide test cases that cover the other methods.

More Related Content

Similar to This is a Java Code- you are only creating unit test for Validate and.pdf

  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
sudhirchourasia86
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
bergel
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
arihantmobileselepun
 
Benefits of Kotlin
Benefits of KotlinBenefits of Kotlin
Benefits of Kotlin
Benjamin Waye
 
Kotlin decompiled
Kotlin decompiledKotlin decompiled
Kotlin decompiled
Ruslan Klymenko
 
Mutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests qualityMutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests quality
Vadim Mikhnevych
 
CHAPTER-3a.ppt
CHAPTER-3a.pptCHAPTER-3a.ppt
CHAPTER-3a.ppt
Tekle12
 
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Tao Xie
 
Creating an Uber Clone - Part XIII.pdf
Creating an Uber Clone - Part XIII.pdfCreating an Uber Clone - Part XIII.pdf
Creating an Uber Clone - Part XIII.pdf
ShaiAlmog1
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kirill Rozov
 
Java/Scala Lab: Slava Schmidt - Introduction to Reactive Streams
Java/Scala Lab: Slava Schmidt - Introduction to Reactive StreamsJava/Scala Lab: Slava Schmidt - Introduction to Reactive Streams
Java/Scala Lab: Slava Schmidt - Introduction to Reactive Streams
GeeksLab Odessa
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji
Jakub Marchwicki
 
Json.parse() in JavaScript
Json.parse() in JavaScriptJson.parse() in JavaScript
Json.parse() in JavaScript
Ideas2IT Technologies
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
AlexShon3
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
arihantmum
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
andyrobinson8
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
Saeid Zebardast
 
Weekly Reflections
Weekly ReflectionsWeekly Reflections
Weekly Reflections
LearningTech
 
DFiant HDL
DFiant HDLDFiant HDL
DFiant HDL
OronPort1
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Codemotion
 

Similar to This is a Java Code- you are only creating unit test for Validate and.pdf (20)

  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleanness
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
Benefits of Kotlin
Benefits of KotlinBenefits of Kotlin
Benefits of Kotlin
 
Kotlin decompiled
Kotlin decompiledKotlin decompiled
Kotlin decompiled
 
Mutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests qualityMutation testing - the way to improve unit tests quality
Mutation testing - the way to improve unit tests quality
 
CHAPTER-3a.ppt
CHAPTER-3a.pptCHAPTER-3a.ppt
CHAPTER-3a.ppt
 
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)Transferring Software Testing Tools to Practice (AST 2017 Keynote)
Transferring Software Testing Tools to Practice (AST 2017 Keynote)
 
Creating an Uber Clone - Part XIII.pdf
Creating an Uber Clone - Part XIII.pdfCreating an Uber Clone - Part XIII.pdf
Creating an Uber Clone - Part XIII.pdf
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Java/Scala Lab: Slava Schmidt - Introduction to Reactive Streams
Java/Scala Lab: Slava Schmidt - Introduction to Reactive StreamsJava/Scala Lab: Slava Schmidt - Introduction to Reactive Streams
Java/Scala Lab: Slava Schmidt - Introduction to Reactive Streams
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji
 
Json.parse() in JavaScript
Json.parse() in JavaScriptJson.parse() in JavaScript
Json.parse() in JavaScript
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Weekly Reflections
Weekly ReflectionsWeekly Reflections
Weekly Reflections
 
DFiant HDL
DFiant HDLDFiant HDL
DFiant HDL
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 

More from aamousnowov

Theresa has many iCU potsents in her care- Some of the potients are on.pdf
Theresa has many iCU potsents in her care- Some of the potients are on.pdfTheresa has many iCU potsents in her care- Some of the potients are on.pdf
Theresa has many iCU potsents in her care- Some of the potients are on.pdf
aamousnowov
 
Theresa has many ICU patients in her care- Some of the patients are on.pdf
Theresa has many ICU patients in her care- Some of the patients are on.pdfTheresa has many ICU patients in her care- Some of the patients are on.pdf
Theresa has many ICU patients in her care- Some of the patients are on.pdf
aamousnowov
 
There is duality between monitors and message passing- What is that du (1).pdf
There is duality between monitors and message passing- What is that du (1).pdfThere is duality between monitors and message passing- What is that du (1).pdf
There is duality between monitors and message passing- What is that du (1).pdf
aamousnowov
 
There are several types of interests that may be at stake in a negotia.pdf
There are several types of interests that may be at stake in a negotia.pdfThere are several types of interests that may be at stake in a negotia.pdf
There are several types of interests that may be at stake in a negotia.pdf
aamousnowov
 
There is an unequal distribution of news coverage regarding disasters-.pdf
There is an unequal distribution of news coverage regarding disasters-.pdfThere is an unequal distribution of news coverage regarding disasters-.pdf
There is an unequal distribution of news coverage regarding disasters-.pdf
aamousnowov
 
There is an archaeological study area located in southwestern NewMexic.pdf
There is an archaeological study area located in southwestern NewMexic.pdfThere is an archaeological study area located in southwestern NewMexic.pdf
There is an archaeological study area located in southwestern NewMexic.pdf
aamousnowov
 
There is a disease called by two copies of a recessive allele- xx- On.pdf
There is a disease called by two copies of a recessive allele- xx- On.pdfThere is a disease called by two copies of a recessive allele- xx- On.pdf
There is a disease called by two copies of a recessive allele- xx- On.pdf
aamousnowov
 
There are two ways that the tilt of the Earth's axis causes the summer.pdf
There are two ways that the tilt of the Earth's axis causes the summer.pdfThere are two ways that the tilt of the Earth's axis causes the summer.pdf
There are two ways that the tilt of the Earth's axis causes the summer.pdf
aamousnowov
 
There doesn't appear to be a statistical difference in the means (you'.pdf
There doesn't appear to be a statistical difference in the means (you'.pdfThere doesn't appear to be a statistical difference in the means (you'.pdf
There doesn't appear to be a statistical difference in the means (you'.pdf
aamousnowov
 
There have been many examples where the use of AI and Data Mining to m.pdf
There have been many examples where the use of AI and Data Mining to m.pdfThere have been many examples where the use of AI and Data Mining to m.pdf
There have been many examples where the use of AI and Data Mining to m.pdf
aamousnowov
 
There has been a debate over how climate change impact the incidence a.pdf
There has been a debate over how climate change impact the incidence a.pdfThere has been a debate over how climate change impact the incidence a.pdf
There has been a debate over how climate change impact the incidence a.pdf
aamousnowov
 
There are 60 students in a class- 10 are graduate students- We form a.pdf
There are 60 students in a class- 10 are graduate students- We form a.pdfThere are 60 students in a class- 10 are graduate students- We form a.pdf
There are 60 students in a class- 10 are graduate students- We form a.pdf
aamousnowov
 
Theme- Understanding relevance and centrality based information reteri.pdf
Theme- Understanding relevance and centrality based information reteri.pdfTheme- Understanding relevance and centrality based information reteri.pdf
Theme- Understanding relevance and centrality based information reteri.pdf
aamousnowov
 
There are 100 inhabitants on a remote island in the year 2000 - The po.pdf
There are 100 inhabitants on a remote island in the year 2000 - The po.pdfThere are 100 inhabitants on a remote island in the year 2000 - The po.pdf
There are 100 inhabitants on a remote island in the year 2000 - The po.pdf
aamousnowov
 
their state of happiness (Happy or Not Happy) and income (Low- Medium-.pdf
their state of happiness (Happy or Not Happy) and income (Low- Medium-.pdftheir state of happiness (Happy or Not Happy) and income (Low- Medium-.pdf
their state of happiness (Happy or Not Happy) and income (Low- Medium-.pdf
aamousnowov
 
There are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdf
There are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdfThere are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdf
There are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdf
aamousnowov
 
The z-test statistic is (Raund to two docimal plizces as naodod-).pdf
The z-test statistic is (Raund to two docimal plizces as naodod-).pdfThe z-test statistic is (Raund to two docimal plizces as naodod-).pdf
The z-test statistic is (Raund to two docimal plizces as naodod-).pdf
aamousnowov
 
There are 15 freshmen and 17 sophomore students in a classroom- We ran.pdf
There are 15 freshmen and 17 sophomore students in a classroom- We ran.pdfThere are 15 freshmen and 17 sophomore students in a classroom- We ran.pdf
There are 15 freshmen and 17 sophomore students in a classroom- We ran.pdf
aamousnowov
 
There are numerous sales apps that are very popular with sales people.pdf
There are numerous sales apps that are very popular with sales people.pdfThere are numerous sales apps that are very popular with sales people.pdf
There are numerous sales apps that are very popular with sales people.pdf
aamousnowov
 
There are several benefits to incorporating a business- Which of the f.pdf
There are several benefits to incorporating a business- Which of the f.pdfThere are several benefits to incorporating a business- Which of the f.pdf
There are several benefits to incorporating a business- Which of the f.pdf
aamousnowov
 

More from aamousnowov (20)

Theresa has many iCU potsents in her care- Some of the potients are on.pdf
Theresa has many iCU potsents in her care- Some of the potients are on.pdfTheresa has many iCU potsents in her care- Some of the potients are on.pdf
Theresa has many iCU potsents in her care- Some of the potients are on.pdf
 
Theresa has many ICU patients in her care- Some of the patients are on.pdf
Theresa has many ICU patients in her care- Some of the patients are on.pdfTheresa has many ICU patients in her care- Some of the patients are on.pdf
Theresa has many ICU patients in her care- Some of the patients are on.pdf
 
There is duality between monitors and message passing- What is that du (1).pdf
There is duality between monitors and message passing- What is that du (1).pdfThere is duality between monitors and message passing- What is that du (1).pdf
There is duality between monitors and message passing- What is that du (1).pdf
 
There are several types of interests that may be at stake in a negotia.pdf
There are several types of interests that may be at stake in a negotia.pdfThere are several types of interests that may be at stake in a negotia.pdf
There are several types of interests that may be at stake in a negotia.pdf
 
There is an unequal distribution of news coverage regarding disasters-.pdf
There is an unequal distribution of news coverage regarding disasters-.pdfThere is an unequal distribution of news coverage regarding disasters-.pdf
There is an unequal distribution of news coverage regarding disasters-.pdf
 
There is an archaeological study area located in southwestern NewMexic.pdf
There is an archaeological study area located in southwestern NewMexic.pdfThere is an archaeological study area located in southwestern NewMexic.pdf
There is an archaeological study area located in southwestern NewMexic.pdf
 
There is a disease called by two copies of a recessive allele- xx- On.pdf
There is a disease called by two copies of a recessive allele- xx- On.pdfThere is a disease called by two copies of a recessive allele- xx- On.pdf
There is a disease called by two copies of a recessive allele- xx- On.pdf
 
There are two ways that the tilt of the Earth's axis causes the summer.pdf
There are two ways that the tilt of the Earth's axis causes the summer.pdfThere are two ways that the tilt of the Earth's axis causes the summer.pdf
There are two ways that the tilt of the Earth's axis causes the summer.pdf
 
There doesn't appear to be a statistical difference in the means (you'.pdf
There doesn't appear to be a statistical difference in the means (you'.pdfThere doesn't appear to be a statistical difference in the means (you'.pdf
There doesn't appear to be a statistical difference in the means (you'.pdf
 
There have been many examples where the use of AI and Data Mining to m.pdf
There have been many examples where the use of AI and Data Mining to m.pdfThere have been many examples where the use of AI and Data Mining to m.pdf
There have been many examples where the use of AI and Data Mining to m.pdf
 
There has been a debate over how climate change impact the incidence a.pdf
There has been a debate over how climate change impact the incidence a.pdfThere has been a debate over how climate change impact the incidence a.pdf
There has been a debate over how climate change impact the incidence a.pdf
 
There are 60 students in a class- 10 are graduate students- We form a.pdf
There are 60 students in a class- 10 are graduate students- We form a.pdfThere are 60 students in a class- 10 are graduate students- We form a.pdf
There are 60 students in a class- 10 are graduate students- We form a.pdf
 
Theme- Understanding relevance and centrality based information reteri.pdf
Theme- Understanding relevance and centrality based information reteri.pdfTheme- Understanding relevance and centrality based information reteri.pdf
Theme- Understanding relevance and centrality based information reteri.pdf
 
There are 100 inhabitants on a remote island in the year 2000 - The po.pdf
There are 100 inhabitants on a remote island in the year 2000 - The po.pdfThere are 100 inhabitants on a remote island in the year 2000 - The po.pdf
There are 100 inhabitants on a remote island in the year 2000 - The po.pdf
 
their state of happiness (Happy or Not Happy) and income (Low- Medium-.pdf
their state of happiness (Happy or Not Happy) and income (Low- Medium-.pdftheir state of happiness (Happy or Not Happy) and income (Low- Medium-.pdf
their state of happiness (Happy or Not Happy) and income (Low- Medium-.pdf
 
There are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdf
There are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdfThere are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdf
There are 24 evenly distributed nodes on an 8 port 100 BaseT HUB- What.pdf
 
The z-test statistic is (Raund to two docimal plizces as naodod-).pdf
The z-test statistic is (Raund to two docimal plizces as naodod-).pdfThe z-test statistic is (Raund to two docimal plizces as naodod-).pdf
The z-test statistic is (Raund to two docimal plizces as naodod-).pdf
 
There are 15 freshmen and 17 sophomore students in a classroom- We ran.pdf
There are 15 freshmen and 17 sophomore students in a classroom- We ran.pdfThere are 15 freshmen and 17 sophomore students in a classroom- We ran.pdf
There are 15 freshmen and 17 sophomore students in a classroom- We ran.pdf
 
There are numerous sales apps that are very popular with sales people.pdf
There are numerous sales apps that are very popular with sales people.pdfThere are numerous sales apps that are very popular with sales people.pdf
There are numerous sales apps that are very popular with sales people.pdf
 
There are several benefits to incorporating a business- Which of the f.pdf
There are several benefits to incorporating a business- Which of the f.pdfThere are several benefits to incorporating a business- Which of the f.pdf
There are several benefits to incorporating a business- Which of the f.pdf
 

Recently uploaded

Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
paigestewart1632
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 

Recently uploaded (20)

Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Cognitive Development Adolescence Psychology
Cognitive Development Adolescence PsychologyCognitive Development Adolescence Psychology
Cognitive Development Adolescence Psychology
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 

This is a Java Code- you are only creating unit test for Validate and.pdf

  • 1. This is a Java Code, you are only creating unit test for Validate and ConvertToBinary methods. Please create at least 2 test for each method and check to see if they are successful. I have inserted some example unit test as well. CONVERT SERVICE CLASS: public class ConvertService { private Boolean isValid; private long intValue; private String hexValue; private String binaryValue; public ConvertService(String binaryValue) { this.binaryValue = binaryValue; Validate(binaryValue); if (this.isValid) { ConvertToInt(binaryValue); ConvertToHex(binaryValue); } } public ConvertService(long intValue) { this.intValue = intValue; Validate(intValue); if (this.isValid) { ConvertToBinary(intValue); ConvertToHex(this.binaryValue); }
  • 2. } public boolean IsValid() { return isValid; } public String BinaryValue() { return binaryValue; } public long IntegerValue() { return intValue; } public String HexadecimalValue() { return hexValue; } /* * Used when the ConvertService(String binaryValue) constructor is used. * Validate that the input value is not blank, and less than 32 characters long. * Validate that the input value is only 1s and 0s. */ private void Validate (String value) { Boolean isValid = true; if (!is1sAnd0sOnly(value)) { isValid = false;
  • 3. } if (!isProperLength(value)) { isValid = false; } this.isValid = isValid; } /* * Used when the ConvertService(long intvalue) constructor is used. * Validate that the input value positive and less than 4294967295L * Note: 4294967295L = FFFFFFFF */ //we have to test this private void Validate (long value) { Boolean isValid = true; if (value < 0 || value > 4294967295L) isValid = false; this.isValid = isValid; } private boolean is1sAnd0sOnly (String str) { if (str.matches("^[01]+$")) { return true; } return false;
  • 4. } private boolean isNullEmptyBlank(String str){ if (str == null || str.equals("") || str.trim().equals("")) return true; return false; } private boolean isProperLength (String str) { if (isNullEmptyBlank(str) || str.length() <= 32 ) { return true; } return false; } private void ConvertToInt(String value) { long iValue = 0L; for (int i=0; i<value.length(); i++) { long multiplier = (long)Math.pow(2, value.length() - 1 - i); if (value.charAt(i) == '1') { iValue += multiplier; } } this.intValue = iValue; }
  • 5. private void ConvertToHex(String value) { String hexValue = ""; //Fill the left size of the value with 0's so the length is a multiple of four. int leftover = value.length() % 4; if (leftover != 0) { for (int i=0; i< (4-leftover); i++) { value = "0" + value; } } for (int i=0; i < value.length() / 4; i++) { //a nibble is 4 bits String nibble = value.substring(i*4, (i*4)+4); if (nibble.equals("0000")) { hexValue = hexValue + "0"; } else if (nibble.equals("0001")) { hexValue = hexValue + "1"; } else if (nibble.equals("0010")) { hexValue = hexValue + "2"; } else if (nibble.equals("0011")) { hexValue = hexValue + "3"; } else if (nibble.equals("0100")) { hexValue = hexValue + "4"; } else if (nibble.equals("0101")) {
  • 6. hexValue = hexValue + "5"; } else if (nibble.equals("0110")) { hexValue = hexValue + "6"; } else if (nibble.equals("0111")) { hexValue = hexValue + "7"; } else if (nibble.equals("1000")) { hexValue = hexValue + "8"; } else if (nibble.equals("1001")) { hexValue = hexValue + "9"; } else if (nibble.equals("1010")) { hexValue = hexValue + "A"; } else if (nibble.equals("1011")) { hexValue = hexValue + "B"; } else if (nibble.equals("1100")) { hexValue = hexValue + "C"; } else if (nibble.equals("1101")) { hexValue = hexValue + "D"; } else if (nibble.equals("1110")) { hexValue = hexValue + "E"; } else if (nibble.equals("1111")) { hexValue = hexValue + "F"; } }
  • 7. this.hexValue = hexValue; } // we have to include this void ConvertToBinary(long value) { String bValue = ""; for (int i=32; i>0; i--) { long multiplier = (long)Math.pow(2, i); if (value > multiplier) { bValue = bValue + "1"; value = value - multiplier; } else { bValue = bValue + "0"; } } this.binaryValue = bValue; } } CONVERT TO SERVICE TEST Class: import static org.junit.Assert.assertEquals; import org.junit.Test; public class ConvertServiceTest { @Test public void ConvertService_SuccessTest() {
  • 8. String val = "1010"; ConvertService bs = new ConvertService(val); assertEquals(true, bs.IsValid()); assertEquals(val, bs.BinaryValue()); assertEquals(10, bs.IntegerValue()); assertEquals("A", bs.HexadecimalValue()); } @Test public void ConvertService_Success_Short_0() { String val = "0"; ConvertService bs = new ConvertService(val); assertEquals(true, bs.IsValid()); assertEquals(val, bs.BinaryValue()); assertEquals(0, bs.IntegerValue()); assertEquals("0", bs.HexadecimalValue()); } @Test public void ConvertService_Success_32Bits_AllHexValues1() { //Test all the values from 0 to 7 String val = "00000001001000110100010101100111"; ConvertService bs = new ConvertService(val); assertEquals(val, bs.BinaryValue()); assertEquals(19088743, bs.IntegerValue());
  • 9. assertEquals("01234567", bs.HexadecimalValue()); } @Test public void ConvertService_Success_32Bits_AllHexValues2() { //Test all the values from 8 to 15 String val = "10001001101010111100110111101111"; ConvertService bs = new ConvertService(val); assertEquals(val, bs.BinaryValue()); assertEquals(2309737967L, bs.IntegerValue()); assertEquals("89ABCDEF", bs.HexadecimalValue()); } } App Class: public class App { public static void main(String[] args) throws Exception { System.out.println("Hello, World!"); ConvertService binaryService = new ConvertService("10000000"); System.out.println(binaryService.HexadecimalValue()); ConvertService binaryTest = new ConvertService("10000000"); System.out.println(binaryTest.IntegerValue()); } } Purpose: Use your unit testing and debugging skills to figure out if this code is working. Steps: binary string and the binary string is used to convert the hexadecimal value. 1. Look at the new
  • 10. constructor and follow the logic. Does it make sense? Verify the new Validate method is correct. Verify the order of the logic is correct. First it will call ConvertToBinary, then it will call ConvertToHex, 1s this correct? 3. Create some unit tests for this new constructor to evaluate if the code is working or not. for validate long and convert to binary ConvertToBinary method. Lab6-Florin-Ryan). If you work with someone else to complete this Lab, provide a note when submitted. Only 1 person needs to submit. How will this be graded? lines in validate(long) and ConvertToBinary(long). You do not need to provide test cases that cover the other methods.