Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
ChunkMetricsTest Class Reference
+ Inheritance diagram for ChunkMetricsTest:
+ Collaboration diagram for ChunkMetricsTest:

Protected Member Functions

template<typename T >
bool is_valid_resource (const T &resource)
 
template<typename Func >
auto run_safely (Func &&func) -> typename std::invoke_result< Func >::type
 
template<typename T >
void safe_cleanup (T &resource)
 
void SetUp () override
 
void TearDown () override
 

Protected Attributes

std::unique_ptr< chunk_metrics::ChunkQualityAnalyzer< double > > analyzer
 
std::vector< std::vector< double > > empty_chunks
 
std::vector< std::vector< double > > mixed_cohesion_chunks
 
std::mutex test_mutex_
 
std::atomic< bool > test_running_ {false}
 
std::vector< std::vector< double > > well_separated_chunks
 

Static Protected Attributes

static std::mutex global_test_mutex_
 
static constexpr auto TEST_COOLDOWN = std::chrono::milliseconds(100)
 
static std::condition_variable test_cv_
 

Detailed Description

Definition at line 16 of file test_metrics.cpp.

Member Function Documentation

◆ is_valid_resource()

template<typename T >
bool ChunkTestBase::is_valid_resource ( const T &  resource)
inlineprotectedinherited

Definition at line 33 of file test_base.hpp.

33 {
34 return resource != nullptr;
35 }

◆ run_safely()

template<typename Func >
auto ChunkMetricsTest::run_safely ( Func &&  func) -> typename std::invoke_result<Func>::type
inlineprotected

Definition at line 84 of file test_metrics.cpp.

84 {
85 if (test_running_.exchange(true)) {
86 throw std::runtime_error("Test already running");
87 }
88
89 struct TestGuard {
90 std::atomic<bool>& flag;
91 TestGuard(std::atomic<bool>& f) : flag(f) {}
92 ~TestGuard() {
93 flag = false;
94 }
95 } guard(test_running_);
96
97 return func();
98 }
std::atomic< bool > test_running_

References test_running_.

◆ safe_cleanup()

template<typename T >
void ChunkTestBase::safe_cleanup ( T &  resource)
inlineprotectedinherited

Definition at line 21 of file test_base.hpp.

21 {
22 try {
23 if (resource) {
24 resource.reset();
25 }
26 } catch (...) {
27 // Log or handle cleanup errors
28 }
29 }

◆ SetUp()

void ChunkMetricsTest::SetUp ( )
inlineoverrideprotected

Definition at line 25 of file test_metrics.cpp.

25 {
27
28 try {
29 // Initialize analyzer with proper error checking
30 analyzer = std::make_unique<chunk_metrics::ChunkQualityAnalyzer<double>>();
31 if (!analyzer) {
32 throw std::runtime_error("Failed to create analyzer");
33 }
34
35 // Initialize test data with bounds checking
36 well_separated_chunks = {std::vector<double>{1.0, 1.1, 1.2},
37 std::vector<double>{5.0, 5.1, 5.2},
38 std::vector<double>{10.0, 10.1, 10.2}};
39
40 mixed_cohesion_chunks = {std::vector<double>{1.0, 1.1, 5.0},
41 std::vector<double>{2.0, 2.1, 8.0},
42 std::vector<double>{3.0, 3.1, 9.0}};
43
44 // Validate test data
45 for (const auto& chunk : well_separated_chunks) {
46 if (chunk.empty() || chunk.size() > 1000000) {
47 throw std::runtime_error("Invalid test data in well_separated_chunks");
48 }
49 }
50 for (const auto& chunk : mixed_cohesion_chunks) {
51 if (chunk.empty() || chunk.size() > 1000000) {
52 throw std::runtime_error("Invalid test data in mixed_cohesion_chunks");
53 }
54 }
55
56 } catch (const std::exception& e) {
57 FAIL() << "Setup failed: " << e.what();
58 }
59 }
std::vector< std::vector< double > > mixed_cohesion_chunks
std::vector< std::vector< double > > well_separated_chunks
std::unique_ptr< chunk_metrics::ChunkQualityAnalyzer< double > > analyzer
void SetUp() override
Definition test_base.cpp:8

References analyzer, mixed_cohesion_chunks, ChunkTestBase::SetUp(), and well_separated_chunks.

◆ TearDown()

void ChunkMetricsTest::TearDown ( )
inlineoverrideprotected

Definition at line 61 of file test_metrics.cpp.

61 {
62 try {
63 std::lock_guard<std::mutex> lock(test_mutex_);
64
65 if (analyzer) {
66 // Ensure no computations are running
67 std::this_thread::sleep_for(std::chrono::milliseconds(100));
68 analyzer.reset();
69 }
70
73 empty_chunks.clear();
74
75 } catch (...) {
76 // Ensure base teardown still happens
77 }
78
80 }
std::vector< std::vector< double > > empty_chunks
std::mutex test_mutex_
void TearDown() override
Definition test_base.cpp:15

References analyzer, empty_chunks, mixed_cohesion_chunks, ChunkTestBase::TearDown(), test_mutex_, and well_separated_chunks.

Member Data Documentation

◆ analyzer

std::unique_ptr<chunk_metrics::ChunkQualityAnalyzer<double> > ChunkMetricsTest::analyzer
protected

Definition at line 18 of file test_metrics.cpp.

Referenced by SetUp(), and TearDown().

◆ empty_chunks

std::vector<std::vector<double> > ChunkMetricsTest::empty_chunks
protected

Definition at line 21 of file test_metrics.cpp.

Referenced by TearDown().

◆ global_test_mutex_

std::mutex ChunkTestBase::global_test_mutex_
staticprotectedinherited

Definition at line 11 of file test_base.hpp.

Referenced by ChunkTestBase::SetUp(), and ChunkTestBase::TearDown().

◆ mixed_cohesion_chunks

std::vector<std::vector<double> > ChunkMetricsTest::mixed_cohesion_chunks
protected

Definition at line 20 of file test_metrics.cpp.

Referenced by SetUp(), and TearDown().

◆ TEST_COOLDOWN

constexpr auto ChunkTestBase::TEST_COOLDOWN = std::chrono::milliseconds(100)
staticconstexprprotectedinherited

Definition at line 14 of file test_base.hpp.

Referenced by ChunkTestBase::TearDown().

◆ test_cv_

std::condition_variable ChunkTestBase::test_cv_
staticprotectedinherited

Definition at line 12 of file test_base.hpp.

Referenced by ChunkTestBase::SetUp(), and ChunkTestBase::TearDown().

◆ test_mutex_

std::mutex ChunkMetricsTest::test_mutex_
mutableprotected

Definition at line 22 of file test_metrics.cpp.

Referenced by TearDown().

◆ test_running_

std::atomic<bool> ChunkMetricsTest::test_running_ {false}
protected

Definition at line 23 of file test_metrics.cpp.

23{false};

Referenced by run_safely().

◆ well_separated_chunks

std::vector<std::vector<double> > ChunkMetricsTest::well_separated_chunks
protected

Definition at line 19 of file test_metrics.cpp.

Referenced by SetUp(), and TearDown().


The documentation for this class was generated from the following file: