LCOV - code coverage report
Current view: top level - test - testBreakCondition.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 398 401 99.3 %
Date: 2024-04-29 14:43:01 Functions: 30 31 96.8 %

          Line data    Source code
       1             : /** Unit tests for break condition, observer, boundary and tool modules */
       2             : 
       3             : #include "crpropa/module/BreakCondition.h"
       4             : #include "crpropa/module/Observer.h"
       5             : #include "crpropa/module/Boundary.h"
       6             : #include "crpropa/module/Tools.h"
       7             : #include "crpropa/module/RestrictToRegion.h"
       8             : #include "crpropa/ParticleID.h"
       9             : #include "crpropa/Geometry.h"
      10             : 
      11             : #include "gtest/gtest.h"
      12             : 
      13             : namespace crpropa {
      14             : 
      15             : //** ========================= Break conditions ============================= */
      16           1 : TEST(MinimumEnergy, test) {
      17           1 :         MinimumEnergy minEnergy(5);
      18           1 :         Candidate c;
      19             : 
      20           1 :         c.current.setEnergy(5.1);
      21           1 :         minEnergy.process(&c);
      22           1 :         EXPECT_TRUE(c.isActive());
      23             : 
      24           1 :         c.current.setEnergy(4.9);
      25           1 :         minEnergy.process(&c);
      26           1 :         EXPECT_FALSE(c.isActive());
      27           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
      28           2 : }
      29             : 
      30           1 : TEST(MinimumChargeNumber, test) {
      31           1 :         MinimumChargeNumber minChargeNumber(20);
      32           1 :         Candidate c;
      33             : 
      34           1 :         c.current.setId(nucleusId(56, 26));
      35           1 :         minChargeNumber.process(&c);
      36           1 :         EXPECT_TRUE(c.isActive());
      37             :         
      38           1 :         c.current.setId(-nucleusId(56, 26));
      39           1 :         minChargeNumber.process(&c);
      40           1 :         EXPECT_TRUE(c.isActive());
      41             : 
      42           1 :         c.current.setId(nucleusId(4, 2));
      43           1 :         minChargeNumber.process(&c);
      44           1 :         EXPECT_FALSE(c.isActive());
      45           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
      46             :         
      47           1 :         c.setActive(true);
      48           1 :         c.removeProperty("Rejected");
      49             : 
      50           1 :         c.current.setId(-nucleusId(4, 2));
      51           1 :         minChargeNumber.process(&c);
      52           1 :         EXPECT_FALSE(c.isActive());
      53           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
      54           2 : }
      55             : 
      56           1 : TEST(MinimumEnergyPerParticleId, test) {
      57           1 :         MinimumEnergyPerParticleId minEnergy(1);
      58           1 :         minEnergy.add(22, 10);
      59           1 :         minEnergy.add(12, 2);
      60           1 :         minEnergy.add(11, 20);
      61             : 
      62           1 :         Candidate c;
      63             : 
      64           1 :         c.current.setEnergy(20);
      65           1 :         c.current.setId(22);
      66           1 :         minEnergy.process(&c);
      67           1 :         EXPECT_TRUE(c.isActive());
      68             : 
      69           1 :         c.current.setEnergy(5);
      70           1 :         c.current.setId(22);
      71           1 :         minEnergy.process(&c);
      72           1 :         EXPECT_FALSE(c.isActive());
      73           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
      74             : 
      75           1 :         c.setActive(true);
      76           1 :         c.removeProperty("Rejected");
      77             : 
      78           1 :         c.current.setEnergy(10);
      79           1 :         c.current.setId(11);
      80           1 :         minEnergy.process(&c);
      81           1 :         EXPECT_FALSE(c.isActive());
      82           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
      83             : 
      84           1 :         c.setActive(true);
      85           1 :         c.removeProperty("Rejected");
      86             : 
      87           1 :         c.current.setEnergy(5);
      88           1 :         c.current.setId(12);
      89           1 :         minEnergy.process(&c);
      90           1 :         EXPECT_TRUE(c.isActive());      
      91             : 
      92           1 :         c.current.setEnergy(0.1);
      93           1 :         c.current.setId(12);
      94           1 :         minEnergy.process(&c);
      95           1 :         EXPECT_FALSE(c.isActive());
      96           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
      97           1 : }
      98             : 
      99           1 : TEST(MaximumTrajectoryLength, test) {
     100           1 :         MaximumTrajectoryLength maxLength(10);
     101           1 :         Candidate c;
     102             : 
     103           1 :         c.setTrajectoryLength(9.9);
     104           1 :         maxLength.process(&c);
     105           1 :         EXPECT_TRUE(c.isActive());
     106             : 
     107           1 :         c.setTrajectoryLength(10.1);
     108           1 :         maxLength.process(&c);
     109           1 :         EXPECT_FALSE(c.isActive());
     110           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
     111           1 : }
     112             : 
     113           1 : TEST(MaximumTrajectoryLength, observer) {
     114           1 :         MaximumTrajectoryLength maxLength(12);
     115           1 :         maxLength.addObserverPosition(Vector3d(10, 0, 0));
     116           1 :         Candidate c;
     117           1 :         c.current.setPosition(Vector3d(5, 0, 0));
     118             : 
     119           1 :         c.setTrajectoryLength(5);
     120           1 :         maxLength.process(&c);
     121           1 :         EXPECT_TRUE(c.isActive());
     122             : 
     123           1 :         c.setTrajectoryLength(8);
     124           1 :         maxLength.process(&c);
     125           1 :         EXPECT_FALSE(c.isActive());
     126           1 : }
     127             : 
     128           1 : TEST(MinimumRedshift, test) {
     129           1 :         MinimumRedshift minZ; // default minimum redshift of 0
     130           1 :         Candidate c;
     131             : 
     132           1 :         c.setRedshift(0.1);
     133           1 :         minZ.process(&c);
     134           1 :         EXPECT_TRUE(c.isActive());
     135             : 
     136           1 :         c.setRedshift(0);
     137           1 :         minZ.process(&c);
     138           1 :         EXPECT_FALSE(c.isActive());
     139           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
     140           2 : }
     141             : 
     142           1 : TEST(DetectionLength, test) {
     143           1 :         DetectionLength detL(10);
     144           1 :         detL.setMakeRejectedInactive(false);
     145           1 :         Candidate c;
     146           1 :         c.current.setPosition(Vector3d(5,0,0));
     147             : 
     148           1 :         c.setTrajectoryLength(2);
     149           1 :         detL.process(&c);
     150           1 :         EXPECT_TRUE(c.isActive());
     151             :         
     152           1 :         c.setCurrentStep(10);
     153           1 :         c.setTrajectoryLength(12);
     154           1 :         detL.process(&c);
     155           1 :         EXPECT_TRUE(c.isActive());
     156           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
     157           2 : }
     158             : 
     159             : //** ============================= Observers ================================ */
     160           1 : TEST(ObserverFeature, SmallSphere) {
     161             :         // detect if the current position is inside and the previous outside of the sphere
     162           1 :         Observer obs;
     163           1 :         obs.add(new ObserverSurface(new Sphere (Vector3d(0, 0, 0), 1)));
     164           1 :         Candidate c;
     165           1 :         c.setNextStep(10);
     166             : 
     167             :         // no detection: particle was inside already
     168           1 :         c.current.setPosition(Vector3d(0.9, 0, 0));
     169           1 :         c.previous.setPosition(Vector3d(0.95, 0, 0));
     170           1 :         obs.process(&c);
     171           1 :         EXPECT_TRUE(c.isActive());
     172             : 
     173             :         // limit step
     174           1 :         EXPECT_NEAR(c.getNextStep(), 0.1, 0.001);
     175             : 
     176             :         // detection: particle just entered
     177           1 :         c.current.setPosition(Vector3d(0.9, 0, 0));
     178           1 :         c.previous.setPosition(Vector3d(1.1, 0, 0));
     179           1 :         obs.process(&c);
     180           1 :         EXPECT_FALSE(c.isActive());
     181           1 : }
     182             : 
     183           1 : TEST(ObserverFeature, LargeSphere) {
     184             :         // detect if the current position is outside and the previous inside of the sphere
     185           1 :         Observer obs;
     186           1 :         obs.add(new ObserverSurface(new Sphere (Vector3d(0, 0, 0), 10)));
     187           1 :         Candidate c;
     188           1 :         c.setNextStep(10);
     189             : 
     190             :         // no detection: particle was outside already
     191           1 :         c.current.setPosition(Vector3d(11, 0, 0));
     192           1 :         c.previous.setPosition(Vector3d(10.5, 0, 0));
     193           1 :         obs.process(&c);
     194           1 :         EXPECT_TRUE(c.isActive());
     195             : 
     196             :         // limit step
     197           1 :         EXPECT_DOUBLE_EQ(c.getNextStep(), 1);
     198             : 
     199             :         // detection: particle just left
     200           1 :         c.current.setPosition(Vector3d(11, 0, 0));
     201           1 :         c.previous.setPosition(Vector3d(9.5, 0, 0));
     202           1 :         obs.process(&c);
     203           1 :         EXPECT_FALSE(c.isActive());
     204           1 : }
     205             : 
     206           1 : TEST(ObserverFeature, Point) {
     207           1 :         Observer obs;
     208           1 :         obs.add(new Observer1D());
     209           1 :         Candidate c;
     210           1 :         c.setNextStep(10);
     211             : 
     212             :         // no detection, limit step
     213           1 :         c.current.setPosition(Vector3d(5, 0, 0));
     214           1 :         obs.process(&c);
     215           1 :         EXPECT_TRUE(c.isActive());
     216             : 
     217             :         // limit step
     218           1 :         EXPECT_DOUBLE_EQ(5, c.getNextStep());
     219             : 
     220             :         // detection
     221           1 :         c.current.setPosition(Vector3d(0, 0, 0));
     222           1 :         obs.process(&c);
     223           1 :         EXPECT_FALSE(c.isActive());
     224           1 : }
     225             : 
     226           1 : TEST(ObserverFeature, DetectAll) {
     227             :         // DetectAll should detect all candidates
     228           1 :         Observer obs;
     229           1 :         obs.add(new ObserverDetectAll());
     230           1 :         Candidate c;
     231           1 :         obs.process(&c);
     232           1 :         EXPECT_FALSE(c.isActive());
     233           1 : }
     234             : 
     235           1 : TEST(ObserverFeature, TimeEvolution) {
     236           1 :   Observer obs;
     237           1 :   obs.setDeactivateOnDetection(false);
     238           2 :   obs.setFlag("Detected", "Detected");
     239           1 :   obs.add(new ObserverTimeEvolution(5, 5, 2));
     240           1 :   Candidate c;
     241           1 :   c.setNextStep(10);
     242           1 :   c.setTrajectoryLength(3);
     243             :   
     244             :   // no detection, limit next step
     245           1 :   obs.process(&c);
     246           1 :   EXPECT_TRUE(c.isActive());
     247             : 
     248             :   // limit step
     249           1 :   EXPECT_DOUBLE_EQ(2, c.getNextStep());
     250             :   
     251             :   // detection one
     252           1 :   c.setCurrentStep(0.1);
     253           1 :   c.setTrajectoryLength(5);
     254           1 :   obs.process(&c);
     255           1 :   EXPECT_TRUE(c.isActive());
     256           2 :   EXPECT_TRUE(c.hasProperty("Detected"));
     257             : 
     258             :   // delete property
     259           1 :   c.removeProperty("Detected");
     260           1 :   EXPECT_FALSE(c.hasProperty("Detected"));
     261             : 
     262             :   // detection two
     263           1 :   c.setCurrentStep(0.1);
     264           1 :   c.setTrajectoryLength(10.05);
     265           1 :   obs.process(&c);
     266           1 :   EXPECT_TRUE(c.isActive());
     267           2 :   EXPECT_TRUE(c.hasProperty("Detected"));
     268           1 : }
     269             : 
     270           1 : TEST(ObserverFeature, TimeEvolutionLog) {
     271           1 :   Observer obs;
     272           1 :   obs.setDeactivateOnDetection(false);
     273           2 :   obs.setFlag("Detected", "Detected");
     274             :   // usage of a log scaling for the observer
     275             :   bool log = true;
     276           1 :   obs.add(new ObserverTimeEvolution(5, 5, 2, log));
     277           1 :   Candidate c;
     278           1 :   c.setNextStep(10);
     279           1 :   c.setTrajectoryLength(3);
     280             :   
     281             :   // no detection, limit next step
     282           1 :   obs.process(&c);
     283           1 :   EXPECT_TRUE(c.isActive());
     284             : 
     285             :   // limit step
     286           1 :   EXPECT_DOUBLE_EQ(2, c.getNextStep());
     287             :   
     288             :   // detection one
     289           1 :   c.setCurrentStep(0.1);
     290           1 :   c.setTrajectoryLength(5);
     291           1 :   obs.process(&c);
     292           1 :   EXPECT_TRUE(c.isActive());
     293           2 :   EXPECT_TRUE(c.hasProperty("Detected"));
     294             : 
     295             :   // delete property
     296           1 :   c.removeProperty("Detected");
     297           1 :   EXPECT_FALSE(c.hasProperty("Detected"));
     298             : 
     299             :   // detection two
     300           1 :   c.setCurrentStep(0.1);
     301           1 :   c.setTrajectoryLength(10.05);
     302           1 :   obs.process(&c);
     303           1 :   EXPECT_TRUE(c.isActive());
     304           2 :   EXPECT_TRUE(c.hasProperty("Detected"));
     305           1 : }
     306             : 
     307             : //** ========================= Boundaries =================================== */
     308           2 : TEST(PeriodicBox, high) {
     309             :         // Tests if the periodical boundaries place the particle back inside the box and translate the initial position accordingly.
     310             :         Vector3d origin(2, 2, 2);
     311             :         Vector3d size(2, 2, 2);
     312           1 :         PeriodicBox box(origin, size);
     313             : 
     314           1 :         Candidate c;
     315           1 :         c.current.setPosition(Vector3d(4.5, 4.3, 4.4));
     316           1 :         c.created.setPosition(Vector3d(3, 3, 3));
     317             : 
     318           1 :         box.process(&c);
     319             : 
     320           1 :         EXPECT_DOUBLE_EQ(2.5, c.current.getPosition().x);
     321           1 :         EXPECT_DOUBLE_EQ(1, c.created.getPosition().x);
     322           1 :         EXPECT_DOUBLE_EQ(2.3, c.current.getPosition().y);
     323           1 :         EXPECT_DOUBLE_EQ(1, c.created.getPosition().y);
     324           1 :         EXPECT_DOUBLE_EQ(2.4, c.current.getPosition().z);
     325           1 :         EXPECT_DOUBLE_EQ(1, c.created.getPosition().z);
     326           2 : }
     327             : 
     328           2 : TEST(PeriodicBox, low) {
     329             :         // Tests if the periodical boundaries place the particle back inside the box and translate the initial position accordingly.
     330             :         Vector3d origin(0, 0, 0);
     331             :         Vector3d size(2, 2, 2);
     332           1 :         PeriodicBox box(origin, size);
     333             : 
     334           1 :         Candidate c;
     335           1 :         c.current.setPosition(Vector3d(-2.5, -0.3, -0.4));
     336           1 :         c.created.setPosition(Vector3d(1, 1, 1));
     337             : 
     338           1 :         box.process(&c);
     339             : 
     340           1 :         EXPECT_DOUBLE_EQ(1.5, c.current.getPosition().x);
     341           1 :         EXPECT_DOUBLE_EQ(5, c.created.getPosition().x);
     342           1 :         EXPECT_DOUBLE_EQ(1.7, c.current.getPosition().y);
     343           1 :         EXPECT_DOUBLE_EQ(3, c.created.getPosition().y);
     344           1 :         EXPECT_DOUBLE_EQ(1.6, c.current.getPosition().z);
     345           1 :         EXPECT_DOUBLE_EQ(3, c.created.getPosition().z);
     346           2 : }
     347             : 
     348           2 : TEST(ReflectiveBox, high) {
     349             :         // Tests if the reflective boundaries place the particle back inside the box and translate the initial position accordingly.
     350             :         // Also the initial and final directions are to be reflected
     351             :         Vector3d origin(10, 10, 10);
     352             :         Vector3d size(10, 20, 20);
     353           1 :         ReflectiveBox box(origin, size);
     354             : 
     355           1 :         Candidate c;
     356           1 :         c.source.setPosition(Vector3d(16, 17, 18));
     357           1 :         c.source.setDirection(Vector3d(1, 1.6, 1.8));
     358           1 :         c.created.setPosition(Vector3d(15, 15, 15));
     359           1 :         c.created.setDirection(Vector3d(0, 0.6, 0.8));
     360           1 :         c.previous.setPosition(Vector3d(15, 15, 29.5));
     361           1 :         c.previous.setDirection(Vector3d(0, 0.6, 0.8));
     362           1 :         c.current.setPosition(Vector3d(15, 15, 30.5));
     363           1 :         c.current.setDirection(Vector3d(0, 0.6, 0.8));
     364             : 
     365           1 :         box.process(&c);
     366             : 
     367           1 :         EXPECT_DOUBLE_EQ(16, c.source.getPosition().x);
     368           1 :         EXPECT_DOUBLE_EQ(17, c.source.getPosition().y);
     369           1 :         EXPECT_DOUBLE_EQ(42, c.source.getPosition().z);
     370             : 
     371           1 :         EXPECT_DOUBLE_EQ(15, c.created.getPosition().x);
     372           1 :         EXPECT_DOUBLE_EQ(15, c.created.getPosition().y);
     373           1 :         EXPECT_DOUBLE_EQ(45, c.created.getPosition().z);
     374             : 
     375           1 :         EXPECT_DOUBLE_EQ(15, c.previous.getPosition().x);
     376           1 :         EXPECT_DOUBLE_EQ(15, c.previous.getPosition().y);
     377           1 :         EXPECT_DOUBLE_EQ(30.5, c.previous.getPosition().z);
     378             : 
     379           1 :         EXPECT_DOUBLE_EQ(15, c.current.getPosition().x);
     380           1 :         EXPECT_DOUBLE_EQ(15, c.current.getPosition().y);
     381           1 :         EXPECT_DOUBLE_EQ(29.5, c.current.getPosition().z);
     382             : 
     383           1 :         EXPECT_DOUBLE_EQ(0, c.created.getDirection().x);
     384           1 :         EXPECT_DOUBLE_EQ(0.6, c.created.getDirection().y);
     385           1 :         EXPECT_DOUBLE_EQ(-0.8, c.created.getDirection().z);
     386             : 
     387           1 :         EXPECT_DOUBLE_EQ(0, c.previous.getDirection().x);
     388           1 :         EXPECT_DOUBLE_EQ(0.6, c.previous.getDirection().y);
     389           1 :         EXPECT_DOUBLE_EQ(-0.8, c.previous.getDirection().z);
     390             : 
     391           1 :         EXPECT_DOUBLE_EQ(0, c.current.getDirection().x);
     392           1 :         EXPECT_DOUBLE_EQ(0.6, c.current.getDirection().y);
     393           1 :         EXPECT_DOUBLE_EQ(-0.8, c.current.getDirection().z);
     394           2 : }
     395             : 
     396           2 : TEST(CubicBoundary, inside) {
     397           1 :         CubicBoundary cube(Vector3d(0, 0, 0), 10);
     398           1 :         Candidate c;
     399           1 :         c.current.setPosition(Vector3d(9, 5, 5));
     400           1 :         cube.process(&c);
     401           1 :         EXPECT_TRUE(c.isActive());
     402           2 : }
     403             : 
     404           2 : TEST(CubicBoundary, outside) {
     405           1 :         CubicBoundary cube(Vector3d(0, 0, 0), 10);
     406           1 :         Candidate c;
     407           1 :         c.current.setPosition(Vector3d(10.1, 5, 5));
     408           1 :         cube.process(&c);
     409           1 :         EXPECT_FALSE(c.isActive());
     410           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
     411           2 : }
     412             : 
     413           2 : TEST(CubicBoundary, limitStepLower) {
     414           1 :         CubicBoundary cube(Vector3d(10, 10, 10), 10);
     415           1 :         cube.setLimitStep(true);
     416           1 :         cube.setMargin(1);
     417           1 :         Candidate c;
     418           1 :         c.current.setPosition(Vector3d(15, 15, 10.5));
     419           1 :         c.setNextStep(100);
     420           1 :         cube.process(&c);
     421           1 :         EXPECT_DOUBLE_EQ(1.5, c.getNextStep());
     422           2 : }
     423             : 
     424           2 : TEST(CubicBoundary, limitStepUpper) {
     425           1 :         CubicBoundary cube(Vector3d(-10, -10, -10), 10);
     426           1 :         cube.setLimitStep(true);
     427           1 :         cube.setMargin(1);
     428           1 :         Candidate c;
     429           1 :         c.current.setPosition(Vector3d(-5, -5, -0.5));
     430           1 :         c.setNextStep(100);
     431           1 :         cube.process(&c);
     432           1 :         EXPECT_DOUBLE_EQ(1.5, c.getNextStep());
     433           2 : }
     434             : 
     435           2 : TEST(SphericalBoundary, inside) {
     436           1 :         SphericalBoundary sphere(Vector3d(0, 0, 0), 10);
     437           1 :         Candidate c;
     438           1 :         c.current.setPosition(Vector3d(9, 0, 0));
     439           1 :         sphere.process(&c);
     440           1 :         EXPECT_TRUE(c.isActive());
     441           1 :         EXPECT_FALSE(c.hasProperty("Rejected"));
     442           2 : }
     443             : 
     444           2 : TEST(SphericalBoundary, outside) {
     445           1 :         SphericalBoundary sphere(Vector3d(0, 0, 0), 10);
     446           2 :         sphere.setRejectFlag("I passed the galactic border", "Nothing happened");
     447           1 :         Candidate c;
     448           1 :         c.current.setPosition(Vector3d(0, -10.1, 0));
     449           1 :         sphere.process(&c);
     450           1 :         EXPECT_FALSE(c.isActive());
     451           2 :         EXPECT_TRUE(c.hasProperty("I passed the galactic border"));
     452           2 : }
     453             : 
     454           2 : TEST(SphericalBoundary, limitStep) {
     455           1 :         SphericalBoundary sphere(Vector3d(0, 0, 0), 10);
     456           1 :         sphere.setLimitStep(true);
     457           1 :         sphere.setMargin(1);
     458           1 :         Candidate c;
     459           1 :         c.setNextStep(100);
     460           1 :         c.current.setPosition(Vector3d(0, 0, 9.5));
     461           1 :         sphere.process(&c);
     462           1 :         EXPECT_DOUBLE_EQ(1.5, c.getNextStep());
     463           2 : }
     464             : 
     465           2 : TEST(EllipsoidalBoundary, inside) {
     466           1 :         EllipsoidalBoundary ellipsoid(Vector3d(-5, 0, 0), Vector3d(5, 0, 0), 15);
     467           1 :         Candidate c;
     468           1 :         c.current.setPosition(Vector3d(3, 2, 0));
     469           1 :         ellipsoid.process(&c);
     470           1 :         EXPECT_TRUE(c.isActive());
     471           1 :         EXPECT_FALSE(c.hasProperty("Rejected"));
     472           2 : }
     473             : 
     474           2 : TEST(EllipsoidalBoundary, outside) {
     475           1 :         EllipsoidalBoundary ellipsoid(Vector3d(-5, 0, 0), Vector3d(5, 0, 0), 15);
     476           1 :         Candidate c;
     477           1 :         c.current.setPosition(Vector3d(0, 25, 0));
     478           1 :         ellipsoid.process(&c);
     479           1 :         EXPECT_FALSE(c.isActive());
     480           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
     481           2 : }
     482             : 
     483           2 : TEST(EllipsoidalBoundary, limitStep) {
     484           1 :         EllipsoidalBoundary ellipsoid(Vector3d(-5, 0, 0), Vector3d(5, 0, 0), 15);
     485           1 :         ellipsoid.setLimitStep(true);
     486           1 :         ellipsoid.setMargin(0.5);
     487           1 :         Candidate c;
     488           1 :         c.setNextStep(2);
     489           1 :         c.current.setPosition(Vector3d(7, 0, 0));
     490           1 :         ellipsoid.process(&c);
     491           1 :         EXPECT_DOUBLE_EQ(c.getNextStep(), 1.5);
     492           2 : }
     493             : 
     494           2 : TEST(CylindricalBoundary, inside) {
     495           1 :         CylindricalBoundary cylinder(Vector3d(0, 0, 0), 2, 15);
     496           1 :         Candidate c;
     497           1 :         c.current.setPosition(Vector3d(6, -3, 0.5));
     498           1 :         cylinder.process(&c);
     499           1 :         EXPECT_TRUE(c.isActive());
     500           1 :         EXPECT_FALSE(c.hasProperty("Rejected"));
     501           2 : }
     502             : 
     503           2 : TEST(CylindricalBoundary, outside) {
     504           1 :         CylindricalBoundary cylinder(Vector3d(0, 0, 0), 2, 15);
     505           1 :         Candidate c;
     506           1 :         c.current.setPosition(Vector3d(6, -3, 1.5));
     507           1 :         cylinder.process(&c);
     508           1 :         EXPECT_FALSE(c.isActive());
     509           2 :         EXPECT_TRUE(c.hasProperty("Rejected"));
     510           2 : }
     511             : 
     512           2 : TEST(CylindricalBoundary, limitStep) {
     513           1 :         CylindricalBoundary cylinder(Vector3d(0, 0, 0), 2, 15);
     514           1 :         cylinder.setLimitStep(true);
     515           1 :         cylinder.setMargin(0.5);
     516           1 :         Candidate c;
     517           1 :         c.setNextStep(2);
     518           1 :         c.current.setPosition(Vector3d(7, 0, 0));
     519           1 :         cylinder.process(&c);
     520           1 :         EXPECT_DOUBLE_EQ(c.getNextStep(), 1.5);
     521           2 : }
     522             : 
     523           1 : TEST(RestrictToRegion, RestrictToRegion) {
     524             : 
     525           1 :         ref_ptr<Observer> obs = new Observer();
     526           1 :         obs->add(new ObserverDetectAll());
     527           1 :         RestrictToRegion R(obs, new Sphere(Vector3d(0, 0, 0), 10));
     528             : 
     529           1 :         Candidate c;
     530           1 :         c.previous.setPosition(Vector3d(13,0,0));
     531           1 :         c.current.setPosition(Vector3d(12,0,0));
     532           1 :         R.process(&c);
     533           1 :         EXPECT_TRUE(c.isActive());
     534           1 :         c.current.setPosition(Vector3d(9,0,0));
     535           1 :         R.process(&c);
     536           1 :         EXPECT_FALSE(c.isActive());
     537           2 : }
     538             : 
     539             : 
     540           0 : int main(int argc, char **argv) {
     541           0 :         ::testing::InitGoogleTest(&argc, argv);
     542           0 :         return RUN_ALL_TESTS();
     543             : }
     544             : 
     545             : } // namespace crpropa

Generated by: LCOV version 1.14