
org.jeometry.factory.GeometryFactoryMeshTest Maven / Gradle / Ivy
package org.jeometry.factory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import org.jeometry.Geometry;
import org.jeometry.geom3D.mesh.indexed.IndexedEdge;
import org.jeometry.geom3D.mesh.indexed.IndexedFace;
import org.jeometry.geom3D.mesh.indexed.IndexedMesh;
import org.jeometry.geom3D.point.Point3D;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* A test class for {@link GeometryFactory} methods that delegate to a {@link MeshBuilder mesh builder}.
*
* Usage:
*
* Create a class that extends this one and add the method:
*
* {@literal @}BeforeClass
* public static void initClass() {
*
* meshClass = [the mesh implementation];
* faceClass = [the face implementation];
* edgeClass = [the edge implementation];
*
* indexedMeshClass = [the indexed mesh implementation];
* indexedFaceClass = [the indexed face implementation];
* indexedEdgeClass = [the indexed edge implementation];
*
* GeometryFactory.setMeshBuilder([a builder that provide suitable classes]);
* }
*
*
* If the object provided by the geometry factory are not from the same classes as the declared ones, tests will fail.
*
* @author Julien Seinturier - COMEX S.A. - [email protected] - https://github.com/jorigin/jeometry
* @version {@value Geometry#version}
* @since 1.0.0
*
*/
public class GeometryFactoryMeshTest {
protected static Class> meshClass = null;
protected static Class> faceClass = null;
protected static Class> edgeClass = null;
protected static Class> indexedMeshClass = null;
protected static Class> indexedFaceClass = null;
protected static Class> indexedEdgeClass = null;
/**
* Test initialization.
*/
@BeforeClass
public static void init() {
fail("method public static void init() has to be set up with @BeforeClass annotation");
}
/**
* Testing {@link GeometryFactory#createIndexedMesh()}
*/
@Test
public void createIndexedMeshTest() {
try {
IndexedMesh mesh = GeometryFactory.createIndexedMesh();
assertNotNull("Cannot instantiate indexed mesh using GeometryFactory.createIndexedMesh().", mesh);
if (indexedMeshClass != null) {
assertTrue("Invalid class: "+indexedMeshClass.getSimpleName()+" expected but found "+mesh.getClass().getSimpleName(), indexedMeshClass.isInstance(mesh));
}
} catch (Exception e) {
fail("Cannot instantiate indexed mesh using GeometryFactory.createIndexedMesh(): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMesh(int)}
*/
@Test
public void createIndexedMeshCapacityTest() {
try {
IndexedMesh mesh = GeometryFactory.createIndexedMesh(10);
assertNotNull("Cannot instantiate indexed mesh using GeometryFactory.createIndexedMesh(int).", mesh);
if (indexedMeshClass != null) {
assertTrue("Invalid class: "+indexedMeshClass.getSimpleName()+" expected but found "+mesh.getClass().getSimpleName(), indexedMeshClass.isInstance(mesh));
}
} catch (Exception e) {
fail("Cannot instantiate indexed mesh using GeometryFactory.createIndexedMesh(int): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMeshEdge(int, int)}
*/
@Test
public void createIndexedMeshEdgeIntIntTest() {
try {
IndexedEdge edge = GeometryFactory.createIndexedMeshEdge(1, 2);
assertNotNull("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshEdge(int, int).", edge);
if (indexedEdgeClass != null) {
assertTrue("Invalid class: "+indexedEdgeClass.getSimpleName()+" expected but found "+edge.getClass().getSimpleName(), indexedEdgeClass.isInstance(edge));
}
assertNotNull("Edge vertex indices are invalid.", edge.getVerticesIndexes());
assertEquals("Edge vertex indices number is invalid.", 2, edge.getVerticesIndexes().length, 0);
assertEquals("Edge extremity 1 is invalid.", 1, edge.getVerticesIndexes()[0], 0);
assertEquals("Edge extremiti 2 is invalid.", 2, edge.getVerticesIndexes()[1], 0);
} catch (Exception e) {
fail("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshEdge(int, int): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMeshEdge(int, int, IndexedMesh)}
*/
@Test
public void createIndexedMeshEdgeIntIntMeshTest() {
try {
IndexedMesh mesh = GeometryFactory.createIndexedMesh();
IndexedEdge edge = GeometryFactory.createIndexedMeshEdge(1, 2, mesh);
assertNotNull("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshEdge(int, int, IndexedMesh).", edge);
if (indexedEdgeClass != null) {
assertTrue("Invalid class: "+indexedEdgeClass.getSimpleName()+" expected but found "+edge.getClass().getSimpleName(), indexedEdgeClass.isInstance(edge));
}
assertNotNull("Edge vertex indices are invalid.", edge.getVerticesIndexes());
assertEquals("Edge vertex indices number is invalid.", 2, edge.getVerticesIndexes().length, 0);
assertEquals("Edge extremity 1 is invalid.", 1, edge.getVerticesIndexes()[0], 0);
assertEquals("Edge extremiti 2 is invalid.", 2, edge.getVerticesIndexes()[1], 0);
assertEquals("Edge mesh is invalid.", mesh, edge.getMesh());
} catch (Exception e) {
fail("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshEdge(int, int, IndexedMesh): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMeshFace(int[])}
*/
@Test
public void createIndexedMeshFaceIntArrayTest() {
try {
int[] indices = new int[] {1, 2, 3, 4, 5, 6};
IndexedFace face = GeometryFactory.createIndexedMeshFace(indices);
assertNotNull("Cannot instantiate indexed face using GeometryFactory.createIndexedMeshFace(int[]).", face);
assertNotNull("Face vertex indices are invalid.", face.getVerticesIndexes());
assertEquals("Face vertex indices number is invalid.", indices.length, face.getVerticesIndexes().length, 0);
for(int i = 0; i < indices.length; i++) {
assertEquals("Face indice "+i+" differs from expected.", indices[i], face.getVerticesIndexes()[i], 0);
}
} catch (Exception e) {
fail("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshFace(int[]): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMeshFace(int[], IndexedMesh)}
*/
@Test
public void createIndexedMeshFaceIntArrayMeshTest() {
try {
int[] indices = new int[] {1, 2, 3, 4, 5, 6};
IndexedMesh mesh = GeometryFactory.createIndexedMesh();
IndexedFace face = GeometryFactory.createIndexedMeshFace(indices, mesh);
assertNotNull("Cannot instantiate indexed face using GeometryFactory.createIndexedMeshFace(int[], IndexedMesh).", face);
assertNotNull("Face vertex indices are invalid.", face.getVerticesIndexes());
assertEquals("Face vertex indices number is invalid.", indices.length, face.getVerticesIndexes().length, 0);
for(int i = 0; i < indices.length; i++) {
assertEquals("Face indice "+i+" differs from expected.", indices[i], face.getVerticesIndexes()[i], 0);
}
assertEquals("Edge mesh is invalid.", mesh, face.getMesh());
} catch (Exception e) {
fail("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshFace(int[], IndexedMesh): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMeshFace(List)}
*/
@Test
public void createIndexedMeshFaceIntListTest() {
try {
List indices = new ArrayList(6);
indices.add(1);
indices.add(2);
indices.add(3);
indices.add(4);
indices.add(5);
indices.add(6);
IndexedFace face = GeometryFactory.createIndexedMeshFace(indices);
assertNotNull("Cannot instantiate indexed face using GeometryFactory.createIndexedMeshFace(List).", face);
assertNotNull("Face vertex indices are invalid.", face.getVerticesIndexes());
assertEquals("Face vertex indices number is invalid.", indices.size(), face.getVerticesIndexes().length, 0);
for(int i = 0; i < indices.size(); i++) {
assertEquals("Face indice "+i+" differs from expected.", indices.get(i), face.getVerticesIndexes()[i], 0);
}
} catch (Exception e) {
fail("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshFace(List): "+e.getMessage());
}
}
/**
* Testing {@link GeometryFactory#createIndexedMeshFace(List, IndexedMesh)}
*/
@Test
public void createIndexedMeshFaceIntListMeshTest() {
try {
List indices = new ArrayList(6);
indices.add(1);
indices.add(2);
indices.add(3);
indices.add(4);
indices.add(5);
indices.add(6);
IndexedMesh mesh = GeometryFactory.createIndexedMesh();
IndexedFace face = GeometryFactory.createIndexedMeshFace(indices, mesh);
assertNotNull("Cannot instantiate indexed face using GeometryFactory.createIndexedMeshFace(List, IndexedMesh).", face);
assertNotNull("Face vertex indices are invalid.", face.getVerticesIndexes());
assertEquals("Face vertex indices number is invalid.", indices.size(), face.getVerticesIndexes().length, 0);
for(int i = 0; i < indices.size(); i++) {
assertEquals("Face indice "+i+" differs from expected.", indices.get(i), face.getVerticesIndexes()[i], 0);
}
assertEquals("Edge mesh is invalid.", mesh, face.getMesh());
} catch (Exception e) {
fail("Cannot instantiate indexed edge using GeometryFactory.createIndexedMeshFace(List, IndexedMesh): "+e.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy