-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest_edge_stream.cpp
98 lines (80 loc) · 2.89 KB
/
test_edge_stream.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Copyright (C) 2019 Dean De Leo, email: dleo[at]cwi.nl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "gtest/gtest.h"
#include <iostream>
#include "common/error.hpp"
#include "common/filesystem.hpp"
#include "graph/edge.hpp"
#include "graph/edge_stream.hpp"
using namespace gfe::graph;
using namespace std;
TEST(EdgeStream, Sanity) {
WeightedEdgeStream stream(common::filesystem::directory_executable() + "/graphs/weighted_no_comments.wel");
ASSERT_EQ(stream.num_edges(), 10);
ASSERT_EQ(stream.max_vertex_id(), 4);
// 1 2 10
ASSERT_EQ(stream[0].source(), 1);
ASSERT_EQ(stream[0].destination(), 2);
ASSERT_EQ(stream[0].weight(), 10);
// 1 3 100
ASSERT_EQ(stream[1].source(), 1);
ASSERT_EQ(stream[1].destination(), 3);
ASSERT_EQ(stream[1].weight(), 100);
// 1 4 200
ASSERT_EQ(stream[2].source(), 1);
ASSERT_EQ(stream[2].destination(), 4);
ASSERT_EQ(stream[2].weight(), 200);
// 2 1 10
ASSERT_EQ(stream[3].source(), 2);
ASSERT_EQ(stream[3].destination(), 1);
ASSERT_EQ(stream[3].weight(), 10);
// 2 4 10
ASSERT_EQ(stream[4].source(), 2);
ASSERT_EQ(stream[4].destination(), 4);
ASSERT_EQ(stream[4].weight(), 10);
// 3 1 100
ASSERT_EQ(stream[5].source(), 3);
ASSERT_EQ(stream[5].destination(), 1);
ASSERT_EQ(stream[5].weight(), 100);
// 3 4 10
ASSERT_EQ(stream[6].source(), 3);
ASSERT_EQ(stream[6].destination(), 4);
ASSERT_EQ(stream[6].weight(), 10);
// 4 1 200
ASSERT_EQ(stream[7].source(), 4);
ASSERT_EQ(stream[7].destination(), 1);
ASSERT_EQ(stream[7].weight(), 200);
// 4 2 10
ASSERT_EQ(stream[8].source(), 4);
ASSERT_EQ(stream[8].destination(), 2);
ASSERT_EQ(stream[8].weight(), 10);
// 4 3 10
ASSERT_EQ(stream[9].source(), 4);
ASSERT_EQ(stream[9].destination(), 3);
ASSERT_EQ(stream[9].weight(), 10);
// permutation
WeightedEdgeStream permuted(common::filesystem::directory_executable() + "/graphs/weighted_no_comments.wel");
permuted.permute();
ASSERT_EQ(stream.num_edges(), permuted.num_edges());
for(int i = 0, end = stream.num_edges(); i < end; i++){
bool found = false;
for(int j = 0; j < end && !found; j++){
found = (stream[i] == permuted[j]);
}
ASSERT_EQ(found, true);
}
}