Implemented getMetrics()
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
*/
|
||||
void test_initializeReadings_uniform()
|
||||
{
|
||||
initializeReadings(NUMBER_OF_SENSORS, SLIDING_WINDOW_SIZE);
|
||||
initializeReadings(NUMBER_OF_SENSORS, 100);
|
||||
assert(getSensorsNumber() == NUMBER_OF_SENSORS);
|
||||
assert(getSlidingWindowSize() == SLIDING_WINDOW_SIZE);
|
||||
}
|
||||
@@ -237,7 +237,7 @@ void test_freeReadings()
|
||||
*/
|
||||
void test_initializeReadings_normal()
|
||||
{
|
||||
initializeReadings(NUMBER_OF_SENSORS, SLIDING_WINDOW_SIZE);
|
||||
initializeReadings(NUMBER_OF_SENSORS, 100);
|
||||
assert(getSensorsNumber() == NUMBER_OF_SENSORS);
|
||||
assert(getSlidingWindowSize() == SLIDING_WINDOW_SIZE);
|
||||
}
|
||||
@@ -424,6 +424,30 @@ void test_anomalyDetect_normal()
|
||||
assert(fabs(NUMBER_OF_SENSORS * SLIDING_WINDOW_SIZE * 0.05 + 1 >= getOutlierCount())); // Assuming 5% of the data is outliers and adding one more
|
||||
}
|
||||
|
||||
void test_getMetrics()
|
||||
{
|
||||
|
||||
// initialize a matrix of readings
|
||||
float **readings = (float **)malloc(NUMBER_OF_SENSORS * sizeof(float *));
|
||||
for (int i = 0; i < NUMBER_OF_SENSORS; i++)
|
||||
{
|
||||
readings[i] = (float *)malloc(SLIDING_WINDOW_SIZE * sizeof(float));
|
||||
for (int j = 0; j < SLIDING_WINDOW_SIZE; j++)
|
||||
{
|
||||
readings[i][j] = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// get metrics
|
||||
Metrics metrics = getMetrics(readings, NUMBER_OF_SENSORS, SLIDING_WINDOW_SIZE);
|
||||
|
||||
printf("Metrics:\n");
|
||||
printf("Mean: %f\n", metrics.mean);
|
||||
printf("Standard Deviation: %f\n", metrics.standardDeviation);
|
||||
printf("Possible Faulty Sensor: %d\n", metrics.possibleFaultySensor);
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
int tests_run = 0;
|
||||
int tests_passed = 0;
|
||||
@@ -458,6 +482,7 @@ int main() {
|
||||
RUN_TEST(test_overallStandardDeviation_normal);
|
||||
RUN_TEST(test_anomalyDetect_normal);
|
||||
RUN_TEST(test_freeReadings);
|
||||
RUN_TEST(test_getMetrics);
|
||||
|
||||
printf("\n=== Results ===\n");
|
||||
printf("Tests run: %d\n", tests_run);
|
||||
|
||||
Reference in New Issue
Block a user