forked from Turupawn/Bellman-Ford-Shortest-Path
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
71 lines (54 loc) · 1.03 KB
/
Test.cpp
File metadata and controls
71 lines (54 loc) · 1.03 KB
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
#include "Test.h"
int** _initGraph(int size)
{
int **answer = new int* [size];
for(int i=0;i<size;i++)
{
answer[i]=new int[size];
for(int j=0;j<size;j++)
{
answer[i][j]=-1;
}
}
return answer;
}
bool compare(int* a, int* b, int size)
{
for(int i=0;i<size;i++)
{
if(a[i]!=b[i])
return false;
}
return true;
}
void test()
{
int** g1 = _initGraph(5);
g1[0][1]=2;
g1[0][2]=6;
g1[0][3]=7;
g1[1][3]=3;
g1[1][4]=6;
g1[2][4]=1;
g1[3][4]=5;
static const int r1[] = {0,0,0,1,2};
int** g2 = _initGraph(5);
g2[0][1]=1;
g2[0][2]=10;
g2[1][3]=2;
g2[2][3]=-10;
g2[3][4]=3;
static const int r2[] = {0,0,0,2,3};
int* a1 = getShortestPath(g1, 5, 0);
int* a2 = getShortestPath(g2, 5, 0);
if(a1 && a2
&& compare(a1, (int*)r1, 5)
&& compare(a2, (int*)r2, 5)
)
{
cout<<"Test: Pass"<<endl;
}else
{
cout<<"Test: Fail"<<endl;
}
}