Skip to content
Snippets Groups Projects
Commit 635b0979 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Ajout test

parent 93f0cd9b
No related branches found
No related tags found
No related merge requests found
package formula;
import java.util.HashMap;
public class Constant implements Formula {
private double value;
public Constant(double value) {
// TODO : change the code.
}
/**
* Compute the value of the formula
*
* @param xValue the value of the variable x
* @return the value of the function when the variable x has value {@code xValue}
*/
@Override
public double eval(double xValue) {
// TODO : change the code.
return 0;
}
/**
* Compute the derivative of the formula.
*
* @return the derivative of the formula
*/
@Override
public Formula derivative() {
// TODO : change the code.
return this;
}
/**
* Return a {@code String} representation of the formula.
*
* @return the formula as a {@code String}
*/
@Override
public String toString() {
// TODO : change the code.
return "toto";
}
/**
* Indicates whether some other object is "equal to" this one.
*
* @param obj the reference object with which to compare.
* @return {@code true} if this object is the same as the obj
* argument; {@code false} otherwise.
* @see #hashCode()
* @see HashMap
*/
@Override
public boolean equals(Object obj) {
if(obj == null) return false;
if(!(obj instanceof Constant constant)) return false;
return this.value == constant.value;
}
}
package viewer; package viewer;
import formula.Constant;
import javafx.scene.chart.XYChart; import javafx.scene.chart.XYChart;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -18,9 +19,8 @@ class FunctionList { ...@@ -18,9 +19,8 @@ class FunctionList {
this.lowerBound = functionChart.getLowerBound(); this.lowerBound = functionChart.getLowerBound();
this.upperBound = functionChart.getUpperBound(); this.upperBound = functionChart.getUpperBound();
// TODO: add functions PlottableFunction function = new PlottableFunction(new Constant(1), "f");
addFunctionAndItsDerivative(function);
} }
void toggleFunction(PlottableFunction function) { void toggleFunction(PlottableFunction function) {
......
...@@ -45,6 +45,7 @@ public class MainAppController implements Initializable { ...@@ -45,6 +45,7 @@ public class MainAppController implements Initializable {
Button button = new Button(function.toString()); Button button = new Button(function.toString());
addButton(button); addButton(button);
button.setOnAction(event -> toggleFunction(function)); button.setOnAction(event -> toggleFunction(function));
toggleFunction(function);
} }
private void toggleFunction(PlottableFunction function){ private void toggleFunction(PlottableFunction function){
......
import formula.Constant;
import formula.Formula;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
public class ConstantTest {
@Test
public void testEval(){
Constant constantTen = new Constant(10);
assertThat(constantTen.eval(0.)).isCloseTo(10., within(.001));
Constant constantOne = new Constant(1);
assertThat(constantOne.eval(10.)).isCloseTo(1., within(.001));
}
@Test
public void testToString(){
Constant constantTen = new Constant(10);
assertThat(constantTen.toString()).isEqualTo("10.0");
Constant constantOne = new Constant(1);
assertThat(constantOne.toString()).isEqualTo("1.0");
}
@Test
public void testEquals() {
Constant constantTen = new Constant(10);
Constant constantTen2 = new Constant(10);
Constant constantOne = new Constant(0);
assertThat(constantTen).isEqualTo(constantTen);
assertThat(constantTen).isEqualTo(constantTen2);
assertThat(constantTen).isNotEqualTo(constantOne);
}
@Test
public void testDerivative() {
Constant constantTen = new Constant(10);
Formula derivedConstant = constantTen.derivative();
assertThat(derivedConstant.eval(10.)).isCloseTo(0., within(.001));
Constant constantZero = new Constant(0);
assertThat(derivedConstant).isEqualTo(constantZero);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment