forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_reporter.cpp
77 lines (60 loc) · 2.28 KB
/
progress_reporter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (C) 2018-2025 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "openvino/frontend/extension/progress_reporter.hpp"
#include <gtest/gtest.h>
#include "openvino/frontend/exception.hpp"
using namespace ov::frontend;
TEST(ProgressReporter_Callables, LambdaReporter) {
const auto lambda = [](float progress, unsigned int total, unsigned int completed) {
EXPECT_NEAR(progress, 0.5, 0.0001);
EXPECT_EQ(total, 100);
EXPECT_EQ(completed, 50);
};
ProgressReporterExtension ext{lambda};
ext.report_progress(0.5, 100, 50);
}
TEST(ProgressReporter_Callables, RvalueLambdaReporter) {
ProgressReporterExtension ext{[](float progress, unsigned int total, unsigned int completed) {
EXPECT_NEAR(progress, 0.5, 0.0001);
EXPECT_EQ(total, 100);
EXPECT_EQ(completed, 50);
}};
ext.report_progress(0.5, 100, 50);
}
TEST(ProgressReporter_Callables, StructReporter) {
struct ProgressConsumer {
void operator()(float progress, unsigned int total, unsigned int completed) {
EXPECT_NEAR(progress, 0.5675, 0.0001);
EXPECT_EQ(total, 37);
EXPECT_EQ(completed, 21);
}
};
ProgressConsumer consumer;
ProgressReporterExtension ext{consumer};
ext.report_progress(0.5675f, 37, 21);
}
namespace {
void function_reporter(float progress, unsigned int total, unsigned int completed) {
EXPECT_NEAR(progress, 0.2574, 0.0001);
EXPECT_EQ(total, 101);
EXPECT_EQ(completed, 26);
}
void reporter_stub(float, unsigned int, unsigned int) {}
} // namespace
TEST(ProgressReporter_Callables, FunctionReporter) {
ProgressReporterExtension ext{function_reporter};
ext.report_progress(0.2574f, 101, 26);
}
TEST(ProgressReporter, ReportMoreStepsThanTotal) {
ProgressReporterExtension ext{reporter_stub};
EXPECT_THROW(ext.report_progress(0.0, 100, 101), ov::frontend::GeneralFailure);
}
TEST(ProgressReporter, ReportMoreThan100Percent) {
ProgressReporterExtension ext{reporter_stub};
EXPECT_THROW(ext.report_progress(1.00001f, 100, 50), ov::frontend::GeneralFailure);
}
TEST(ProgressReporter, ReportLessThanZeroPercent) {
ProgressReporterExtension ext{reporter_stub};
EXPECT_THROW(ext.report_progress(-100.0, 100, 50), ov::frontend::GeneralFailure);
}