ValueTimeLineTest.cpp

Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <utils/common/ValueTimeLine.h>
00003 
00004 using namespace std;
00005 
00006 /*
00007 Tests ValueTimeLine class from <SUMO>/src/utils/common
00008 */
00009 
00010 /* Tests what happens if one tries to get a value from an empty ValueTimeLine. */
00011 /*
00012 TEST(ValueTimeLine, test_get_from_empty) {
00013     ValueTimeLine<int> vtl;
00014     EXPECT_EQ(1, vtl.getValue(0)) << "Something should happen if nothing was stored.";
00015 }
00016 */
00017 
00018 
00019 // --------------------------------
00020 // plain retrieval / overwriting tests
00021 // --------------------------------
00022 
00023 /* Tests what happens if one tries to get a stored value (one value stored, fillGaps not called). */
00024 TEST(ValueTimeLine, test_get_single_nocollect) {
00025     ValueTimeLine<int> vtl;
00026     vtl.add(0, 100, 2);
00027     EXPECT_EQ(2, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00028     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00029     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00030 }
00031 
00032 /* Tests what happens if one tries to get a stored value (three values stored, fillGaps not called). */
00033 TEST(ValueTimeLine, test_get_multi_nocollect) {
00034     ValueTimeLine<int> vtl;
00035     vtl.add(0, 100, 1);
00036     vtl.add(100, 200, 2);
00037     vtl.add(200, 300, 3);
00038     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00039     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00040     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00041     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00042     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00043     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00044     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00045     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00046     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00047 }
00048 
00049 /* Tests what happens if one tries to get a stored value (one value stored, fillGaps called). */
00050 TEST(ValueTimeLine, test_get_single_collect) {
00051     ValueTimeLine<int> vtl;
00052     vtl.add(0, 100, 2);
00053     vtl.fillGaps(0);
00054     EXPECT_EQ(2, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00055     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00056     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00057 }
00058 
00059 /* Tests what happens if one tries to get a stored value (three values stored, fillGaps called). */
00060 TEST(ValueTimeLine, test_get_multi_collect) {
00061     ValueTimeLine<int> vtl;
00062     vtl.add(0, 100, 1);
00063     vtl.add(100, 200, 2);
00064     vtl.add(200, 300, 3);
00065     vtl.fillGaps(0);
00066     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00067     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00068     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00069     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00070     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00071     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00072     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00073     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00074     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00075 }
00076 
00077 // --------------------------------
00078 // overwriting filling tests
00079 // --------------------------------
00080 
00081 /* Tests what happens if one overwrites a value (three values stored, fillGaps not called). */
00082 TEST(ValueTimeLine, test_overwrite_nocollect) {
00083     ValueTimeLine<int> vtl;
00084     vtl.add(0, 100, 1);
00085     vtl.add(200, 300, 3);
00086     vtl.add(50, 250, 2);
00087     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00088     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00089     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00090     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00091     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00092     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00093     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00094     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00095     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00096 }
00097 
00098 /* Tests what happens if one overwrites a value (three values stored, fillGaps called). */
00099 TEST(ValueTimeLine, test_overwrite_collect) {
00100     ValueTimeLine<int> vtl;
00101     vtl.add(0, 100, 1);
00102     vtl.add(200, 300, 3);
00103     vtl.add(50, 250, 2);
00104     vtl.fillGaps(0);
00105     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00106     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00107     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00108     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00109     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00110     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00111     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00112     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00113     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00114 }
00115 
00116 /* Tests what happens if one overwrites a value (three values stored, fillGaps not called, order changed). */
00117 TEST(ValueTimeLine, test_overwrite_nocollect2) {
00118     ValueTimeLine<int> vtl;
00119     vtl.add(50, 250, 2);
00120     vtl.add(0, 100, 1);
00121     vtl.add(200, 300, 3);
00122     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00123     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00124     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00125     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00126     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00127     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00128     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00129     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00130     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00131 }
00132 
00133 /* Tests what happens if one overwrites a value (three values stored, fillGaps called, order changed). */
00134 TEST(ValueTimeLine, test_overwrite_collect2) {
00135     ValueTimeLine<int> vtl;
00136     vtl.add(50, 250, 2);
00137     vtl.add(0, 100, 1);
00138     vtl.add(200, 300, 3);
00139     vtl.fillGaps(0);
00140     EXPECT_EQ(1, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00141     EXPECT_EQ(1, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00142     EXPECT_EQ(1, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00143     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00144     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00145     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00146     EXPECT_EQ(3, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00147     EXPECT_EQ(3, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00148     EXPECT_EQ(3, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00149 }
00150 
00151 
00152 // --------------------------------
00153 // gap filling tests
00154 // --------------------------------
00155 
00156 /* Tests what happens if one overwrites a value (three values stored, fillGaps called). */
00157 TEST(ValueTimeLine, test_fill_gaps_withbounds) {
00158     ValueTimeLine<int> vtl;
00159     vtl.add(50, 250, 2);
00160     vtl.fillGaps(4, true);
00161     EXPECT_EQ(2, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00162     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00163     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00164     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00165     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00166     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00167     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00168     EXPECT_EQ(2, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00169     EXPECT_EQ(2, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00170 }
00171 
00172 
00173 /* Tests what happens if one overwrites a value (three values stored, fillGaps called). */
00174 TEST(ValueTimeLine, test_fill_gaps_nobounds) {
00175     ValueTimeLine<int> vtl;
00176     vtl.add(50, 250, 2);
00177     vtl.fillGaps(4, false);
00178     EXPECT_EQ(4, vtl.getValue(0)) << "The stored number should be returned when asking within the interval.";
00179     EXPECT_EQ(2, vtl.getValue(99)) << "The stored number should be returned when asking within the interval.";
00180     EXPECT_EQ(2, vtl.getValue(50)) << "The stored number should be returned when asking within the interval.";
00181     EXPECT_EQ(2, vtl.getValue(100)) << "The stored number should be returned when asking within the interval.";
00182     EXPECT_EQ(2, vtl.getValue(199)) << "The stored number should be returned when asking within the interval.";
00183     EXPECT_EQ(2, vtl.getValue(150)) << "The stored number should be returned when asking within the interval.";
00184     EXPECT_EQ(2, vtl.getValue(200)) << "The stored number should be returned when asking within the interval.";
00185     EXPECT_EQ(4, vtl.getValue(299)) << "The stored number should be returned when asking within the interval.";
00186     EXPECT_EQ(4, vtl.getValue(250)) << "The stored number should be returned when asking within the interval.";
00187 }
00188 
00189 

Generated on Wed May 5 00:06:37 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6