-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from seldon-code/unit_tests_in_ci
Unit tests in ci
- Loading branch information
Showing
15 changed files
with
252 additions
and
55 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,152 @@ | ||
--- | ||
WarningsAsErrors: '' | ||
HeaderFilterRegex: '' | ||
AnalyzeTemporaryDtors: false | ||
FormatStyle: file | ||
Checks: > | ||
-*, | ||
clang-diagnostic-*, | ||
bugprone-argument-comment, | ||
bugprone-assert-side-effect, | ||
bugprone-bad-signal-to-kill-thread, | ||
bugprone-bool-pointer-implicit-conversion, | ||
bugprone-branch-clone, | ||
bugprone-copy-constructor-init, | ||
bugprone-dangling-handle, | ||
bugprone-exception-escape, | ||
bugprone-fold-init-type, | ||
bugprone-forward-declaration-namespace, | ||
bugprone-forwarding-reference-overload, | ||
bugprone-implicit-widening-of-multiplication-result, | ||
bugprone-inaccurate-erase, | ||
bugprone-incorrect-roundings, | ||
bugprone-infinite-loop, | ||
bugprone-integer-division, | ||
bugprone-lambda-function-name, | ||
bugprone-macro-parentheses, | ||
bugprone-macro-repeated-side-effects, | ||
bugprone-misplaced-operator-in-strlen-in-alloc, | ||
bugprone-misplaced-pointer-arithmetic-in-alloc, | ||
bugprone-misplaced-widening-cast, | ||
bugprone-move-forwarding-reference, | ||
bugprone-multiple-statement-macro, | ||
bugprone-not-null-terminated-result, | ||
bugprone-parent-virtual-call, | ||
bugprone-posix-return, | ||
bugprone-redundant-branch-condition, | ||
bugprone-reserved-identifier, | ||
bugprone-signal-handler, | ||
bugprone-signed-char-misuse, | ||
bugprone-sizeof-container, | ||
bugprone-sizeof-expression, | ||
bugprone-spuriously-wake-up-functions, | ||
bugprone-string-constructor, | ||
bugprone-string-integer-assignment, | ||
bugprone-string-literal-with-embedded-nul, | ||
bugprone-suspicious-enum-usage, | ||
bugprone-suspicious-include, | ||
bugprone-suspicious-memory-comparison, | ||
bugprone-suspicious-memset-usage, | ||
bugprone-suspicious-missing-comma, | ||
bugprone-suspicious-semicolon, | ||
bugprone-suspicious-string-compare, | ||
bugprone-swapped-arguments, | ||
bugprone-terminating-continue, | ||
bugprone-throw-keyword-missing, | ||
bugprone-too-small-loop-variable, | ||
bugprone-undefined-memory-manipulation, | ||
bugprone-undelegated-constructor, | ||
bugprone-unhandled-exception-at-new, | ||
bugprone-unhandled-self-assignment, | ||
bugprone-unused-raii, | ||
bugprone-unused-return-value, | ||
bugprone-use-after-move, | ||
bugprone-virtual-near-miss, | ||
cert-dcl58-cpp, | ||
cert-env33-c, | ||
cert-err34-c, | ||
cert-err52-cpp, | ||
cert-err60-cpp, | ||
cert-flp30-c, | ||
cert-msc50-cpp, | ||
cert-msc51-cpp, | ||
cert-oop57-cpp, | ||
cert-oop58-cpp, | ||
cert-dcl59-cpp, | ||
cppcoreguidelines-avoid-goto, | ||
cppcoreguidelines-init-variables, | ||
cppcoreguidelines-macro-usage, | ||
cppcoreguidelines-no-malloc, | ||
cppcoreguidelines-prefer-member-initializer, | ||
cppcoreguidelines-pro-type-const-cast, | ||
cppcoreguidelines-pro-type-cstyle-cast, | ||
cppcoreguidelines-pro-type-member-init, | ||
cppcoreguidelines-pro-type-static-cast-downcast, | ||
cppcoreguidelines-slicing, | ||
cppcoreguidelines-virtual-class-destructor, | ||
hicpp-exception-baseclass, | ||
hicpp-no-assembler, | ||
hicpp-signed-bitwise, | ||
misc-definitions-in-headers, | ||
misc-non-copyable-objects, | ||
misc-redundant-expression, | ||
misc-static-assert, | ||
misc-throw-by-value-catch-by-reference, | ||
misc-unconventional-assign-operator, | ||
misc-uniqueptr-reset-release, | ||
misc-unused-alias-decls, | ||
misc-unused-parameters, | ||
misc-unused-using-decls, | ||
modernize-avoid-bind, | ||
modernize-deprecated-headers, | ||
modernize-make-shared, | ||
modernize-make-unique, | ||
modernize-redundant-void-arg, | ||
modernize-use-auto, | ||
modernize-use-bool-literals, | ||
modernize-use-emplace, | ||
modernize-use-equals-default, | ||
modernize-use-equals-delete, | ||
modernize-use-nullptr, | ||
modernize-use-override, | ||
modernize-use-uncaught-exceptions, | ||
modernize-use-using, | ||
openmp-exception-escape, | ||
openmp-use-default-none, | ||
performance-for-range-copy, | ||
performance-implicit-conversion-in-loop, | ||
performance-inefficient-algorithm, | ||
performance-inefficient-string-concatenation, | ||
performance-move-const-arg, | ||
performance-move-constructor-init, | ||
performance-trivially-destructible, | ||
performance-type-promotion-in-math-fn, | ||
performance-unnecessary-copy-initialization, | ||
performance-unnecessary-value-param, | ||
readability-avoid-const-params-in-decls, | ||
readability-container-size-empty, | ||
readability-convert-member-functions-to-static, | ||
readability-delete-null-pointer, | ||
readability-function-cognitive-complexity, | ||
readability-function-size, | ||
readability-implicit-bool-conversion, | ||
readability-inconsistent-declaration-parameter-name, | ||
readability-make-member-function-const, | ||
readability-misplaced-array-index, | ||
readability-non-const-parameter, | ||
readability-qualified-auto, | ||
readability-redundant-access-specifiers, | ||
readability-redundant-control-flow, | ||
readability-redundant-declaration, | ||
readability-redundant-preprocessor, | ||
readability-redundant-smartptr-get, | ||
readability-redundant-string-cstr, | ||
readability-simplify-boolean-expr, | ||
readability-simplify-subscript-expr, | ||
readability-static-accessed-through-instance, | ||
readability-string-compare, | ||
readability-uniqueptr-delete-release, | ||
readability-use-anyofallof | ||
CheckOptions: | ||
- { key: readability-function-size.StatementThreshold, value: '800' } | ||
- { key: readability-function-size.LineThreshold, value: '200' } |
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/sh | ||
find ./include -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -i {} \; | ||
find ./src -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -i {} \; | ||
find ./test -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -i {} \; |
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,4 @@ | ||
#!/bin/sh | ||
find ./include -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-tidy {} \; | ||
find ./src -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-tidy {} \; | ||
find ./test -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-tidy {} \; |
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
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,44 @@ | ||
#include <catch2/catch_test_macros.hpp> | ||
#include <catch2/matchers/catch_matchers_floating_point.hpp> | ||
|
||
#include "models/DeGroot.hpp" | ||
#include "network.hpp" | ||
#include <random> | ||
|
||
TEST_CASE( "Test the DeGroot Model Symmetric", "[DeGroot]" ) | ||
{ | ||
using namespace Seldon; | ||
using namespace Catch::Matchers; | ||
|
||
size_t n_agents = 2; | ||
auto neighbour_list = std::vector<std::vector<size_t>>{ | ||
{ 1, 0 }, | ||
{ 0, 1 }, | ||
}; | ||
|
||
auto weight_list = std::vector<std::vector<double>>{ | ||
{ 0.2, 0.8 }, | ||
{ 0.2, 0.8 }, | ||
}; | ||
|
||
auto gen = std::mt19937(); | ||
auto network = Network( std::move( neighbour_list ), std::move( weight_list ) ); | ||
auto model = DeGrootModel( n_agents, network ); | ||
|
||
model.convergence_tol = 1e-6; | ||
model.max_iterations = 100; | ||
model.agents[0].opinion = 0.0; | ||
model.agents[1].opinion = 1.0; | ||
|
||
do | ||
{ | ||
model.iteration(); | ||
} while( !model.finished() ); | ||
|
||
fmt::print( "N_iterations = {} (with convergence_tol {})\n", model.n_iterations, model.convergence_tol ); | ||
for( size_t i = 0; i < n_agents; i++ ) | ||
{ | ||
fmt::print( "Opinion {} = {}\n", i, model.agents[i].opinion ); | ||
REQUIRE_THAT( model.agents[i].opinion, WithinAbs( 0.5, model.convergence_tol * 10.0 ) ); | ||
} | ||
} |
Oops, something went wrong.