Skip to content
Snippets Groups Projects
Commit 61f09125 authored by Maxence Antoine's avatar Maxence Antoine
Browse files

ajout des tests pour ClassificationModel

parent 594b42d4
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 getClassificationModel() {
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 getDatas() {
void testAjouterDonneeInsuffisante() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
model.ajouterDonnee(5.1);
});
assertEquals(null, exception.getMessage());
}
@Test
void getDataToClass() {
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 getType() {
void testSetType() {
model.setType(DataType.IRIS);
assertEquals(DataType.IRIS, model.getType());
}
}
\ 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