LCOV - code coverage report
Current view: top level - unittest/src/utils/common - ValueTimeLineTest.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 126 126
Test Date: 2024-10-24 15:46:30 Functions: 100.0 % 10 10

            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    ValueTimeLineTest.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Matthias Heppner
      17              : /// @author  Michael Behrisch
      18              : /// @date    Sept 2009
      19              : ///
      20              : // Tests ValueTimeLine class from <SUMO>/src/utils/common
      21              : /****************************************************************************/
      22              : 
      23              : 
      24              : // ===========================================================================
      25              : // included modules
      26              : // ===========================================================================
      27              : #include <config.h>
      28              : 
      29              : #include <gtest/gtest.h>
      30              : #include <utils/common/ValueTimeLine.h>
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // test definitions
      35              : // ===========================================================================
      36              : /* Tests what happens if one tries to get a value from an empty ValueTimeLine. */
      37              : /*
      38              : TEST(ValueTimeLine, test_get_from_empty) {
      39              :     ValueTimeLine<int> vtl;
      40              :     EXPECT_EQ(1, vtl.getValue(0)) << "Something should happen if nothing was stored.";
      41              : }
      42              : */
      43              : 
      44              : 
      45              : // --------------------------------
      46              : // plain retrieval / overwriting tests
      47              : // --------------------------------
      48              : 
      49              : /* Tests what happens if one tries to get a stored value (one value stored, fillGaps not called). */
      50            2 : TEST(ValueTimeLine, test_get_single_nocollect) {
      51              :     ValueTimeLine<int> vtl;
      52            1 :     vtl.add(0, 100, 2);
      53            1 :     EXPECT_EQ(2, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
      54            1 :     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
      55            1 :     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
      56            1 : }
      57              : 
      58              : /* Tests what happens if one tries to get a stored value (three values stored, fillGaps not called). */
      59            2 : TEST(ValueTimeLine, test_get_multi_nocollect) {
      60              :     ValueTimeLine<int> vtl;
      61            1 :     vtl.add(0, 100, 1);
      62            1 :     vtl.add(100, 200, 2);
      63            1 :     vtl.add(200, 300, 3);
      64            1 :     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
      65            1 :     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
      66            1 :     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
      67            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
      68            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
      69            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
      70            1 :     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
      71            1 :     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
      72            1 :     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
      73            1 : }
      74              : 
      75              : /* Tests what happens if one tries to get a stored value (one value stored, fillGaps called). */
      76            2 : TEST(ValueTimeLine, test_get_single_collect) {
      77              :     ValueTimeLine<int> vtl;
      78            1 :     vtl.add(0, 100, 2);
      79            1 :     vtl.fillGaps(0);
      80            1 :     EXPECT_EQ(2, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
      81            1 :     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
      82            1 :     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
      83            1 : }
      84              : 
      85              : /* Tests what happens if one tries to get a stored value (three values stored, fillGaps called). */
      86            2 : TEST(ValueTimeLine, test_get_multi_collect) {
      87              :     ValueTimeLine<int> vtl;
      88            1 :     vtl.add(0, 100, 1);
      89            1 :     vtl.add(100, 200, 2);
      90            1 :     vtl.add(200, 300, 3);
      91            1 :     vtl.fillGaps(0);
      92            1 :     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
      93            1 :     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
      94            1 :     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
      95            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
      96            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
      97            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
      98            1 :     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
      99            1 :     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     100            1 :     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     101            1 : }
     102              : 
     103              : // --------------------------------
     104              : // overwriting filling tests
     105              : // --------------------------------
     106              : 
     107              : /* Tests what happens if one overwrites a value (three values stored, fillGaps not called). */
     108            2 : TEST(ValueTimeLine, test_overwrite_nocollect) {
     109              :     ValueTimeLine<int> vtl;
     110            1 :     vtl.add(0, 100, 1);
     111            1 :     vtl.add(200, 300, 3);
     112            1 :     vtl.add(50, 250, 2);
     113            1 :     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
     114            1 :     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
     115            1 :     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
     116            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
     117            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
     118            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
     119            1 :     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
     120            1 :     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     121            1 :     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     122            1 : }
     123              : 
     124              : /* Tests what happens if one overwrites a value (three values stored, fillGaps called). */
     125            2 : TEST(ValueTimeLine, test_overwrite_collect) {
     126              :     ValueTimeLine<int> vtl;
     127            1 :     vtl.add(0, 100, 1);
     128            1 :     vtl.add(200, 300, 3);
     129            1 :     vtl.add(50, 250, 2);
     130            1 :     vtl.fillGaps(0);
     131            1 :     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
     132            1 :     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
     133            1 :     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
     134            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
     135            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
     136            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
     137            1 :     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
     138            1 :     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     139            1 :     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     140            1 : }
     141              : 
     142              : /* Tests what happens if one overwrites a value (three values stored, fillGaps not called, order changed). */
     143            2 : TEST(ValueTimeLine, test_overwrite_nocollect2) {
     144              :     ValueTimeLine<int> vtl;
     145            1 :     vtl.add(50, 250, 2);
     146            1 :     vtl.add(0, 100, 1);
     147            1 :     vtl.add(200, 300, 3);
     148            1 :     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
     149            1 :     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
     150            1 :     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
     151            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
     152            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
     153            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
     154            1 :     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
     155            1 :     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     156            1 :     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     157            1 : }
     158              : 
     159              : /* Tests what happens if one overwrites a value (three values stored, fillGaps called, order changed). */
     160            2 : TEST(ValueTimeLine, test_overwrite_collect2) {
     161              :     ValueTimeLine<int> vtl;
     162            1 :     vtl.add(50, 250, 2);
     163            1 :     vtl.add(0, 100, 1);
     164            1 :     vtl.add(200, 300, 3);
     165            1 :     vtl.fillGaps(0);
     166            1 :     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
     167            1 :     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
     168            1 :     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
     169            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
     170            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
     171            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
     172            1 :     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
     173            1 :     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     174            1 :     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     175            1 : }
     176              : 
     177              : 
     178              : // --------------------------------
     179              : // gap filling tests
     180              : // --------------------------------
     181              : 
     182              : /* Tests what happens if one overwrites a value (three values stored, fillGaps called). */
     183            2 : TEST(ValueTimeLine, test_fill_gaps_withbounds) {
     184              :     ValueTimeLine<int> vtl;
     185            1 :     vtl.add(50, 250, 2);
     186            1 :     vtl.fillGaps(4, true);
     187            1 :     EXPECT_EQ(2, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
     188            1 :     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
     189            1 :     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
     190            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
     191            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
     192            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
     193            1 :     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
     194            1 :     EXPECT_EQ(2, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     195            1 :     EXPECT_EQ(2, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     196            1 : }
     197              : 
     198              : 
     199              : /* Tests what happens if one overwrites a value (three values stored, fillGaps called). */
     200            2 : TEST(ValueTimeLine, test_fill_gaps_nobounds) {
     201              :     ValueTimeLine<int> vtl;
     202            1 :     vtl.add(50, 250, 2);
     203            1 :     vtl.fillGaps(4, false);
     204            1 :     EXPECT_EQ(4, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
     205            1 :     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
     206            1 :     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
     207            1 :     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
     208            1 :     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
     209            1 :     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
     210            1 :     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
     211            1 :     EXPECT_EQ(4, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
     212            1 :     EXPECT_EQ(4, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
     213            1 : }
        

Generated by: LCOV version 2.0-1