Solved by Expert Tutors
Download the jUnit class MathematicsTest.java from desire to learn Create a class Mathematics.java that passes all the tests.
Solved by Expert Tutors
Question

Download the jUnit class MathematicsTest.java from desire to learn

Create a class Mathematics.java that passes all the tests.


Demonstrate your completed project to your instructor After that, your paper will be signed and you can go home



import static org.junit.Assert.*;

import java.util.HashSet;

import org.junit.Test;

public class MathematicsTest {

private Mathematics math;

public MathematicsTest()

{

math = new Mathematics();

}

@Test

public void testPIValue() {

assertEquals(3.14159, Mathematics.PI, 0.1);

}

@Test

public void testFeetToKMRatioValue() {

assertEquals(0.0003048,

Mathematics.ONE_FOOT_TO_KILOMETER_RATIO, 0.1);

}

@Test

public void testGetCircleArea1() {

double area = math.getCircleArea(1.0);

assertEquals(3.14159, area, 0.1);

}

@Test

public void testGetCircleArea2() {

double area = math.getCircleArea(15.0);

assertEquals(706.85775, area, 0.1);

}

@Test

public void testGetSquareArea1() {

double area = math.getSquareArea(2.0);

assertEquals(4.0, area, 0.1);

6


}

@Test

public void testGetSquareArea2() {

double area = math.getSquareArea(32.0);

assertEquals(1024.0, area, 0.1);

}

@Test

public void testAdd1() {

double sum = math.add(6.0, 7.0);

assertEquals(13.0, sum, 0.1);

}

@Test

public void testAdd2() {

double sum = math.add(-6.0, 6.0);

assertEquals(0.0, sum, 0.1);

}

@Test

public void testTimes1() {

double product = math.times(1.0, 5.0);

assertEquals(5.0, product, 0.1);

}

@Test

public void testTimes2() {

double product = math.times(20.0, 20.0);

assertEquals(400.0, product, 0.1);

}

@Test

public void testSubtract1() {

double difference = math.subtract(0.0, 20.0);

assertEquals(-20.0, difference, 0.1);

}


@Test

public void testSubtract2() {

double difference = math.subtract(20.0, 20.0);

assertEquals(0.0, difference, 0.1);

}

@Test

public void testDivide1() {

int division = math.divide(20, 10);

assertEquals(2, division);

}

@Test

public void testDivide2() {

int division = math.divide(20, 0);

assertEquals(0, division);

}

@Test

public void testAbsolute1() {

int abs = math.absoluteValue(1);

assertEquals(1, abs);

}

@Test

public void testAbsolute2() {

int abs = math.absoluteValue(-5000);

assertEquals(5000, abs);

}

@Test

public void testRandomNumberBetweenTenAndTwentyButNotFifteen()

{

HashSet<Integer> values = new HashSet<Integer>();

for(int i=0; i < 10000; i++)


{

int number =

math.getRandomNumberBetweenTenAndTwentyButNotFifteen();

boolean lessThanTen = number < 10;

boolean greaterThanTwenty = number > 20;

boolean notFifteen = number == 15;

assertFalse(lessThanTen);

assertFalse(greaterThanTwenty);

assertFalse(notFifteen);

values.add(number);

}

assertEquals(10, values.size());

}

@Test

public void testFootToKM1() {

double km = math.convertFeetToKilometers(1.0);

assertEquals(0.0003048, km, 0.1);

}

@Test

public void testFootToKM2() {

double km = math.convertFeetToKilometers(892.0);

assertEquals(0.272186, km, 0.1);

}

@Test

public void testDoubleTheNumber1(){

Integer number = Integer.valueOf(5);

Integer answer = math.doubleTheNumber(number);

assertEquals((Integer)10, answer);

}


@Test

public void testDoubleTheNumber2()

{

integer number = Integer.valueOf(16);

Integer answer = math.doubleTheNumber(number);

assertEquals((Integer)32, answer);

}


@Test

public void testDoubleTheNumber3(){

Integer number = null;

try{

Integer answer = math.doubleTheNumber(number);

fail();

}catch(NullPointerException e){

assertEquals("You can't double null!!", e.getMessage());

}catch(Exception e){

fail();

}

}

}

Step-by-step answer

cing elit. Nam lacinacinia pulvi

ec facilisis. Pe

llent

pulvinar tortor necconlisciicongue veiicituconlfficlrisuslitur ldictuma moleuscconlfficlrisuslitur lsque dapibus efficitur laoreet.ac, dictu, ultsumiongueiitur laoreexipsumfficituriicitor nellentesque dapibus efficisumiongueilestie conseqxipsumec faciicitor neipsum dolor sit amsumiongueiorxipsumsuipsumfiicitor nem ipsum dolosumiongueice dxipsumsuipsumfiicitor nefacilisis.sumiongueisus antxipsumsuipsumfiicitor neac, dictum vsumamet, coa. Fuscing elit. Nam laciniaiicitucing0ur laor nel0ipisor nellentesque dsumamet, cotesque dapiscing elitiicituac,0ur laor neur laoror nerem ipsumsumi,idictum vitae odio. Donec aliquet. Lorem ipsumicionec aliacon0or necm ipsnllm ipsum,rem ipsuDonec asuo. Donec aliquet.lea molestor neconsectetur asumiongueidictum vitae odio. Donexipsumiionec alor nerisus ante, dapibus a molestie consesumamet, coicitur laoreeipsum dolorionec alurisuametur lainialsurisus ante, dapibus afficitur laoreet. Nam ria molestor nelllestie conseq


ultrices ac magna.

risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.

Subscribe to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question