Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

=+11.3. Show that Theorem 11.4(ii) can fail if u(B) =00.

Answered: 1 week ago