Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download the jUnit class MathematicsTest.java from desire to learn Create a class Mathematics.java that passes all the tests import static org. junit.Assert.*; import java.util.HashSet; import

Download the jUnit class MathematicsTest.java from desire to learn

Create a class Mathematics.java that passes all the tests

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)

}

@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 values = new HashSet();

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

6

COMP1451

[

LAB4A

]

{

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(){

6

COMP1451

[

LAB4A

]

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 Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

9. How can expected value be used to evaluate risky investments?

Answered: 1 week ago