@@ -24,6 +24,7 @@ using namespace cc;
2424extern char * dbConnectionString;
2525
2626typedef std::pair<std::string, unsigned int > StringUintParam;
27+ typedef std::pair<std::string, double > StringDoubleParam;
2728
2829class CppMetricsParserTest : public ::testing::Test
2930{
@@ -353,3 +354,41 @@ INSTANTIATE_TEST_SUITE_P(
353354 ParameterizedEfferentModuleCouplingTest,
354355 ::testing::ValuesIn (paramEfferentModule)
355356);
357+
358+ // Relational cohesion at module level
359+
360+ class ParameterizedRelationalCohesionTest
361+ : public CppMetricsParserTest,
362+ public ::testing::WithParamInterface<StringDoubleParam>
363+ {};
364+
365+ // Relational cohesion formula:
366+ // H = (R + 1)/ N
367+ // where R is the number of type relationships that are internal to a module,
368+ // N is the number of types within a module.
369+
370+ std::vector<StringDoubleParam> paramRelationalCohesion = {
371+ {" %/test/sources/parser/rc_module_a" , (3 + 1 ) / 3.0 },
372+ {" %/test/sources/parser/rc_module_b" , (0 + 1 ) / 1.0 },
373+ {" %/test/sources/parser/rc_module_c" , (1 + 1 ) / 4.0 },
374+ };
375+
376+ TEST_P (ParameterizedRelationalCohesionTest, RelationalCohesionTest) {
377+ _transaction ([&, this ]() {
378+
379+ typedef odb::query<model::CppModuleMetricsForPathView> CppModuleMetricsQuery;
380+
381+ const auto metric = _db->query_value <model::CppModuleMetricsForPathView>(
382+ CppModuleMetricsQuery::CppFileMetrics::type == model::CppFileMetrics::Type::RELATIONAL_COHESION_MODULE &&
383+ CppModuleMetricsQuery::File::path.like (GetParam ().first ));
384+
385+ constexpr double tolerance = 1e-8 ;
386+ EXPECT_NEAR (GetParam ().second , metric.value , tolerance);
387+ });
388+ }
389+
390+ INSTANTIATE_TEST_SUITE_P (
391+ ParameterizedRelationalCohesionTestSuite,
392+ ParameterizedRelationalCohesionTest,
393+ ::testing::ValuesIn (paramRelationalCohesion)
394+ );
0 commit comments