Skip to content

Commit

Permalink
Centralize definition of test main and include cstdint in several hea…
Browse files Browse the repository at this point in the history
…ders

Removed CATCH_CONFIG_MAIN from individual test files and consolidated it into a single test_main.cc.
This simplifies the test configuration and reduces the number of files defining the main function for the Catch2 test suite.
Additionally, the cstdint header was included in several algorithm and data structure headers to ensure the int64_t type is recognized. A new Bubble sort test was also added.
  • Loading branch information
NoOoBiiii authored and spirosmaggioros committed Feb 5, 2024
1 parent fae0c17 commit a615d8e
Show file tree
Hide file tree
Showing 49 changed files with 40 additions and 31 deletions.
1 change: 1 addition & 0 deletions src/algorithms/dynamic_programming/coin_change.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#endif

/**
Expand Down
4 changes: 3 additions & 1 deletion src/algorithms/dynamic_programming/fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <math.h>
#include <cstdint>
#endif

/**
Expand Down Expand Up @@ -62,6 +64,6 @@ int64_t fibonacci_bottom_up(int64_t n) {
*/
int64_t fibonacci_binet(int64_t n) {
double phi = (std::sqrt(5) + 1) / 2;
return std::round(std::pow(phi, n) / sqrt(5));
return (int64_t) std::round(std::pow(phi, n) / sqrt(5));
}
#endif
1 change: 1 addition & 0 deletions src/algorithms/dynamic_programming/kadane.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/dynamic_programming/lcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <string>
#include <cstdint>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/dynamic_programming/lis.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/number_theory/gcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#ifdef __cplusplus
#include <iostream>
#include <cstdint>
#endif

/**
Expand Down
2 changes: 2 additions & 0 deletions src/algorithms/searching/binary_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#endif

/**
Expand Down
3 changes: 3 additions & 0 deletions src/algorithms/searching/jump_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#ifdef __cplusplus
#include <iostream>
#include <cstdint>
#include <vector>
#include <cmath>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/searching/linear_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#ifdef __cplusplus
#include <iostream>
#include <vector>
#endif

/**
Expand Down
2 changes: 2 additions & 0 deletions src/algorithms/sorting/bubble_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#ifdef __cplusplus
#include <iostream>
#include <cstdint>
#include <vector>
#endif

/**
Expand Down
2 changes: 2 additions & 0 deletions src/algorithms/sorting/bucket_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/sorting/insertion_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/sorting/radix_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <algorithm>
#endif

template <typename T> void radix_sort(std::vector<T> &arr) {
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/sorting/selection_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <vector>
#include <cstdint>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/string/edit_distance.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifdef __cplusplus
#include <iostream>
#include <string>
#include <cstdint>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/classes/tree/interval_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <iostream>
#include <memory>
#include <vector>
#include <functional>
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions src/classes/tree/splay_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <iostream>
#include <memory>
#include <vector>
#include <functional>
#endif

/**
Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/dynamic_programming/coin_change.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/dynamic_programming/coin_change.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/dynamic_programming/fibonacci.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/dynamic_programming/fib.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/dynamic_programming/kadane.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/dynamic_programming/kadane.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/dynamic_programming/lcs.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/dynamic_programming/lcs.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/dynamic_programming/lis.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/dynamic_programming/lis.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/number_theory/gcd.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/number_theory/gcd.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/searching/binary_search.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/searching/binary_search.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/searching/exponential_search.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/searching/exponential_search.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/searching/jump_search.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/searching/jump_search.h"
#include "../../catch2/catch.hpp"

Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/searching/linear_search.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/searching/linear_search.h"
#include "../../catch2/catch.hpp"

Expand Down
14 changes: 14 additions & 0 deletions tests/algorithms/sorting/bubble_sort.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "../../../src/algorithms/sorting/bubble_sort.h"
#include "../../catch2/catch.hpp"
#include <random>
#include <vector>

TEST_CASE("testing merge sort") {
std::vector<int64_t> v;
for (int i = 0; i < 5000; i++) {
int random = rand() % 50000;
v.push_back(i - random);
}
bubble_sort(v);
REQUIRE(std::is_sorted(v.begin(), v.end()) == true);
}
1 change: 0 additions & 1 deletion tests/algorithms/sorting/bucket_sort.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/sorting/bucket_sort.h"
#include "../../catch2/catch.hpp"
#include <random>
Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/sorting/insertion_sort.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/sorting/insertion_sort.h"
#include "../../catch2/catch.hpp"
#include <random>
Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/sorting/merge_sort.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/sorting/merge_sort.h"
#include "../../catch2/catch.hpp"
#include <random>
Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/sorting/quick_sort.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/sorting/quick_sort.h"
#include "../../catch2/catch.hpp"
#include <random>
Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/sorting/selection_sort.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/sorting/selection_sort.h"
#include "../../catch2/catch.hpp"
#include <random>
Expand Down
1 change: 0 additions & 1 deletion tests/algorithms/string/min_distance.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../../src/algorithms/string/edit_distance.h"
#include "../../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/graph/graph.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/graph/graph.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/graph/weighted_graph.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/graph/graph.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/hash_table/hash_table.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/hash_table/hash_table.h"
#include "../catch2/catch.hpp"
#include <list>
Expand Down
1 change: 0 additions & 1 deletion tests/list/circular_linked_list.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/list/circular_linked_list.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/list/doubly_list.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/list/doubly_linked_list.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/list/list.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/list/linked_list.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/list/skip_list.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/list/skip_list.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/queue/dequeue_list.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/queue/dequeue_list.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/stack/stack_list.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/stack/stack_list.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
2 changes: 2 additions & 0 deletions tests/test_main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
1 change: 0 additions & 1 deletion tests/tree/avl.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/tree/avl_tree.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/tree/bst.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/tree/bst.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/tree/interval_tree.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/tree/interval_tree.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/tree/splay_tree.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/tree/splay_tree.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down
1 change: 0 additions & 1 deletion tests/tree/trie.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include "../../src/classes/tree/trie.h"
#include "../catch2/catch.hpp"
#include <string>
Expand Down

0 comments on commit a615d8e

Please sign in to comment.