SlideShare a Scribd company logo
1 of 10
Download to read offline
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.pdfsudhirchourasia86
 
Test beautycleanness
Test beautycleannessTest beautycleanness
Test beautycleannessbergel
 
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.pdfarihantmobileselepun
 
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 qualityVadim Mikhnevych
 
CHAPTER-3a.ppt
CHAPTER-3a.pptCHAPTER-3a.ppt
CHAPTER-3a.pptTekle12
 
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.pdfShaiAlmog1
 
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 2Kirill 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 StreamsGeeksLab Odessa
 
[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancji[PL] O klasycznej, programistycznej elegancji
[PL] O klasycznej, programistycznej elegancjiJakub Marchwicki
 
javascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfjavascript-variablesanddatatypes-130218094831-phpapp01.pdf
javascript-variablesanddatatypes-130218094831-phpapp01.pdfAlexShon3
 
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 .pdfarihantmum
 
Weekly Reflections
Weekly ReflectionsWeekly Reflections
Weekly ReflectionsLearningTech
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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).pdfaamousnowov
 
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.pdfaamousnowov
 
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-.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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'.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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-.pdfaamousnowov
 
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.pdfaamousnowov
 
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-).pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 
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.pdfaamousnowov
 

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

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
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
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.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
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
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
 
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
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 

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.