Skip to content
Snippets Groups Projects
Commit 603ecc1a authored by Matias Mennecart's avatar Matias Mennecart
Browse files

Merge branch 'maxenceantoine' into 'master'

Ajout des tests

See merge request sae302/2024/H4_SAE3.3!13
parents ec76e2f6 61f09125
Branches
Tags
No related merge requests found
package fr.univlille.sae.classification.model;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class ClassificationModelTest {
private ClassificationModel model;
@BeforeEach
void setUp() {
model = ClassificationModel.getClassificationModel();
}
@Test
void testSingletonInstance() {
ClassificationModel anotherModel = ClassificationModel.getClassificationModel();
assertSame(model, anotherModel);
}
@Test
void testAjouterDonnee() {
double[] coords = {5.1, 3.5, 1.4, 0.2};
model.ajouterDonnee(coords);
List<LoadableData> dataToClass = model.getDataToClass();
assertEquals(1, dataToClass.size());
assertNotNull(dataToClass.get(0).getClassification());
}
@Test
void testAjouterDonneeInsuffisante() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
model.ajouterDonnee(5.1);
});
assertEquals(null, exception.getMessage());
}
@Test
void testLoadData() throws IOException {
File csvTemp = File.createTempFile("test", ".csv");
String csvTest = "sepal_length,sepal_width,petal_length,petal_width,class\n" +
"5.1,3.5,1.4,0.2,Iris-setosa\n" +
"4.9,3.0,1.4,0.2,Iris-setosa\n";
Files.write(Paths.get(csvTemp.getAbsolutePath()), csvTest.getBytes());
model.loadData(csvTemp);
List<LoadableData> datas = model.getDatas();
assertEquals(2, datas.size());
csvTemp.delete();
}
@Test
void testClassifierDonnees() {
double[] coords1 = {5.1, 3.5, 1.4, 0.2};
double[] coords2 = {4.9, 3.0, 1.4, 0.2};
model.ajouterDonnee(coords1);
model.ajouterDonnee(coords2);
model.classifierDonnees();
assertEquals(0, model.getDataToClass().size());
}
@Test
void testSetType() {
model.setType(DataType.IRIS);
assertEquals(DataType.IRIS, model.getType());
}
}
package fr.univlille.sae.classification.model;
import javafx.scene.paint.Color;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class IrisTest {
Iris iris = new Iris(2.8, 3.0, 1.9, 4.1, "Setosa");
@Test
void getSepalWidth() {
assertEquals(3.0 , iris.getSepalWidth());
}
@Test
void getSepalLength() {
assertEquals(2.8, iris.getSepalLength());
}
@Test
void getPetalWidth() {
assertEquals(4.1, iris.getPetalWidth());
}
@Test
void getPetalLength() {
assertEquals(1.9, iris.getPetalLength());
}
@Test
void getDataType() {
assertEquals(3.0 , iris.getDataType("sepalWidth"));
assertEquals(2.8, iris.getDataType("sepalLength"));
assertEquals(4.1, iris.getDataType("petalWidth"));
assertEquals(1.9, iris.getDataType("petalLength"));
}
@Test
void getColor() {
assertEquals(Color.RED, iris.getColor());
}
@Test
void testToString() {
assertEquals("Iris{sepalLength=2.8, sepalWidth=3.0, petalLength=1.9, petalWidth=4.1}", iris.toString());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment