1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "testing/testing.hpp"
#include "traffic/speed_groups.hpp"
#include "traffic/traffic_info.hpp"
#include "std/algorithm.hpp"
namespace traffic
{
namespace
{
SpeedGroup GetSpeedGroup(TrafficInfo::Coloring const & coloring,
TrafficInfo::RoadSegmentId const & fid)
{
auto const it = coloring.find(fid);
if (it == coloring.cend())
return SpeedGroup::Unknown;
return it->second;
}
} // namespace
UNIT_TEST(TrafficInfo_RemoteFile)
{
string const kTestFileName = "traffic_data";
TrafficInfo r;
TEST(r.ReceiveTrafficData(kTestFileName), ());
}
UNIT_TEST(TrafficInfo_Serialization)
{
TrafficInfo::Coloring coloring = {
{TrafficInfo::RoadSegmentId(0, 0, 0), SpeedGroup::G0},
{TrafficInfo::RoadSegmentId(1000, 1, 1), SpeedGroup::G1},
{TrafficInfo::RoadSegmentId(1000000, 0, 0), SpeedGroup::G5},
{TrafficInfo::RoadSegmentId(4294967295, 32767, 1), SpeedGroup::TempBlock},
};
vector<uint8_t> buf;
TrafficInfo::SerializeTrafficData(coloring, buf);
TrafficInfo::Coloring deserializedColoring;
TrafficInfo::DeserializeTrafficData(buf, deserializedColoring);
TEST_EQUAL(coloring.size(), deserializedColoring.size(), ());
for (auto const & p : coloring)
{
auto const g1 = p.second;
auto const g2 = GetSpeedGroup(deserializedColoring, p.first);
TEST_EQUAL(g1, g2, ());
}
}
} // namespace traffic
|