I have this calculator .java from an online practice and I need to test it in JUnit in Eclipse;
package calculator;
import java.util.Scanner;
public class Calculator {
private double accumulator;
public Calculator() { }
public Calculator(double initialValue) { accumulator = initialValue; }
public void add(double number) { accumulator += number; }
public void subtract(double number) { accumulator -= number; }
public void multiply(double number) { accumulator *= number; }
public void divide(double number) { accumulator /= number; }
public void sqrt() { accumulator = Math.sqrt(accumulator); }
public void setAccumlator(double accumulator) { this.accumulator = accumulator; }
public double getAccumulator() { return accumulator; }
@Override
public String toString() { return "Result:" + accumulator; }
}
I've been pouring through documentation (I'm rather new to programming in general) and unsure of how to actually do this. I have JUnit set up and a test file set up, like;
@Test
public void testAdd(){
}
@Test
public void testDivideByZero(){
}
etc.
I've tried a few things and the syntax was wrong, stuff like
The method add(double) in the type Calculator is not applicable for the arguments (double, double)
or
Cannot make a static reference to the non static method add(double) from the type Calculator
Any suggestions?