Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit f7e8038

Browse files
committed
Add method for testing undirected graphs
1 parent 595b2be commit f7e8038

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

UndirectedGraph.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
#include <random>
66
#include <queue>
77
#include <algorithm>
8+
#include <iostream>
9+
#include <fstream>
10+
#include <ctime>
811
#include "UndirectedGraph.h"
912
#include "MinHeapElement.h"
13+
#include "Counter.h"
1014

1115
using namespace std;
1216

@@ -96,7 +100,76 @@ string UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3)
96100
}
97101

98102
void UndirectedGraph::test() {
103+
int numberOfElements[5] = {50, 100, 150, 200, 250};
104+
int density[4] = {25, 50, 75, 99};
105+
char representationType[2] = {'M', 'L'};
106+
int range = 1000;
107+
int numberOfTests = 100;
108+
string path;
109+
double sumOfResults;
110+
Counter counter;
111+
double result = 0;
112+
113+
for (int i = 0; i < 5; i++) {
114+
for (int j = 0; j < 4; j++) {
115+
for (int k = 0; k < 2; k++) {
116+
path = "..\\wyniki\\";
117+
path += to_string(time(0));
118+
path += "-gNieskierowany-algorytmPrima-n" + to_string(numberOfElements[i]) + "-g" +
119+
to_string(density[j]) + "-r" + representationType[k] + ".txt";
120+
121+
cout << "Test - Graf: Nieskierowany - Algorytm: Prima - Ilosc elem: " << numberOfElements[i] << " - Gestosc: " << density[j] << " - Reprezentacja: " << representationType[k] << endl;
122+
123+
fstream file(path, fstream::out);
124+
125+
file.setf(ios::fixed);
126+
127+
sumOfResults = 0;
128+
129+
if (!file.is_open()) {
130+
cerr << "Wyniki sie nie zapisza!!!" << endl;
131+
}
132+
133+
for (int l = 0; l < numberOfTests; l++) {
134+
generate(numberOfElements[i], density[j], range);
135+
136+
cout << "Test: " << l << " - ";
137+
138+
if (representationType[k] == 'M') {
139+
try {
140+
counter.startCounter();
141+
primsAlgorithmOnMatrix(false);
142+
result = counter.getCounter();
143+
} catch (const char* e) {
144+
l--;
145+
result = 0;
146+
}
147+
} else {
148+
try {
149+
counter.startCounter();
150+
primsAlgorithmOnList(false);
151+
result = counter.getCounter();
152+
} catch (const char* e) {
153+
l--;
154+
result = 0;
155+
}
156+
}
157+
158+
cout << "Czas: " << result << endl;
159+
file << result << endl;
160+
161+
sumOfResults += result;
162+
}
99163

164+
sumOfResults /= numberOfTests;
165+
166+
cout << "Srednia: " << sumOfResults << endl;
167+
file << "Srednia" << endl << sumOfResults << endl;
168+
169+
file.close();
170+
}
171+
}
172+
}
100173
}
101174

102175
// protected

0 commit comments

Comments
 (0)