-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added helper folder with analyzer and debugger
- Loading branch information
1 parent
349e19c
commit f9a1da9
Showing
6 changed files
with
153 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
#include "../../src/helpers/timer.h" | ||
#include "../../src/helpers/debug.h" | ||
#include "../../src/classes/graph/graph.h" | ||
#include "../../src/algorithms/number_theory/eratosthenes_sieve.h" | ||
|
||
int main() { | ||
weighted_graph<int> g("directed"); | ||
g.add_edge(0, 1, 5); | ||
g.add_edge(1, 2, 4); | ||
g.add_edge(2, 3, 5); | ||
g.add_edge(3, 4, 2); | ||
g.add_edge(4, 5, 1); | ||
|
||
// in order to pass member function, you need to make them lambda first, | ||
// if they're static function, this step could be ignored | ||
auto shortest_path = [&](int a, int b) -> double { | ||
return g.shortest_path(a, b); | ||
}; | ||
|
||
auto dfs = [&](int a) -> std::vector<int> { | ||
return g.dfs(a); | ||
}; | ||
|
||
// you can even do this: auto bound_dfs = std::bind(&graph<int>::dfs, &g, std::placeholders::_1); | ||
TIMER::exec_time(shortest_path, 0, 4); | ||
|
||
// printing all the arguments(0, 2, 3, 4, 'a') | ||
DEBUG::get_args(shortest_path, 0, 2, 3, 4, 'a'); | ||
|
||
// returns which function is faster | ||
std::cout << TIMER::check_faster(shortest_path, std::make_tuple(0, 1), dfs, std::make_tuple(0)) << '\n'; | ||
|
||
// analyzes the time complxity, also returns a useful graph | ||
TIMER::time_complexity(soe, std::make_tuple(4), std::make_tuple(5), std::make_tuple(10), std::make_tuple(15), std::make_tuple(50), std::make_tuple(100), std::make_tuple(500), std::make_tuple(10000), std::make_tuple(99999)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"execution_time": [ | ||
0.002, | ||
0.002, | ||
0.002, | ||
0.003, | ||
0.004, | ||
0.006, | ||
0.026, | ||
0.5950000000000001, | ||
5.0809999999999995 | ||
], | ||
"input_size": [ | ||
4, | ||
5, | ||
10, | ||
15, | ||
50, | ||
100, | ||
500, | ||
10000, | ||
99999 | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "../../src/helpers/debug.h" | ||
#include "../../third_party/catch.hpp" | ||
#include "../../src/classes/graph/graph.h" | ||
|
||
TEST_CASE("Testing get args for debug namespace") { | ||
weighted_graph<int> g("directed"); | ||
g.add_edge(0, 1, 5); | ||
g.add_edge(1, 2, 4); | ||
g.add_edge(2, 3, 5); | ||
g.add_edge(3, 4, 2); | ||
g.add_edge(4, 5, 1); | ||
|
||
// in order to pass member function, you need to make them lambda first, | ||
// if they're static function, this step could be ignored | ||
auto shortest_path = [&](int a, int b) -> double { | ||
return g.shortest_path(a, b); | ||
}; | ||
|
||
CHECK_NOTHROW(DEBUG::get_args(shortest_path, 0, 2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "../../src/helpers/timer.h" | ||
#include "../../third_party/catch.hpp" | ||
#include "../../src/classes/graph/graph.h" | ||
|
||
|
||
TEST_CASE("Testing execution time for timer namespcae") { | ||
weighted_graph<int> g("directed"); | ||
g.add_edge(0, 1, 5); | ||
g.add_edge(1, 2, 4); | ||
g.add_edge(2, 3, 5); | ||
g.add_edge(3, 4, 2); | ||
g.add_edge(4, 5, 1); | ||
|
||
// in order to pass member function, you need to make them lambda first, | ||
// if they're static function, this step could be ignored | ||
auto shortest_path = [&](int a, int b) -> double { | ||
return g.shortest_path(a, b); | ||
}; | ||
|
||
auto dfs = [&](int a) -> std::vector<int> { | ||
return g.dfs(a); | ||
}; | ||
|
||
CHECK_NOTHROW(TIMER::exec_time(shortest_path, 0, 4)); | ||
} | ||
|
||
TEST_CASE("Testing time complxity for timer namespace") { | ||
weighted_graph<int> g("directed"); | ||
g.add_edge(0, 1, 5); | ||
g.add_edge(1, 2, 4); | ||
g.add_edge(2, 3, 5); | ||
g.add_edge(3, 4, 2); | ||
g.add_edge(4, 5, 1); | ||
|
||
// in order to pass member function, you need to make them lambda first, | ||
// if they're static function, this step could be ignored | ||
auto shortest_path = [&](int a, int b) -> double { | ||
return g.shortest_path(a, b); | ||
}; | ||
|
||
auto dfs = [&](int a) -> std::vector<int> { | ||
return g.dfs(a); | ||
}; | ||
|
||
CHECK_NOTHROW(TIMER::time_complexity(dfs, std::make_tuple(0), std::make_tuple(2), std::make_tuple(4))); | ||
} | ||
|
||
TEST_CASE("Testing check faster for timer namespace") { | ||
weighted_graph<int> g("directed"); | ||
g.add_edge(0, 1, 5); | ||
g.add_edge(1, 2, 4); | ||
g.add_edge(2, 3, 5); | ||
g.add_edge(3, 4, 2); | ||
g.add_edge(4, 5, 1); | ||
|
||
// in order to pass member function, you need to make them lambda first, | ||
// if they're static function, this step could be ignored | ||
auto shortest_path = [&](int a, int b) -> double { | ||
return g.shortest_path(a, b); | ||
}; | ||
|
||
auto dfs = [&](int a) -> std::vector<int> { | ||
return g.dfs(a); | ||
}; | ||
|
||
CHECK_NOTHROW(TIMER::check_faster(shortest_path, std::make_tuple(0, 1), dfs, std::make_tuple(0))); | ||
} |