Skip to content

Commit 6ebb3d8

Browse files
committed
add basic unittest for Random
1 parent 52de229 commit 6ebb3d8

File tree

6 files changed

+445
-5
lines changed

6 files changed

+445
-5
lines changed

TODO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Random class
2+
3+
- [] Review all the unit tests
4+
5+
# Project wide
6+
7+
- add gcov
8+
- add CI/Coverage

src/Core/Random/Random.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
#include <gsl/gsl_randist.h>
1111

1212
#include <cmath>
13+
#include <cstdint>
1314
#include <random>
1415

1516
// Constructor
16-
Random::Random(gsl_rng* rng) : seed_(0) {
17+
Random::Random(gsl_rng* rng, uint64_t seed) : seed_(seed) {
1718
if (rng != nullptr) {
1819
// If an external RNG is provided, take ownership using the unique_ptr
1920
rng_.reset(rng);

src/Core/Random/Random.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Random {
3636
*
3737
* @param external_rng Pointer to an external GSL RNG. Defaults to nullptr.
3838
*/
39-
explicit Random(gsl_rng* external_rng = nullptr);
39+
explicit Random(gsl_rng* external_rng = nullptr, uint64_t seed = 0);
4040

4141
/**
4242
* @brief Destructor.

tests/.clang-tidy

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Checks: >
2+
*,
3+
-altera-id-dependent-backward-branch,
4+
-altera-struct-pack-align,
5+
-altera-unroll-loops,
6+
-fuchsia-*,
7+
-llvmlibc-*,
8+
-llvm-header-guard,
9+
-llvm-include-order,
10+
-cppcoreguidelines-owning-memory,
11+
-cppcoreguidelines-non-private-member-variables-in-classes,
12+
-cppcoreguidelines-avoid-non-const-global-variables,
13+
-cppcoreguidelines-avoid-magic-numbers,
14+
-google-readability-todo,
15+
-modernize-use-trailing-return-type,
16+
-modernize-pass-by-value,
17+
-misc-non-private-member-variables-in-classes,
18+
-performance-avoid-endl,
19+
-readability-magic-numbers
20+
21+
# Checks: >
22+
# *,
23+
# -cppcoreguidelines-owning-memory
24+
# -google-readability-todo,
25+
# -altera-unroll-loops,
26+
# -altera-id-dependent-backward-branch,
27+
# -altera-struct-pack-align,
28+
# -fuchsia-*,
29+
# fuchsia-multiple-inheritance,
30+
# -llvm-header-guard,
31+
# -llvm-include-order,
32+
# -llvmlibc-*,
33+
# -modernize-use-trailing-return-type,
34+
# -misc-non-private-member-variables-in-classes,
35+
# -cppcoreguidelines-pro-type-vararg,
36+
# -cppcoreguidelines-avoid-c-arrays,
37+
# -hicpp-vararg,
38+
# -hicpp-avoid-c-arrays,
39+
# -modernize-avoid-c-arrays
40+
41+
WarningsAsErrors: ""
42+
# WarningsAsErrors: "*,-readability-convert-member-functions-to-static"
43+
44+
CheckOptions:
45+
- key: "readability-identifier-length.MinimumVariableNameLength"
46+
value: "2"
47+
- key: "readability-identifier-length.MinimumParameterNameLength"
48+
value: "2"
49+
- key: "readability-identifier-length.MinimumLoopCounterNameLength"
50+
value: "2"
51+
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
52+
- {
53+
key: readability-identifier-naming.MacroDefinitionCase,
54+
value: UPPER_CASE,
55+
}
56+
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
57+
- { key: readability-identifier-naming.StructCase, value: CamelCase }
58+
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
59+
- { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
60+
- { key: readability-identifier-naming.TypedefCase, value: CamelCase }
61+
- { key: readability-identifier-naming.TypeAliasCase, value: CamelCase }
62+
- { key: readability-identifier-naming.UnionCase, value: CamelCase }
63+
64+
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
65+
- { key: readability-identifier-naming.GlobalFunctionCase, value: lower_case }
66+
67+
- { key: readability-identifier-naming.GlobalVariableCase, value: CamelCase }
68+
69+
- { key: readability-identifier-naming.LocalVariableCase, value: aNy_CasE }
70+
- { key: readability-identifier-naming.ParameterCase, value: aNy_CasE }
71+
#static
72+
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
73+
- { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
74+
75+
- { key: readability-identifier-naming.MethodCase, value: lower_case }
76+
- { key: readability-identifier-naming.PrivateMethodCase, value: lower_case }
77+
78+
- { key: readability-identifier-naming.MemberCase, value: lower_case }
79+
- { key: readability-identifier-naming.PrivateMemberCase, value: lower_case }
80+
- { key: readability-identifier-naming.PrivateMemberSuffix, value: "_" }
81+
82+
- { key: readability-identifier-naming.VariableCase, value: lower_case }
83+
84+
- { key: readability-identifier-naming.StaticVariableCase, value: lower_case }
85+
- {
86+
key: readability-identifier-naming.ConstexprVariableCase,
87+
value: UPPER_CASE,
88+
}
89+
#constant
90+
- { key: readability-identifier-naming.GlobalConstantCase, value: lower_case }
91+
92+
- { key: readability-identifier-naming.MemberConstantCase, value: lower_case }
93+
94+
- { key: readability-identifier-naming.StaticConstantCase, value: lower_case }
95+
96+
- {
97+
key: readability-identifier-naming.TemplateParameterCase,
98+
value: CamelCase,
99+
}
100+
# some magic number
101+
- {
102+
key: readability-magic-numbers.IgnoredIntegerValues,
103+
value: "-1; 0; 1; 2; 3; 4; 5;10;100",
104+
}

tests/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
33
# Find Google Test
44
find_package(GTest REQUIRED)
55

6+
file(GLOB_RECURSE MALASIM_TEST_SOURCES
7+
"*.cpp"
8+
"Core/Random/*.cpp"
9+
)
10+
11+
612
# Add test executable
713
add_executable(runTests
8-
# Add your test files here
9-
example_test.cpp
14+
${MALASIM_TEST_SOURCES}
1015
)
1116

17+
add_dependencies(runTests MalaSimCore)
18+
1219
# Link the core library and GTest to the test executable
1320
target_link_libraries(runTests PRIVATE
1421
GTest::gtest_main
1522
MalaSimCore
1623
)
1724

1825
# Add tests
19-
add_test(NAME example_test COMMAND ${CMAKE_BINARY_DIR}/bin/runTests)
26+
add_test(NAME malasim_test COMMAND ${CMAKE_BINARY_DIR}/bin/runTests)

0 commit comments

Comments
 (0)