Advanced Chunk Processing Library 0.2.0
A comprehensive C++ library for advanced data chunking strategies and processing operations
Loading...
Searching...
No Matches
test_metrics.cpp File Reference
#include "chunk_metrics.hpp"
#include "test_base.hpp"
#include <algorithm>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <future>
#include <iostream>
#include <limits>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <thread>
#include <vector>
+ Include dependency graph for test_metrics.cpp:

Go to the source code of this file.

Classes

class  ChunkMetricsTest
 

Functions

 TEST_F (ChunkMetricsTest, CacheClear)
 
 TEST_F (ChunkMetricsTest, CohesionCalculation)
 
 TEST_F (ChunkMetricsTest, EmptyChunks)
 
 TEST_F (ChunkMetricsTest, QualityScore)
 
 TEST_F (ChunkMetricsTest, SeparationCalculation)
 
 TEST_F (ChunkMetricsTest, SilhouetteScore)
 
 TEST_F (ChunkMetricsTest, SingleChunk)
 
 TEST_F (ChunkMetricsTest, SizeMetrics)
 

Function Documentation

◆ TEST_F() [1/8]

TEST_F ( ChunkMetricsTest  ,
CacheClear   
)

Definition at line 196 of file test_metrics.cpp.

196 {
197 analyzer->compute_cohesion(well_separated_chunks);
198 analyzer->compute_separation(well_separated_chunks);
199 analyzer->clear_cache();
200 // Verify the function runs without errors
201 EXPECT_NO_THROW(analyzer->compute_cohesion(well_separated_chunks));
202}

◆ TEST_F() [2/8]

TEST_F ( ChunkMetricsTest  ,
CohesionCalculation   
)

Definition at line 101 of file test_metrics.cpp.

101 {
102 ASSERT_TRUE(analyzer != nullptr) << "Analyzer is null";
103 ASSERT_FALSE(well_separated_chunks.empty()) << "Well separated chunks is empty";
104 ASSERT_FALSE(mixed_cohesion_chunks.empty()) << "Mixed cohesion chunks is empty";
105
106 try {
107 double high_cohesion = 0.0;
108 double mixed_cohesion = 0.0;
109
110 bool success = analyzer->compare_cohesion(
111 well_separated_chunks,
112 mixed_cohesion_chunks,
113 high_cohesion,
114 mixed_cohesion
115 );
116
117 ASSERT_TRUE(success) << "Cohesion comparison failed";
118 ASSERT_TRUE(std::isfinite(high_cohesion)) << "High cohesion is not finite";
119 ASSERT_TRUE(std::isfinite(mixed_cohesion)) << "Mixed cohesion is not finite";
120
121 EXPECT_GT(high_cohesion, mixed_cohesion)
122 << "High cohesion (" << high_cohesion
123 << ") should be greater than mixed cohesion (" << mixed_cohesion << ")";
124
125 } catch (const std::exception& e) {
126 FAIL() << "Unexpected exception: " << e.what();
127 }
128}

◆ TEST_F() [3/8]

TEST_F ( ChunkMetricsTest  ,
EmptyChunks   
)

Definition at line 179 of file test_metrics.cpp.

179 {
180 std::vector<std::vector<double>> empty_chunks;
181 EXPECT_THROW(analyzer->compute_quality_score(empty_chunks), std::invalid_argument);
182 EXPECT_THROW(analyzer->compute_cohesion(empty_chunks), std::invalid_argument);
183 EXPECT_THROW(analyzer->compute_separation(empty_chunks), std::invalid_argument);
184 EXPECT_THROW(analyzer->compute_silhouette_score(empty_chunks), std::invalid_argument);
185 EXPECT_THROW(analyzer->compute_size_metrics(empty_chunks), std::invalid_argument);
186}

◆ TEST_F() [4/8]

TEST_F ( ChunkMetricsTest  ,
QualityScore   
)

Definition at line 142 of file test_metrics.cpp.

142 {
143 ASSERT_TRUE(analyzer != nullptr);
144
145 try {
146 auto result = run_safely([this]() -> std::pair<double, double> {
147 std::unique_lock<std::mutex> lock(test_mutex_);
148
149 double high_quality = analyzer->compute_quality_score(well_separated_chunks);
150 analyzer->clear_cache();
151 double mixed_quality = analyzer->compute_quality_score(mixed_cohesion_chunks);
152
153 if (!std::isfinite(high_quality) || !std::isfinite(mixed_quality)) {
154 throw std::runtime_error("Invalid quality score results");
155 }
156
157 return std::make_pair(high_quality, mixed_quality);
158 });
159
160 EXPECT_GT(result.first, result.second)
161 << "High quality should be greater than mixed quality";
162 EXPECT_GE(result.first, 0.0) << "Quality score should be non-negative";
163 EXPECT_LE(result.first, 1.0) << "Quality score should not exceed 1.0";
164
165 } catch (const std::exception& e) {
166 FAIL() << "Unexpected exception: " << e.what();
167 }
168}

◆ TEST_F() [5/8]

TEST_F ( ChunkMetricsTest  ,
SeparationCalculation   
)

Definition at line 130 of file test_metrics.cpp.

130 {
131 double separation = analyzer->compute_separation(well_separated_chunks);
132 EXPECT_GT(separation, 0.0);
133 EXPECT_LE(separation, 1.0);
134}

◆ TEST_F() [6/8]

TEST_F ( ChunkMetricsTest  ,
SilhouetteScore   
)

Definition at line 136 of file test_metrics.cpp.

136 {
137 double silhouette = analyzer->compute_silhouette_score(well_separated_chunks);
138 EXPECT_GE(silhouette, -1.0);
139 EXPECT_LE(silhouette, 1.0);
140}

◆ TEST_F() [7/8]

TEST_F ( ChunkMetricsTest  ,
SingleChunk   
)

Definition at line 188 of file test_metrics.cpp.

188 {
189 std::vector<std::vector<double>> single_chunk = {{1.0, 2.0, 3.0}};
190 EXPECT_NO_THROW(analyzer->compute_cohesion(single_chunk));
191 EXPECT_THROW(analyzer->compute_separation(single_chunk), std::invalid_argument);
192 EXPECT_THROW(analyzer->compute_silhouette_score(single_chunk), std::invalid_argument);
193 EXPECT_NO_THROW(analyzer->compute_quality_score(single_chunk));
194}

◆ TEST_F() [8/8]

TEST_F ( ChunkMetricsTest  ,
SizeMetrics   
)

Definition at line 170 of file test_metrics.cpp.

170 {
171 auto metrics = analyzer->compute_size_metrics(well_separated_chunks);
172
173 EXPECT_EQ(metrics["average_size"], 3.0);
174 EXPECT_EQ(metrics["max_size"], 3.0);
175 EXPECT_EQ(metrics["min_size"], 3.0);
176 EXPECT_NEAR(metrics["size_variance"], 0.0, 1e-10);
177}