LCOV - code coverage report
Current view: top level - unittest/src/microsim - MSCFModelTest.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 45 45
Test Date: 2024-11-21 15:56:26 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MSCFModelTest.cpp
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Michael Behrisch
      17              : /// @date    2013-06-05
      18              : ///
      19              : // Tests the cfmodel functions
      20              : /****************************************************************************/
      21              : 
      22              : // ===========================================================================
      23              : // included modules
      24              : // ===========================================================================
      25              : #include <config.h>
      26              : 
      27              : #include <gtest/gtest.h>
      28              : #include <utils/vehicle/SUMOVTypeParameter.h>
      29              : #include <microsim/MSGlobals.h>
      30              : #include <microsim/MSVehicleType.h>
      31              : #include <microsim/cfmodels/MSCFModel.h>
      32              : #include <microsim/cfmodels/MSCFModel_Krauss.h>
      33              : 
      34              : 
      35            4 : class MSCFModelTest : public testing::Test {
      36              : protected :
      37              :     MSVehicleType* type;
      38              :     MSCFModel* m;
      39              :     double accel;
      40              :     double decel;
      41              :     double dawdle;
      42              :     double tau; // headway time
      43              : 
      44            4 :     virtual void SetUp() {
      45            4 :         accel = 2;
      46            4 :         decel = 4;
      47            4 :         dawdle = 0;
      48            4 :         tau = 1;
      49            4 :         type = new MSVehicleType(SUMOVTypeParameter("0"));
      50            4 :         m = new MSCFModel_Krauss(type);
      51            4 :     }
      52              : 
      53            4 :     virtual void TearDown() {
      54            4 :         delete m;
      55            4 :         delete type;
      56            4 :     }
      57              : };
      58              : 
      59              : /* Test the method 'brakeGap'.*/
      60              : 
      61            1 : TEST_F(MSCFModelTest, test_method_brakeGap) {
      62              :     // discrete braking model. keep driving for 1 s
      63              :     const double v = 3;
      64            1 :     EXPECT_DOUBLE_EQ(tau * v, m->brakeGap(v));
      65            1 : }
      66              : 
      67            1 : TEST_F(MSCFModelTest, test_method_static_brakeGap) {
      68              :     const double v = 3;
      69              :     const double b = 4;
      70              :     const double t = 1; // tau
      71            1 :     EXPECT_DOUBLE_EQ(3, m->brakeGap(v, b, t));
      72            1 :     EXPECT_DOUBLE_EQ(0, m->brakeGap(v, b, 0));
      73            1 :     EXPECT_DOUBLE_EQ(3, m->brakeGap(7, b, 0));
      74            1 :     EXPECT_DOUBLE_EQ(28.6, m->brakeGap(18.4, 4.5, 0));
      75            1 :     EXPECT_DOUBLE_EQ(47., m->brakeGap(22.9, 4.5, 0));
      76            1 :     EXPECT_DOUBLE_EQ(44., m->brakeGap(22.25, 4.5, 0));
      77            1 : }
      78              : 
      79            1 : TEST_F(MSCFModelTest, test_method_static_freeSpeed) {
      80              :     const double vCur = 10;
      81              :     const double b = 4;
      82              :     const double v = 0;
      83              :     const double g = 4;
      84            1 :     EXPECT_DOUBLE_EQ(4, MSCFModel::freeSpeed(vCur, b, g, v, false, 1.0));
      85            1 :     EXPECT_DOUBLE_EQ(8, MSCFModel::freeSpeed(vCur, b, g, v, true, 1.0));
      86            1 :     EXPECT_DOUBLE_EQ(17.5, MSCFModel::freeSpeed(vCur, 5, 30, 10, false, 1.0));
      87            1 :     EXPECT_DOUBLE_EQ(18.4, MSCFModel::freeSpeed(vCur, 4.5, 20, 13.9, false, 1.0));
      88            1 :     EXPECT_DOUBLE_EQ(18.4, MSCFModel::freeSpeed(vCur, 4.5, 30, 13.9, false, 1.0));
      89            1 :     EXPECT_DOUBLE_EQ(22.9, MSCFModel::freeSpeed(vCur, 4.5, 30, 13.9, true, 1.0));
      90            1 :     EXPECT_DOUBLE_EQ(22.25, MSCFModel::freeSpeed(vCur, 4.5, 40, 13.9, false, 1.0));
      91            1 : }
      92              : 
      93              : 
      94            1 : TEST_F(MSCFModelTest, test_method_static_freeSpeed_half) {
      95            1 :     DELTA_T = 500;
      96              :     const double vCur = 10;
      97              :     const double b = 4;
      98              :     const double v = 0;
      99              :     const double g = 4;
     100            1 :     EXPECT_DOUBLE_EQ(14. / 3., MSCFModel::freeSpeed(vCur, b, g, v, false, TS));
     101            1 :     EXPECT_DOUBLE_EQ(6., MSCFModel::freeSpeed(vCur, b, 6, v, false, TS));
     102            1 :     EXPECT_DOUBLE_EQ(18.75, MSCFModel::freeSpeed(vCur, 5, 30, 10, false, TS));
     103            1 :     EXPECT_DOUBLE_EQ(18.4, MSCFModel::freeSpeed(vCur, 4.5, 20, 13.9, false, TS));
     104            1 :     EXPECT_DOUBLE_EQ(20.65, MSCFModel::freeSpeed(vCur, 4.5, 20, 13.9, true, TS));
     105            1 :     EXPECT_DOUBLE_EQ(20.65, MSCFModel::freeSpeed(vCur, 4.5, 30, 13.9, false, TS));
     106            1 :     EXPECT_DOUBLE_EQ(22.9, MSCFModel::freeSpeed(vCur, 4.5, 30, 13.9, true, TS));
     107            1 :     EXPECT_DOUBLE_EQ(22.9, MSCFModel::freeSpeed(vCur, 4.5, 40, 13.9, false, TS));
     108            1 :     DELTA_T = 1000;
     109            1 : }
        

Generated by: LCOV version 2.0-1