Question: import static org.junit.Assert. * ; import org.junit.Before; import org.junit.Test; / / - - - - - - - - - - - - - -

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
//-------------------------------------------------------------------------
/**
* Test class for Calculator.
*
* @author Stephen Edwards
* @version 2006.06.14
*/
public class CalculatorTest {
//~ Setup .................................................................
//~ Instance/static variables .............................................
private Calculator calc;
//----------------------------------------------------------
/**
* Creates a new Calculator object with zero in the accumulator.
*/
@Before
public void setUp()
{
calc = new Calculator();
}
//~ Public Methods ........................................................
//----------------------------------------------------------
/**
* Check that a new calculator starts off with a zero value.
*/
@Test
public void initial()
{
assertEquals(0, calc.getValue());
}
//----------------------------------------------------------
/**
* Check setValue/getValue.
*/
@Test
public void setValue()
{
calc.setValue(37);
assertEquals(37, calc.getValue());
calc.setValue(-42);
assertEquals(-42, calc.getValue());
}
//----------------------------------------------------------
/**
* Check that clear returns the accumulator to zero.
*/
@Test
public void clear()
{
calc.setValue(49);
calc.clear();
assertEquals(0, calc.getValue());
}
//----------------------------------------------------------
/**
* Check that add works on zero and non-zero accumulators.
*/
@Test
public void addition()
{
// Add your own test actions here
calc.setValue(5);
calc.add(5);
assertEquals(10, calc.getValue());
calc.add(-1);
assertEquals(9, calc.getValue());
}
//----------------------------------------------------------
/**
* Check that subtract works on zero and non-zero accumulators.
*/
@Test
public void subtraction()
{
// Add your own test actions here
fail("Define your test");
}
//----------------------------------------------------------
/**
* Check that multiplyBy works on non-zero accumulators.
*/
@Test
public void multiplication()
{
// Add your own test actions here
fail("Define your test");
}
//----------------------------------------------------------
/**
* Check that divideBy works on non-zero accumulators.
*/
@Test
public void division()
{
// Add your own test actions here
calc.setValue(20);
calc.divideBy(5);
assertEquals(4, calc.getValue());
calc.setValue(20);
calc.divideBy(2);
assertEquals(10, calc.getValue());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!