Skip to content

Commit 50ec435

Browse files
committed
refactor performance tests: remove redundant whitespace and improve formatting for better readability
1 parent dea8e28 commit 50ec435

File tree

1 file changed

+46
-47
lines changed

1 file changed

+46
-47
lines changed

modules/performance/tests/perf_tests.cpp

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ TEST(TaskTest, DestructorTerminatesIfWrongOrder) {
282282
DummyTask task;
283283
EXPECT_THROW(task.Run(), std::runtime_error);
284284
}
285-
285+
286286
// Create a new task to complete the lifecycle properly
287287
DummyTask task2;
288288
task2.Validation();
@@ -360,9 +360,7 @@ TEST(PerfTest, GetStringParamNameTest) {
360360
EXPECT_EQ(GetStringParamName(PerfResults::kNone), "none");
361361
}
362362

363-
TEST(PerfTest, DefaultTimerReturnsNegativeOne) {
364-
EXPECT_EQ(DefaultTimer(), -1.0);
365-
}
363+
TEST(PerfTest, DefaultTimerReturnsNegativeOne) { EXPECT_EQ(DefaultTimer(), -1.0); }
366364

367365
TEST(PerfTest, PerfAttrDefaultValues) {
368366
PerfAttr attr;
@@ -386,9 +384,9 @@ TEST(PerfTest, PerfResultsEnumValues) {
386384
TEST(PerfTest, PerfConstructorSetsTaskState) {
387385
auto task_ptr = std::make_shared<DummyTask>();
388386
Perf<int, int> perf(task_ptr);
389-
387+
390388
EXPECT_EQ(task_ptr->GetStateOfTesting(), ppc::task::StateOfTesting::kPerf);
391-
389+
392390
// Complete the task lifecycle to avoid destructor issues
393391
task_ptr->Validation();
394392
task_ptr->PreProcessing();
@@ -399,25 +397,25 @@ TEST(PerfTest, PerfConstructorSetsTaskState) {
399397
TEST(PerfTest, GetPerfResultsReturnsCorrectResults) {
400398
auto task_ptr = std::make_shared<DummyTask>();
401399
Perf<int, int> perf(task_ptr);
402-
400+
403401
// Initially should be default values
404402
auto initial_results = perf.GetPerfResults();
405403
EXPECT_EQ(initial_results.time_sec, 0.0);
406404
EXPECT_EQ(initial_results.type_of_running, PerfResults::kNone);
407-
405+
408406
PerfAttr attr;
409407
double time = 0.0;
410408
attr.current_timer = [&time]() {
411409
double t = time;
412410
time += 0.5;
413411
return t;
414412
};
415-
413+
416414
perf.PipelineRun(attr);
417415
auto pipeline_results = perf.GetPerfResults();
418416
EXPECT_EQ(pipeline_results.type_of_running, PerfResults::kPipeline);
419417
EXPECT_GT(pipeline_results.time_sec, 0.0);
420-
418+
421419
perf.TaskRun(attr);
422420
auto taskrun_results = perf.GetPerfResults();
423421
EXPECT_EQ(taskrun_results.type_of_running, PerfResults::kTaskRun);
@@ -427,83 +425,83 @@ TEST(PerfTest, GetPerfResultsReturnsCorrectResults) {
427425
TEST(PerfTest, CommonRunCalculatesAverageTime) {
428426
auto task_ptr = std::make_shared<DummyTask>();
429427
Perf<int, int> perf(task_ptr);
430-
428+
431429
PerfAttr attr;
432430
int call_count = 0;
433431
attr.num_running = 3;
434432
attr.current_timer = [&call_count]() {
435433
if (call_count == 0) {
436434
call_count++;
437-
return 0.0; // Start time
435+
return 0.0; // Start time
438436
} else {
439-
return 3.0; // End time after 3 runs
437+
return 3.0; // End time after 3 runs
440438
}
441439
};
442-
440+
443441
perf.PipelineRun(attr);
444442
auto results = perf.GetPerfResults();
445-
443+
446444
// Total time should be 3 seconds, average should be 1 second (3.0 - 0.0) / 3
447445
EXPECT_DOUBLE_EQ(results.time_sec, 1.0);
448446
}
449447

450448
TEST(PerfTest, PrintPerfStatisticPipelineOutput) {
451449
auto task_ptr = std::make_shared<DummyTask>();
452450
Perf<int, int> perf(task_ptr);
453-
451+
454452
PerfAttr attr;
455453
double time = 0.0;
456454
attr.current_timer = [&time]() {
457455
double t = time;
458456
time += 0.1;
459457
return t;
460458
};
461-
459+
462460
perf.PipelineRun(attr);
463-
461+
464462
testing::internal::CaptureStdout();
465463
perf.PrintPerfStatistic("test_pipeline");
466464
std::string output = testing::internal::GetCapturedStdout();
467-
465+
468466
EXPECT_NE(output.find("test_pipeline:pipeline:"), std::string::npos);
469-
EXPECT_NE(output.find("0.0200000000"), std::string::npos); // 0.1/5 = 0.02
467+
EXPECT_NE(output.find("0.0200000000"), std::string::npos); // 0.1/5 = 0.02
470468
}
471469

472470
TEST(PerfTest, PrintPerfStatisticTaskRunOutput) {
473471
auto task_ptr = std::make_shared<DummyTask>();
474472
Perf<int, int> perf(task_ptr);
475-
473+
476474
PerfAttr attr;
477475
double time = 0.0;
478476
attr.current_timer = [&time]() {
479477
double t = time;
480478
time += 0.25;
481479
return t;
482480
};
483-
481+
484482
perf.TaskRun(attr);
485-
483+
486484
testing::internal::CaptureStdout();
487485
perf.PrintPerfStatistic("test_taskrun");
488486
std::string output = testing::internal::GetCapturedStdout();
489-
487+
490488
EXPECT_NE(output.find("test_taskrun:task_run:"), std::string::npos);
491489
}
492490

493491
TEST(PerfTest, PrintPerfStatisticThrowsOnExceedingMaxTime) {
494492
auto task_ptr = std::make_shared<DummyTask>();
495493
Perf<int, int> perf(task_ptr);
496-
494+
497495
PerfAttr attr;
498496
double time = 0.0;
499497
attr.current_timer = [&time]() {
500498
double t = time;
501-
time += 55.0; // Exceeds kMaxTime (10.0)
499+
time += 55.0; // Exceeds kMaxTime (10.0)
502500
return t;
503501
};
504-
502+
505503
perf.PipelineRun(attr);
506-
504+
507505
testing::internal::CaptureStdout();
508506
try {
509507
perf.PrintPerfStatistic("test_exceed_time");
@@ -523,73 +521,74 @@ TEST(PerfTest, TaskRunCompletesPipelineAfterTiming) {
523521
int preprocessing_count = 0;
524522
int run_count = 0;
525523
int postprocessing_count = 0;
526-
524+
527525
// Create a custom task that counts method calls
528526
class CountingTask : public Task<int, int> {
529527
public:
530528
int* validation_count_;
531529
int* preprocessing_count_;
532530
int* run_count_;
533531
int* postprocessing_count_;
534-
535-
CountingTask(int* vc, int* pc, int* rc, int* ppc)
532+
533+
CountingTask(int* vc, int* pc, int* rc, int* ppc)
536534
: validation_count_(vc), preprocessing_count_(pc), run_count_(rc), postprocessing_count_(ppc) {}
537-
535+
538536
bool ValidationImpl() override {
539537
(*validation_count_)++;
540538
return true;
541539
}
542-
540+
543541
bool PreProcessingImpl() override {
544542
(*preprocessing_count_)++;
545543
return true;
546544
}
547-
545+
548546
bool RunImpl() override {
549547
(*run_count_)++;
550548
return true;
551549
}
552-
550+
553551
bool PostProcessingImpl() override {
554552
(*postprocessing_count_)++;
555553
return true;
556554
}
557555
};
558-
559-
auto counting_task = std::make_shared<CountingTask>(&validation_count, &preprocessing_count, &run_count, &postprocessing_count);
556+
557+
auto counting_task =
558+
std::make_shared<CountingTask>(&validation_count, &preprocessing_count, &run_count, &postprocessing_count);
560559
Perf<int, int> counting_perf(counting_task);
561-
560+
562561
PerfAttr attr;
563562
attr.num_running = 1;
564-
563+
565564
counting_perf.TaskRun(attr);
566-
565+
567566
// TaskRun should call:
568567
// 1. Validation + PreProcessing + Run (num_running times) + PostProcessing
569568
// 2. Validation + PreProcessing + Run + PostProcessing (one additional complete cycle)
570569
EXPECT_EQ(validation_count, 2); // Called twice
571-
EXPECT_EQ(preprocessing_count, 2); // Called twice
570+
EXPECT_EQ(preprocessing_count, 2); // Called twice
572571
EXPECT_EQ(run_count, 2); // Called twice (once in timing, once in final cycle)
573572
EXPECT_EQ(postprocessing_count, 2); // Called twice
574573
}
575574

576575
namespace test_namespace {
577576
struct TestType {};
578-
}
577+
} // namespace test_namespace
579578

580579
TEST(PerfTest, TemplateInstantiationWithDifferentTypes) {
581580
// Test that Perf template can be instantiated with different types
582581
auto int_task = std::make_shared<DummyTask>();
583582
Perf<int, int> int_perf(int_task);
584-
583+
585584
auto vector_task = std::make_shared<ppc::test::TestPerfTask<std::vector<int>, int>>(std::vector<int>{1, 2, 3});
586585
Perf<std::vector<int>, int> vector_perf(vector_task);
587-
586+
588587
PerfAttr attr;
589-
588+
590589
EXPECT_NO_THROW(int_perf.PipelineRun(attr));
591590
EXPECT_NO_THROW(vector_perf.PipelineRun(attr));
592-
591+
593592
EXPECT_EQ(int_perf.GetPerfResults().type_of_running, PerfResults::kPipeline);
594593
EXPECT_EQ(vector_perf.GetPerfResults().type_of_running, PerfResults::kPipeline);
595594
}
@@ -598,7 +597,7 @@ TEST(PerfTest, PerfAttrCustomValues) {
598597
PerfAttr attr;
599598
attr.num_running = 10;
600599
attr.current_timer = []() { return 42.0; };
601-
600+
602601
EXPECT_EQ(attr.num_running, 10U);
603602
EXPECT_EQ(attr.current_timer(), 42.0);
604603
}

0 commit comments

Comments
 (0)