From: <emm...@us...> - 2008-12-30 17:02:15
|
Revision: 4317 http://fudaa.svn.sourceforge.net/fudaa/?rev=4317&view=rev Author: emmanuel_martin Date: 2008-12-30 17:02:04 +0000 (Tue, 30 Dec 2008) Log Message: ----------- correction du test unitaire Added Paths: ----------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestProfilContainerAdapter.java Removed Paths: ------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java Deleted: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java 2008-12-30 15:19:53 UTC (rev 4316) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java 2008-12-30 17:02:04 UTC (rev 4317) @@ -1,914 +0,0 @@ -/* - * @creation 16 d\xE9c. 2008 - * @modification $Date:$ - * @license GNU General Public License 2 - * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne - * @mail fud...@li... - */ -package testModeleur1d; - -import junit.framework.TestCase; - -import org.fudaa.ctulu.gis.GISAttributeConstants; -import org.fudaa.ctulu.gis.GISAttributeInterface; -import org.fudaa.ctulu.gis.GISGeometryFactory; -import org.fudaa.ctulu.gis.GISPolyligne; -import org.fudaa.ctulu.gis.GISZoneCollectionLigneBrisee; -import org.fudaa.fudaa.modeleur.modeleur1d.model.DataGeometryAdapter; -import org.fudaa.fudaa.modeleur.modeleur1d.model.DataGeometryException; -import org.fudaa.fudaa.modeleur.modeleur1d.model.DataGeometryListener; - -import com.vividsolutions.jts.geom.Coordinate; - -/** - * Test pour DataGeometryAdapter. - * @author Emmanuel MARTIN - * @version $Id$ - */ -public class TestDataGeometryAdapter extends TestCase { - - /** Tolerance pour les comparaisons de doubles. */ - private double tolerance=0.000001; - private DataGeometryAdapter geomAdapter_; - private GISZoneCollectionLigneBrisee zone0_; - private GISZoneCollectionLigneBrisee zone1_; - private GISZoneCollectionLigneBrisee zone3_; - private GISZoneCollectionLigneBrisee zone4_; - private GISZoneCollectionLigneBrisee zone5_; - private GISZoneCollectionLigneBrisee zone6_; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @Override - protected void setUp() throws Exception { - super.setUp(); - geomAdapter_=new DataGeometryAdapter(null, -1); - // Zone6_ \\ - // Attribut z non d\xE9fini - zone6_=new GISZoneCollectionLigneBrisee(); - zone6_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); - zone6_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), - new Coordinate(50, 10, 10)}), null, null); - // Zone0_ \\ - // Quelconque - zone0_=new GISZoneCollectionLigneBrisee(); - zone0_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); - zone0_.setAttributeIsZ(GISAttributeConstants.BATHY); - zone0_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), - new Coordinate(50, 10, 10)}), null, null); - // Zone1_ \\ - // Quelconque - zone1_=new GISZoneCollectionLigneBrisee(); - zone1_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); - zone1_.setAttributeIsZ(GISAttributeConstants.BATHY); - zone1_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory() - .create( - new Coordinate[]{new Coordinate(8, 6, 0), new Coordinate(5.052590034554651, 6.559262456806686, 0), - new Coordinate(3, 2, 0)}), null, null); - // Zone3_ \\ - // Quelconque - zone3_=new GISZoneCollectionLigneBrisee(); - zone3_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); - zone3_.setAttributeIsZ(GISAttributeConstants.BATHY); - zone3_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), new Coordinate(50, 10, 10), - new Coordinate(30, 5, 5), new Coordinate(10, 0, 0)}), null, null); - zone3_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(5, 0, 0), new Coordinate(-15, -20, -20), new Coordinate(55, 10, 10), - new Coordinate(35, 5, -20), new Coordinate(15, 0, -20)}), null, null); - // zone4_ \\ - zone4_=new GISZoneCollectionLigneBrisee(); - zone4_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); - zone4_.setAttributeIsZ(GISAttributeConstants.BATHY); - // 0 : Points confondus - zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), new Coordinate(-10, -20, -20), - new Coordinate(-20, -40, -40), new Coordinate(-30, -60, -60)}), null, null); - // 1 : nb ruptures > 2 - zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 20, 5), new Coordinate(11, 100, 8), new Coordinate(41, 5, 9), new Coordinate(41, 0, 8)}), null, null); - // 2 : nb ruptures = 1 - zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(11, 100, 8), new Coordinate(12, 101, 10), new Coordinate(13, 102, -5)}), null, null); - // 3 : nb ruptures = 0 - zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 20, 5), new Coordinate(20, 40, 8)}), null, null); - // 4 : nb ruptures = 2 - zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(10, 10, 0), new Coordinate(20, 10, 5), new Coordinate(20, 20, 8), new Coordinate(25, 20, 8), new Coordinate(30, 20, 8)}), null, null); - // 5 : axes crois\xE9s - zone4_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(10, 10, 0), new Coordinate(20, 10, 5), new Coordinate(20, 20, 8), new Coordinate(10, 5, 8)}), null, null); - // Zone5_ \\ - zone5_=new GISZoneCollectionLigneBrisee(); - zone5_.setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); - zone5_.setAttributeIsZ(GISAttributeConstants.BATHY); - // 0 : 2 points align\xE9s (cas g\xE9n\xE9ral) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, -4)}), null, null); - // 1 : 2 points align\xE9s parall\xE8le \xE0 l'axe des X - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(5, 10, 3), new Coordinate(20, 10, -7)}), null, null); - // 2 : 2 points align\xE9s parall\xE8le \xE0 l'axe des Y - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(5, 0, 0), new Coordinate(5, 10, 88)}), null, null); - // 3 : 3 points align\xE9s (cas g\xE9n\xE9ral) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0)}), null, null); - // 4 : 3 points align\xE9s parall\xE8le \xE0 l'axe des X - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(-5, 10, 3), new Coordinate(20, 10, 6), new Coordinate(20.4, 10, 2)}), null, null); - // 5 : 3 points align\xE9s parall\xE8le \xE0 l'axe des Y - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(-5, 10, 8), new Coordinate(-5, -2, -2), new Coordinate(-5, -50, 50)}), null, null); - // 6 : 4 points align\xE9s (cas g\xE9n\xE9ral) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(1, 1, 0), new Coordinate(2, 1, 3), new Coordinate(8, 5, -9), new Coordinate(40, 25, 99)}), null, null); - // 7 : 4 points align\xE9s parall\xE8le \xE0 l'axe des X - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(1, 2.56, -2), new Coordinate(10, 2.56, 0), new Coordinate(99, 2.56, 84), new Coordinate(100.5, 2.56, 100)}), null, null); - // 8 : 4 points align\xE9s parall\xE8le \xE0 l'axe des Y - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(-9.1, 88, 0), new Coordinate(-9.1, 50, 8), new Coordinate(-9.1, 0, -87), new Coordinate(-9.1, -10, -10)}), null, null); - // 9 : 3 points avec un point de rupture - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9)}), null, null); - // 10 : 4 points avec un point de rupture (deux points sur le premier axe) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0), new Coordinate(50, 60, 70)}), null, null); - // 11 : 5 points avec un point de rupture (deux points sur chaque axe) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0), new Coordinate(33, 3.75, 9), new Coordinate(11, 1.25, 9)}), null, null); - // 12 : 4 points avec deux points de ruptures - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); - // 13 : 5 points avec deux points de ruptures (deux points sur le premier axe) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); - // 14 : 6 points avec deux points de ruptures (deux points sur les deux premiers axes) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); - // 15 : 7 points avec deux points de ruptures (deux points sur chacun des axes) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -5, 9), new Coordinate(15, -2.5, 2), new Coordinate(20, 0, 0)}), null, null); - // 16 : 10 points avec deux points de ruptures (trois points sur chacun des axes) - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(2.5, 1.25, 44), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -2, 0), new Coordinate(10, -5, 9), new Coordinate(10/2., -5/2., 2), new Coordinate(10/4., -5/4., 0), new Coordinate(10/8., -5/8., 0)}), null, null); - // 17 : 3 points avec un point de rupture et le premier et le dernier points sont sur le m\xEAme axe des y - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(5, 5, -9), new Coordinate(10, 10, 0), new Coordinate(5, 20, 0)}), null, null); - // 18 : 3 points avec un point de rupture et le premier et le dernier points sont sur le m\xEAme axe des x - zone5_.addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( - new Coordinate[]{new Coordinate(5, 5, -9), new Coordinate(10, 10, 0), new Coordinate(20, 5, 0)}), null, null); - } - - public void testDataGeometryAdapter() throws IllegalArgumentException, DataGeometryException { - // Points confondus - try { - new DataGeometryAdapter(zone4_, 0); - fail(); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) {} - // nb points > 2 - try { - new DataGeometryAdapter(zone4_, 1); - fail(); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) {} - // nb ruptures = 1 - try { - new DataGeometryAdapter(zone4_, 2); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - // nb ruptures = 0 - try { - new DataGeometryAdapter(zone4_, 3); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - // nb ruptures = 2 - try { - new DataGeometryAdapter(zone4_, 4); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - // axes crois\xE9s - try { - new DataGeometryAdapter(zone4_, 5); - fail(); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - } - // aguments invalide - geomAdapter_=new DataGeometryAdapter(null, -1); - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(null, 0); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(null, 1); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, -1); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, -10); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()+1); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments valide - try { - new DataGeometryAdapter(zone3_, zone3_.getNbGeometries()-1); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - } - - public void testSetData() throws IllegalArgumentException, DataGeometryException { - // Zone sans attribut Z d\xE9fini - try{ - geomAdapter_.setData(zone6_, 0); - } - catch (DataGeometryException _exc) { - fail(); - } - catch(IllegalArgumentException _exc){} - // Points confondus - try { - new DataGeometryAdapter(zone4_, 0); - fail(); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) {} - // nb points > 2 - try { - new DataGeometryAdapter(zone4_, 1); - fail(); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) {} - // nb ruptures = 1 - try { - new DataGeometryAdapter(zone4_, 2); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - // nb ruptures = 0 - try { - new DataGeometryAdapter(zone4_, 3); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - // nb ruptures = 2 - try { - new DataGeometryAdapter(zone4_, 4); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - // axes crois\xE9s - try { - new DataGeometryAdapter(zone4_, 5); - fail(); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - } - // aguments invalide - geomAdapter_=new DataGeometryAdapter(null, -1); - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(null, 0); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(null, 1); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, -1); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, -10); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments invalide - try { - geomAdapter_=new DataGeometryAdapter(zone4_, zone4_.getNbGeometries()+1); - fail(); - } - catch (IllegalArgumentException _exc) { - assertNull(geomAdapter_.getGISZoneCollection()); - assertEquals(-1, geomAdapter_.getIdxGeom()); - } - catch (DataGeometryException _exc) { - fail(); - } - // aguments valide - try { - new DataGeometryAdapter(zone3_, zone3_.getNbGeometries()-1); - } - catch (IllegalArgumentException _exc) { - fail(); - } - catch (DataGeometryException _exc) { - fail(); - } - } - - public void testGetGISZoneCollection() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(zone0_, geomAdapter_.getGISZoneCollection()); - geomAdapter_.setData(zone1_, 0); - assertEquals(zone1_, geomAdapter_.getGISZoneCollection()); - geomAdapter_.setData(null, -1); - assertEquals(null, geomAdapter_.getGISZoneCollection()); - } - - public void testGetIdxGeom() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(0, geomAdapter_.getIdxGeom()); - geomAdapter_.setData(zone3_, 0); - assertEquals(0, geomAdapter_.getIdxGeom()); - geomAdapter_.setData(zone3_, 1); - assertEquals(1, geomAdapter_.getIdxGeom()); - geomAdapter_.setData(null, -1); - assertEquals(-1, geomAdapter_.getIdxGeom()); - geomAdapter_.setData(zone0_, zone0_.getNbGeometries()-1); - assertEquals(zone0_.getNbGeometries()-1, geomAdapter_.getIdxGeom()); - } - - public void testGetNbPoint() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(3, geomAdapter_.getNbPoint()); - geomAdapter_.setData(zone1_, 0); - assertEquals(3, geomAdapter_.getNbPoint()); - geomAdapter_.setData(zone3_, 0); - assertEquals(5, geomAdapter_.getNbPoint()); - geomAdapter_.setData(zone3_, 1); - assertEquals(5, geomAdapter_.getNbPoint()); - geomAdapter_.setData(null, -1); - assertEquals(0, geomAdapter_.getNbPoint()); - } - - public void testGetCurv() throws IllegalArgumentException, DataGeometryException { - // Cas limits - geomAdapter_.setData(null, -1); - try { - geomAdapter_.getCurv(0); - fail(); - } - catch (IllegalArgumentException _exc) {} - geomAdapter_.setData(zone0_, 0); - try { - geomAdapter_.getCurv(-1); - fail(); - } - catch (IllegalArgumentException _exc) {} - try { - geomAdapter_.getCurv(-5); - fail(); - } - catch (IllegalArgumentException _exc) {} - try { - geomAdapter_.getCurv(geomAdapter_.getNbPoint()); - fail(); - } - catch (IllegalArgumentException _exc) {} - // Cas g\xE9n\xE9rals - assertEquals(0, geomAdapter_.getCurv(0), tolerance); - assertEquals(Math.sqrt(10*10+20*20), geomAdapter_.getCurv(1), tolerance); - assertEquals(Math.sqrt(10*10+20*20)+Math.sqrt((50+10)*(50+10)+(10+20)*(10+20)), geomAdapter_.getCurv(2), tolerance); - } - - public void testGetZ() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(0, geomAdapter_.getZ(0), tolerance); - assertEquals(-20, geomAdapter_.getZ(1), tolerance); - assertEquals(10, geomAdapter_.getZ(2), tolerance); - geomAdapter_.setData(null, -1); - try { - geomAdapter_.getZ(0); - fail(); - } - catch(IllegalArgumentException ex){} - geomAdapter_.setData(zone0_, 0); - try { - geomAdapter_.getZ(-1); - fail(); - } - catch (IllegalArgumentException _exc) { - } - geomAdapter_.setData(zone0_, 0); - try { - geomAdapter_.getZ(100); - fail(); - } - catch (IllegalArgumentException _exc) { - } - } - - public void testSetCurv() throws Exception { - // Cas limits - geomAdapter_.setData(null, -1); - try{ - geomAdapter_.setCurv(0, 0, null); - fail(); - } - catch(IllegalArgumentException _exc) {} - try{ - geomAdapter_.setCurv(-1, 0, null); - fail(); - } - catch(IllegalArgumentException _exc) {} - geomAdapter_.setData(zone1_, 0); - try{ - geomAdapter_.setCurv(-1, 0, null); - fail(); - } - catch(IllegalArgumentException _exc) {} - try{ - geomAdapter_.setCurv(zone1_.getGeometry(0).getNumPoints(), 0, null); - fail(); - } - catch(IllegalArgumentException _exc) {} - try{ - geomAdapter_.setCurv(zone1_.getGeometry(0).getNumPoints()+1, 0, null); - fail(); - } - catch(IllegalArgumentException _exc) {} - // Une abcisse curviligne peut \xEAtre donn\xE9 pour le premier point, seulement pour lui - geomAdapter_.setData(zone5_, 0); - try{ - geomAdapter_.setCurv(0, -1, null); - } - catch(Exception exc){ - fail(); - } - try{ - geomAdapter_.setCurv(1, -1, null); - fail(); - } - catch(DataGeometryException exc){} - try{ - geomAdapter_.setCurv(geomAdapter_.getNbPoint()-1, -1, null); - fail(); - } - catch(DataGeometryException exc){} - setUp(); - // Test sur le d\xE9placement d'un point au del\xE0 d'un autre ou au niveau d'un autre - geomAdapter_.setData(zone5_, 0); - try{ - geomAdapter_.setCurv(0, Math.sqrt(10*10+5*5)+1, null); - fail(); - } - catch(DataGeometryException exc){} - try{ - geomAdapter_.setCurv(1, 0, null); - fail(); - } - catch(DataGeometryException exc){} - geomAdapter_.setData(zone5_, 6); - try{ - geomAdapter_.setCurv(2, geomAdapter_.getCurv(1)-0.1, null); - fail(); - } - catch(DataGeometryException exc){} - geomAdapter_.setData(zone5_, 11); - try{ // Tentative de se placer sur un point de rupture - geomAdapter_.setCurv(3, geomAdapter_.getCurv(2), null); - fail(); - } - catch(DataGeometryException exc){} - try{ // Tentative d'un point de rupture de d\xE9pacer un point adjacent - geomAdapter_.setCurv(2, geomAdapter_.getCurv(3)+1, null); - fail(); - } - catch(DataGeometryException exc){} - - // D\xE9placement des points extr\xE9mit\xE9s \\ - // Cas g\xE9n\xE9ral, d\xE9placement d\xE9but - geomAdapter_.setData(zone5_, 0); - double curvOld=geomAdapter_.getCurv(1); - geomAdapter_.setCurv(0, Math.sqrt(5*5+2.5*2.5), null); - assertEquals(curvOld-Math.sqrt(5*5+2.5*2.5), geomAdapter_.getCurv(1), tolerance); - assertEquals(5, zone5_.getGeometry(0).getCoordinates()[0].x, tolerance); - assertEquals(2.5, zone5_.getGeometry(0).getCoordinates()[0].y, tolerance); - setUp(); - // Cas g\xE9n\xE9ral, d\xE9placement fin avec point de ruptures - geomAdapter_.setData(zone5_, 16); - curvOld=geomAdapter_.getCurv(9); - geomAdapter_.setCurv(9, geomAdapter_.getCurv(8)+Math.sqrt((10/4.-10/16.)*(10/4.-10/16.)+(-5/4.+5/16.)*(-5/4.+5/16.)), null); - assertEquals(geomAdapter_.getCurv(8)+Math.sqrt((10/4.-10/16.)*(10/4.-10/16.)+(-5/4.+5/16.)*(-5/4.+5/16.)), geomAdapter_.getCurv(9), tolerance); - assertEquals(10/16., zone5_.getGeometry(16).getCoordinates()[9].x, tolerance); - assertEquals(-5/16., zone5_.getGeometry(16).getCoordinates()[9].y, tolerance); - setUp(); - // Cas particulier parall\xE8le \xE0 l'axe des x - geomAdapter_.setData(zone5_, 1); - curvOld=geomAdapter_.getCurv(1); - geomAdapter_.setCurv(0, -5, null); - assertEquals(curvOld+5, geomAdapter_.getCurv(1), tolerance); - assertEquals(0, zone5_.getGeometry(1).getCoordinates()[0].x, tolerance); - assertEquals(10, zone5_.getGeometry(1).getCoordinates()[0].y, tolerance); - setUp(); - // Cas particulier parall\xE8le \xE0 l'axe des y - geomAdapter_.setData(zone5_, 8); - curvOld=geomAdapter_.getCurv(2); - geomAdapter_.setCurv(0, -5, null); - assertEquals(curvOld+5, geomAdapter_.getCurv(2), tolerance); - assertEquals(-9.1, zone5_.getGeometry(8).getCoordinates()[0].x, tolerance); - assertEquals(93, zone5_.getGeometry(8).getCoordinates()[0].y, tolerance); - setUp(); - // D\xE9placement de points non extr\xE9mit\xE9 non de rupture \\ - // Cas g\xE9n\xE9ral : d\xE9placement d'un point au centre ; axe sans point de ruptures et parall\xE8le \xE0 l'axe des x - geomAdapter_.setData(zone5_, 4); - curvOld=geomAdapter_.getCurv(1); - double curvOld2=geomAdapter_.getCurv(2); - geomAdapter_.setCurv(1, geomAdapter_.getCurv(1)-5, null); - assertEquals(curvOld-5, geomAdapter_.getCurv(1), tolerance); - assertEquals(curvOld2, geomAdapter_.getCurv(2), tolerance); - assertEquals(15, zone5_.getGeometry(4).getCoordinates()[1].x, tolerance); - assertEquals(10, zone5_.getGeometry(4).getCoordinates()[1].y, tolerance); - setUp(); - // Cas g\xE9n\xE9ral : d\xE9placement d'un point au centre avec 2 points de ruptures - geomAdapter_.setData(zone5_, 15); - curvOld=geomAdapter_.getCurv(3); - curvOld2=geomAdapter_.getCurv(1); - geomAdapter_.setCurv(3, geomAdapter_.getCurv(3)-2, null); - assertEquals(curvOld-2, geomAdapter_.getCurv(3), tolerance); - assertEquals(curvOld2, geomAdapter_.getCurv(1), tolerance); - assertEquals(10, zone5_.getGeometry(15).getCoordinates()[3].x, tolerance); - assertEquals(2, zone5_.getGeometry(15).getCoordinates()[3].y, tolerance); - setUp(); - - // Cas sp\xE9cial : d\xE9placement d'un point de rupture \\ - // Cas classique : d\xE9placement d'un point de rupture sur un axe en ayant deux et des points un peut partout - geomAdapter_.setData(zone5_, 14); - double[] absCurv=new double[6]; - for(int i=0;i<6;i++) - absCurv[i]=geomAdapter_.getCurv(i); - geomAdapter_.setCurv(2,geomAdapter_.getCurv(2)-2, null); - absCurv[2]=absCurv[2]-2; - // R\xE9instancier un nouvel adapter va verifier si il n'y a pas de nouveaux points de ruptures qui sont apparux ou qu'il y ai pas des axes qui se croisent - DataGeometryAdapter testAdapter=null; - try{ - testAdapter=new DataGeometryAdapter(zone5_, 14); - } - catch(Exception exc){ - fail(); - } - assertEquals(6, testAdapter.getNbPoint()); - // test des nouvelles abs curviligne - for(int i=0;i<6;i++) - assertEquals(absCurv[i], testAdapter.getCurv(i), tolerance); - setUp(); - // Test sur les coordonn\xE9es g\xE9n\xE9r\xE9es - geomAdapter_.setData(zone1_, 0); - geomAdapter_.setCurv(1, 5, null); - assertEquals(5.0, geomAdapter_.getCurv(1), tolerance); - Coordinate p=((GISPolyligne)zone1_.getGeometry(0)).getCoordinateSequence().getCoordinate(1); - assertEquals(3.1013705223595296, p.x, tolerance); - assertEquals(4.998286847050588, p.y, tolerance); - } - - public void testSetZ() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - geomAdapter_.setZ(0, 20, null); - assertEquals(20, geomAdapter_.getZ(0), tolerance); - geomAdapter_.setZ(2, -2, null); - assertEquals(-2, geomAdapter_.getZ(2), tolerance); - // Cas limits - try{ - geomAdapter_.setZ(-11, -2, null); - fail(); - }catch(IllegalArgumentException _exc){} - try { - geomAdapter_.setZ(1000, -2, null); - fail(); - } - catch (IllegalArgumentException _exc){} - // Cas limits - geomAdapter_.setData(null, -1); - try { - geomAdapter_.setZ(0, 10, null); - fail(); - } - catch(IllegalArgumentException _exc){} - } - - public void testGetCurvMax() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(Math.sqrt(10*10+20*20)+Math.sqrt((50+10)*(50+10)+(10+20)*(10+20)), geomAdapter_.getCurvMax(), tolerance); - geomAdapter_.setData(null, -1); - assertEquals(0, geomAdapter_.getCurvMax(), tolerance); - } - - public void testGetCurvMin() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(0, geomAdapter_.getCurvMin(), tolerance); - geomAdapter_.setData(null, -1); - assertEquals(0, geomAdapter_.getCurvMin(), tolerance); - } - - public void testGetZMax() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(10, geomAdapter_.getZMax(), tolerance); - geomAdapter_.setData(zone1_, 0); - assertEquals(0, geomAdapter_.getZMax(), tolerance); - geomAdapter_.setZ(0, 20, null); - assertEquals(20, geomAdapter_.getZMax(), tolerance); - geomAdapter_.setZ(0, -5, null); - assertEquals(0, geomAdapter_.getZMax(), tolerance); - } - - public void testGetZMin() throws IllegalArgumentException, DataGeometryException { - geomAdapter_.setData(zone0_, 0); - assertEquals(-20, geomAdapter_.getZMin(), tolerance); - geomAdapter_.setData(zone1_, 0); - assertEquals(0, geomAdapter_.getZMin(), tolerance); - geomAdapter_.setZ(0, -20, null); - assertEquals(-20, geomAdapter_.getZMin(), tolerance); - geomAdapter_.setZ(0, 10, null); - assertEquals(0, geomAdapter_.getZMin(), tolerance); - } - - public void testSetValues() throws IllegalArgumentException, DataGeometryException { - // Test rapide reprit de setCurv ; les cas sont d\xE9j\xE0 test\xE9 dans setZ et setCurv - geomAdapter_.setData(zone5_, 14); - double[] absCurv=new double[6]; - for(int i=0;i<6;i++) - absCurv[i]=geomAdapter_.getCurv(i); - geomAdapter_.setValues(2,geomAdapter_.getCurv(2)-2, 60, null); - assertEquals(60, geomAdapter_.getZ(2), tolerance); - absCurv[2]=absCurv[2]-2; - // R\xE9instancier un nouvel adapter va verifier si il n'y a pas de nouveaux points de ruptures qui sont apparux ou qu'il y ai pas des axes qui se croisent - DataGeometryAdapter testAdapter=null; - try{ - testAdapter=new DataGeometryAdapter(zone5_, 14); - } - catch(Exception exc){ - fail(); - } - assertEquals(6, testAdapter.getNbPoint()); - // test des nouvelles abs curviligne - for(int i=0;i<6;i++) - assertEquals(absCurv[i], testAdapter.getCurv(i), tolerance); - } - - public void testRemove() throws IllegalArgumentException, DataGeometryException { - // Un cas g\xE9n\xE9ral - geomAdapter_.setData(zone0_, 0); - geomAdapter_.remove(0, null); - assertEquals(2, geomAdapter_.getNbPoint()); - assertEquals(-20, geomAdapter_.getZ(0), tolerance); - assertEquals(0, geomAdapter_.getCurv(0), tolerance); - assertEquals(Math.sqrt((50+10)*(50+10)+(10+20)*(10+20)), geomAdapter_.getCurv(1), tolerance); - // On ne peut pas descendre en dessous de 2 points - try { - geomAdapter_.remove(0, null); - fail(); - } - catch(DataGeometryException _exc){ - assertEquals(2, geomAdapter_.getNbPoint()); - } - // Cas limits - geomAdapter_.setData(null, -1); - try { - geomAdapter_.remove(0, null); - fail(); - } - catch(IllegalArgumentException _exc){} - // Un cas g\xE9n\xE9ral - geomAdapter_.setData(zone3_, 1); - geomAdapter_.remove(4, null); - geomAdapter_.remove(2, null); - geomAdapter_.remove(1, null); - assertEquals(2, geomAdapter_.getNbPoint()); - assertEquals(0, geomAdapter_.getZ(0), tolerance); - assertEquals(0, geomAdapter_.getCurv(0), tolerance); - assertEquals(-20, geomAdapter_.getZ(1), tolerance); - assertEquals(Math.sqrt((35-5)*(35-5)+5*5), geomAdapter_.getCurv(1), tolerance); - } - - public void testAddDataGeometryListener() throws DataGeometryException { - // Initialisation du test - class MyDataGeometryListener implements DataGeometryListener { - public boolean callChanged=false; - public boolean callNewGeom=false; - public void dataGeometryChanged() {callChanged=true;} - public void dataGeometryNewGeom() {callNewGeom=true;} - }; - MyDataGeometryListener listener=new MyDataGeometryListener(); - geomAdapter_.addDataGeometryListener(listener); - // Test dataGeometryNewGeom - geomAdapter_.setData(null, -1); - assertTrue(listener.callNewGeom); - listener.callNewGeom=false; - geomAdapter_.setData(zone1_, 0); - assertTrue(listener.callNewGeom); - listener.callNewGeom=false; - // Test dataGeometryChanged - geomAdapter_.setZ(0, 10, null); - assertTrue(listener.callChanged); - listener.callChanged=false; - geomAdapter_.setCurv(1, (geomAdapter_.getCurv(2)-geomAdapter_.getCurv(0))/2, null); - assertTrue(listener.callChanged); - listener.callChanged=false; - geomAdapter_.setValues(0, 0, 20, null); - assertTrue(listener.callChanged); - listener.callChanged=false; - try { - geomAdapter_.addDataGeometryListener(null); - fail(); - } - catch (IllegalArgumentException _exc){} - } - - public void testRemoveDataGeometryListener() throws DataGeometryException { - // Initialisation du test - class MyDataGeometryListener implements DataGeometryListener { - public boolean callChanged=false; - public boolean callNewGeom=false; - public void dataGeometryChanged() {callChanged=true;} - public void dataGeometryNewGeom() {callNewGeom=true;} - }; - MyDataGeometryListener listener=new MyDataGeometryListener(); - geomAdapter_.addDataGeometryListener(listener); - geomAdapter_.removeDataGeometryListener(listener); - // Test dataGeometryNewGeom - geomAdapter_.setData(null, -1); - assertFalse(listener.callNewGeom); - listener.callNewGeom=false; - geomAdapter_.setData(zone1_, 0); - assertFalse(listener.callNewGeom); - listener.callNewGeom=false; - // Test dataGeometryChanged - geomAdapter_.setZ(0, 10, null); - assertFalse(listener.callChanged); - listener.callChanged=false; - geomAdapter_.setCurv(1, (geomAdapter_.getCurv(2)-geomAdapter_.getCurv(0))/2, null); - assertFalse(listener.callChanged); - listener.callChanged=false; - geomAdapter_.setValues(0, 0, 20, null); - assertFalse(listener.callChanged); - listener.callChanged=false; - try { - geomAdapter_.removeDataGeometryListener(null); - fail(); - } - catch (IllegalArgumentException _exc){} - } -} Copied: branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestProfilContainerAdapter.java (from rev 4312, branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestDataGeometryAdapter.java) =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestProfilContainerAdapter.java (rev 0) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/fudaa/test/testModeleur1d/TestProfilContainerAdapter.java 2008-12-30 17:02:04 UTC (rev 4317) @@ -0,0 +1,776 @@ +/* + * @creation 16 d\xE9c. 2008 + * @modification $Date:$ + * @license GNU General Public License 2 + * @copyright (c)1998-2008 CETMEF 2 bd Gambetta F-60231 Compiegne + * @mail fud...@li... + */ +package testModeleur1d; + +import junit.framework.TestCase; + +import org.fudaa.ctulu.gis.GISAttributeConstants; +import org.fudaa.ctulu.gis.GISAttributeInterface; +import org.fudaa.ctulu.gis.GISGeometryFactory; +import org.fudaa.ctulu.gis.GISPolyligne; +import org.fudaa.ebli.calque.ZModeleLigneBrisee; +import org.fudaa.fudaa.modeleur.layer.MdlModel2dProfile; +import org.fudaa.fudaa.modeleur.modeleur1d.model.BiefContainerAdapter; +import org.fudaa.fudaa.modeleur.modeleur1d.model.BiefSet; +import org.fudaa.fudaa.modeleur.modeleur1d.model.ProfilContainerAdapter; +import org.fudaa.fudaa.modeleur.modeleur1d.model.ProfilContainerException; +import org.fudaa.fudaa.modeleur.modeleur1d.model.ProfilContainerListener; + +import com.vividsolutions.jts.geom.Coordinate; + +/** + * Test pour ProfilContainerAdapter. + * @author Emmanuel MARTIN + * @version $Id$ + */ +public class TestProfilContainerAdapter extends TestCase { + + /** Tolerance pour les comparaisons de doubles. */ + private double tolerance=0.000001; + private BiefContainerAdapter biefContainer; + private ProfilContainerAdapter geomAdapter_; + private MdlModel2dProfile zone0_; + private MdlModel2dProfile zone1_; + private MdlModel2dProfile zone3_; + private MdlModel2dProfile zone4_; + private MdlModel2dProfile zone5_; + private MdlModel2dProfile zone6_; + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + // Zone6_ \\ + // Attribut z non d\xE9fini + zone6_=new MdlModel2dProfile(null, null); + zone6_.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone6_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), + new Coordinate(50, 10, 10)}), null, null); + // Zone0_ \\ + // Quelconque + zone0_=new MdlModel2dProfile(null, null); + zone0_.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone0_.getGeomData().setAttributeIsZ(GISAttributeConstants.BATHY); + zone0_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), + new Coordinate(50, 10, 10)}), null, null); + // Zone1_ \\ + // Quelconque + zone1_=new MdlModel2dProfile(null, null); + zone1_.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone1_.getGeomData().setAttributeIsZ(GISAttributeConstants.BATHY); + zone1_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory() + .create( + new Coordinate[]{new Coordinate(8, 6, 0), new Coordinate(5.052590034554651, 6.559262456806686, 0), + new Coordinate(3, 2, 0)}), null, null); + // Zone3_ \\ + // Quelconque + zone3_=new MdlModel2dProfile(null, null); + zone3_.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone3_.getGeomData().setAttributeIsZ(GISAttributeConstants.BATHY); + zone3_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), new Coordinate(50, 10, 10), + new Coordinate(30, 5, 5), new Coordinate(10, 0, 0)}), null, null); + zone3_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 0, 0), new Coordinate(-15, -20, -20), new Coordinate(55, 10, 10), + new Coordinate(35, 5, -20), new Coordinate(15, 0, -20)}), null, null); + // zone4_ \\ + zone4_=new MdlModel2dProfile(null, null); + zone4_.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone4_.getGeomData().setAttributeIsZ(GISAttributeConstants.BATHY); + // 0 : Points confondus + zone4_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(-10, -20, -20), new Coordinate(-10, -20, -20), + new Coordinate(-20, -40, -40), new Coordinate(-30, -60, -60)}), null, null); + // 1 : nb ruptures > 2 + zone4_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 20, 5), new Coordinate(11, 100, 8), new Coordinate(41, 5, 9), new Coordinate(41, 0, 8)}), null, null); + // 2 : nb ruptures = 1 + zone4_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(11, 100, 8), new Coordinate(12, 101, 10), new Coordinate(13, 102, -5)}), null, null); + // 3 : nb ruptures = 0 + zone4_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 20, 5), new Coordinate(20, 40, 8)}), null, null); + // 4 : nb ruptures = 2 + zone4_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(10, 10, 0), new Coordinate(20, 10, 5), new Coordinate(20, 20, 8), new Coordinate(25, 20, 8), new Coordinate(30, 20, 8)}), null, null); + // 5 : axes crois\xE9s + zone4_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(10, 10, 0), new Coordinate(20, 10, 5), new Coordinate(20, 20, 8), new Coordinate(10, 5, 8)}), null, null); + // Zone5_ \\ + zone5_=new MdlModel2dProfile(null, null); + zone5_.getGeomData().setAttributes(new GISAttributeInterface[]{GISAttributeConstants.BATHY}, null); + zone5_.getGeomData().setAttributeIsZ(GISAttributeConstants.BATHY); + // 0 : 2 points align\xE9s (cas g\xE9n\xE9ral) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, -4)}), null, null); + // 1 : 2 points align\xE9s parall\xE8le \xE0 l'axe des X + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 10, 3), new Coordinate(20, 10, -7)}), null, null); + // 2 : 2 points align\xE9s parall\xE8le \xE0 l'axe des Y + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 0, 0), new Coordinate(5, 10, 88)}), null, null); + // 3 : 3 points align\xE9s (cas g\xE9n\xE9ral) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0)}), null, null); + // 4 : 3 points align\xE9s parall\xE8le \xE0 l'axe des X + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(-5, 10, 3), new Coordinate(20, 10, 6), new Coordinate(20.4, 10, 2)}), null, null); + // 5 : 3 points align\xE9s parall\xE8le \xE0 l'axe des Y + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(-5, 10, 8), new Coordinate(-5, -2, -2), new Coordinate(-5, -50, 50)}), null, null); + // 6 : 4 points align\xE9s (cas g\xE9n\xE9ral) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(1, 1, 0), new Coordinate(2, 1, 3), new Coordinate(8, 5, -9), new Coordinate(40, 25, 99)}), null, null); + // 7 : 4 points align\xE9s parall\xE8le \xE0 l'axe des X + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(1, 2.56, -2), new Coordinate(10, 2.56, 0), new Coordinate(99, 2.56, 84), new Coordinate(100.5, 2.56, 100)}), null, null); + // 8 : 4 points align\xE9s parall\xE8le \xE0 l'axe des Y + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(-9.1, 88, 0), new Coordinate(-9.1, 50, 8), new Coordinate(-9.1, 0, -87), new Coordinate(-9.1, -10, -10)}), null, null); + // 9 : 3 points avec un point de rupture + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9)}), null, null); + // 10 : 4 points avec un point de rupture (deux points sur le premier axe) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0), new Coordinate(50, 60, 70)}), null, null); + // 11 : 5 points avec un point de rupture (deux points sur chaque axe) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, -2), new Coordinate(11, 5, 7), new Coordinate(16.5, 7.5, 0), new Coordinate(33, 3.75, 9), new Coordinate(11, 1.25, 9)}), null, null); + // 12 : 4 points avec deux points de ruptures + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); + // 13 : 5 points avec deux points de ruptures (deux points sur le premier axe) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); + // 14 : 6 points avec deux points de ruptures (deux points sur les deux premiers axes) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -5, 9), new Coordinate(20, 0, 0)}), null, null); + // 15 : 7 points avec deux points de ruptures (deux points sur chacun des axes) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -5, 9), new Coordinate(15, -2.5, 2), new Coordinate(20, 0, 0)}), null, null); + // 16 : 10 points avec deux points de ruptures (trois points sur chacun des axes) + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(0, 0, 0), new Coordinate(2.5, 1.25, 44), new Coordinate(5, 2.5, 88), new Coordinate(10, 5, 2), new Coordinate(10, 0, 44), new Coordinate(10, -2, 0), new Coordinate(10, -5, 9), new Coordinate(10/2., -5/2., 2), new Coordinate(10/4., -5/4., 0), new Coordinate(10/8., -5/8., 0)}), null, null); + // 17 : 3 points avec un point de rupture et le premier et le dernier points sont sur le m\xEAme axe des y + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 5, -9), new Coordinate(10, 10, 0), new Coordinate(5, 20, 0)}), null, null); + // 18 : 3 points avec un point de rupture et le premier et le dernier points sont sur le m\xEAme axe des x + zone5_.getGeomData().addPolyligne(GISGeometryFactory.INSTANCE.getCoordinateSequenceFactory().create( + new Coordinate[]{new Coordinate(5, 5, -9), new Coordinate(10, 10, 0), new Coordinate(20, 5, 0)}), null, null); + + BiefSet biefSet_=new BiefSet(); + biefSet_.addBief("zone0_", new ZModeleLigneBrisee[]{zone0_}, null); + biefSet_.addBief("zone1_", new ZModeleLigneBrisee[]{zone1_}, null); + biefSet_.addBief("zone3_", new ZModeleLigneBrisee[]{zone3_}, null); + biefSet_.addBief("zone4_", new ZModeleLigneBrisee[]{zone4_}, null); + biefSet_.addBief("zone5_", new ZModeleLigneBrisee[]{zone5_}, null); + biefSet_.addBief("zone6_", new ZModeleLigneBrisee[]{zone6_}, null); + biefContainer=new BiefContainerAdapter(biefSet_); + biefContainer.setSelectedBief("zone0_"); + geomAdapter_=new ProfilContainerAdapter(biefContainer); + } + + public void testProfilContainerAdapter() throws IllegalArgumentException, ProfilContainerException { + // Points confondus + try { + biefContainer.setSelectedBief("zone4_"); + geomAdapter_.setSelectedProfil(0); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) {} + // nb points > 2 + try { + biefContainer.setSelectedBief("zone4_"); + geomAdapter_.setSelectedProfil(1); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) {} + // nb ruptures = 1 + try { + biefContainer.setSelectedBief("zone4_"); + geomAdapter_.setSelectedProfil(2); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) { + fail(); + } + // nb ruptures = 0 + try { + biefContainer.setSelectedBief("zone4_"); + geomAdapter_.setSelectedProfil(3); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) { + fail(); + } + // nb ruptures = 2 + try { + biefContainer.setSelectedBief("zone4_"); + geomAdapter_.setSelectedProfil(4); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) { + fail(); + } + // axes crois\xE9s + try { + biefContainer.setSelectedBief("zone4_"); + geomAdapter_.setSelectedProfil(5); + fail(); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) { + } + // aguments invalide + try { + geomAdapter_.setSelectedProfil(-2); + fail(); + } + catch (IllegalArgumentException _exc) { + } + catch (ProfilContainerException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_.setSelectedProfil(100); + fail(); + } + catch (IllegalArgumentException _exc) { + } + catch (ProfilContainerException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_.setSelectedProfil(zone4_.getGeomData().getNbGeometries()); + fail(); + } + catch (IllegalArgumentException _exc) { + } + catch (ProfilContainerException _exc) { + fail(); + } + // aguments invalide + try { + geomAdapter_.setSelectedProfil(zone4_.getGeomData().getNbGeometries()+1); + fail(); + } + catch (IllegalArgumentException _exc) { + } + catch (ProfilContainerException _exc) { + fail(); + } + // aguments valide + try { + biefContainer.setSelectedBief("zone3_"); + geomAdapter_.setSelectedProfil(zone3_.getGeomData().getNbGeometries()-1); + } + catch (IllegalArgumentException _exc) { + fail(); + } + catch (ProfilContainerException _exc) { + fail(); + } + } + + public void testGetGISZoneCollection() throws IllegalArgumentException, ProfilContainerException { + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(zone0_.getGeomData(), geomAdapter_.getGISZoneCollection()); + biefContainer.setSelectedBief("zone1_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(zone1_.getGeomData(), geomAdapter_.getGISZoneCollection()); + } + + public void testGetIdxGeom() throws IllegalArgumentException, ProfilContainerException { + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(0, geomAdapter_.getIdxGeom()); + biefContainer.setSelectedBief("zone3_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(0, geomAdapter_.getIdxGeom()); + biefContainer.setSelectedBief("zone3_"); + geomAdapter_.setSelectedProfil(1); + assertEquals(1, geomAdapter_.getIdxGeom()); + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(zone0_.getGeomData().getNbGeometries()-1); + assertEquals(zone0_.getGeomData().getNbGeometries()-1, geomAdapter_.getIdxGeom()); + biefContainer.setSelectedBief(null); + geomAdapter_.setSelectedProfil(-1); + assertEquals(-1, geomAdapter_.getIdxGeom()); + } + + public void testGetNbPoint() throws IllegalArgumentException, ProfilContainerException { + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(3, geomAdapter_.getNbPoint()); + biefContainer.setSelectedBief("zone1_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(3, geomAdapter_.getNbPoint()); + biefContainer.setSelectedBief("zone3_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(5, geomAdapter_.getNbPoint()); + biefContainer.setSelectedBief("zone3_"); + geomAdapter_.setSelectedProfil(1); + assertEquals(5, geomAdapter_.getNbPoint()); + biefContainer.setSelectedBief(null); + geomAdapter_.setSelectedProfil(-1); + assertEquals(0, geomAdapter_.getNbPoint()); + } + + public void testGetCurv() throws IllegalArgumentException, ProfilContainerException { + // Cas limits + biefContainer.setSelectedBief(null); + geomAdapter_.setSelectedProfil(-1); + try { + geomAdapter_.getCurv(0); + fail(); + } + catch (IllegalArgumentException _exc) {} + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + try { + geomAdapter_.getCurv(-1); + fail(); + } + catch (IllegalArgumentException _exc) {} + try { + geomAdapter_.getCurv(-5); + fail(); + } + catch (IllegalArgumentException _exc) {} + try { + geomAdapter_.getCurv(geomAdapter_.getNbPoint()); + fail(); + } + catch (IllegalArgumentException _exc) {} + // Cas g\xE9n\xE9rals + assertEquals(0, geomAdapter_.getCurv(0), tolerance); + assertEquals(Math.sqrt(10*10+20*20), geomAdapter_.getCurv(1), tolerance); + assertEquals(Math.sqrt(10*10+20*20)+Math.sqrt((50+10)*(50+10)+(10+20)*(10+20)), geomAdapter_.getCurv(2), tolerance); + } + + public void testGetZ() throws IllegalArgumentException, ProfilContainerException { + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + assertEquals(0, geomAdapter_.getZ(0), tolerance); + assertEquals(-20, geomAdapter_.getZ(1), tolerance); + assertEquals(10, geomAdapter_.getZ(2), tolerance); + biefContainer.setSelectedBief(null); + geomAdapter_.setSelectedProfil(-1); + try { + geomAdapter_.getZ(0); + fail(); + } + catch(IllegalArgumentException ex){} + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + try { + geomAdapter_.getZ(-1); + fail(); + } + catch (IllegalArgumentException _exc) { + } + biefContainer.setSelectedBief("zone0_"); + geomAdapter_.setSelectedProfil(0); + try { + geomAdapter_.getZ(100); + fail(); + } + catch (IllegalArgumentException _exc) { + } + } + + public void testSetCurv() throws Exception { + // Cas limits + biefContainer.setSelectedBief(null); + geomAdapter_.setSelectedProfil(-1); + try{ + geomAdapter_.setCurv(0, 0, null); + fail(); + } + catch(IllegalArgumentException _exc) {} + try{ + geomAdapter_.setCurv(-1, 0, null); + fail(); + } + catch(IllegalArgumentException _exc) {} + biefContainer.setSelectedBief("zone1_"); + geomAdapter_.setSelectedProfil(0); + try{ + geomAdapter_.setCurv(-1, 0, null); + fail(); + } + catch(IllegalArgumentException _exc) {} + try{ + geomAdapter_.setCurv(zone1_.getGeomData().getGeometry(0).getNumPoints(), 0, null); + fail(); + } + catch(IllegalArgumentException _exc) {} + try{ + geomAdapter_.setCurv(zone1_.getGeomData().getGeometry(0).getNumPoints()+1, 0, null); + fail(); + } + catch(IllegalArgumentException _exc) {} + // Une abcisse curviligne peut \xEAtre donn\xE9 pour le premier point, seulement pour lui + biefContainer.setSelectedBief("zone5_"); + geomAdapter_.setSelectedProfil(0); + try{ + geomAdapter_.setCurv(0, -1, null); + } + catch(Exception exc){ + fail(); + } + try{ + geomAdapter_.setCurv(1, -1, null); + fail(); + } + catch(ProfilContainerException exc){} + try{ + geomAdapter_.setCurv(geomAdapter_.getNbPoint()-1, -1, null); + fail(); + } + catch(ProfilContainerException exc){} + setUp(); + // Test sur le d\xE9placement d'un point au del\xE0 d'un autre ou au niveau d'un autre + biefContainer.setSe... [truncated message content] |