geopro/tests/app/test_scatter_hover.cpp

33 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <gtest/gtest.h>
#include "panels/chart/ScatterHoverTip.hpp"
using geopro::app::electrodeHoverText;
using geopro::app::measurementHoverText;
using geopro::app::scatterHoverText;
// 对齐原版 Plotly hovertemplate
// <b>X:</b> %{x:.3f}<br><b>Y:</b> %{y:.3f}<br><b>值:</b> %{marker.color:.3f}
TEST(ScatterHoverTip, FormatsXYValueWith3Decimals) {
const QString t = scatterHoverText(12.3456, 24.0, 60.77);
EXPECT_EQ(t, QStringLiteral("<b>X:</b> 12.346<br><b>Y:</b> 24.000<br><b>值:</b> 60.770"));
}
TEST(ScatterHoverTip, RoundsAndPadsToFixed3) {
// 负值、整数、需补零各覆盖一次
EXPECT_EQ(scatterHoverText(-1.0, 0.5, 1.0),
QStringLiteral("<b>X:</b> -1.000<br><b>Y:</b> 0.500<br><b>值:</b> 1.000"));
}
// measurement 浮动框X/Y/Value/a/b/m/n 多行(对齐原版 Plotly 浮动框)。
TEST(ScatterHoverTip, MeasurementFloatingTipShowsXYValueABMN) {
const QString t = measurementHoverText(2.283, -1.2, 242.952988, 1, 4, 2, 3);
EXPECT_EQ(t, QStringLiteral("<b>X:</b> 2.283<br><b>Y:</b> -1.200<br><b>Value:</b> 242.953"
"<br><b>a:</b> 1<br><b>b:</b> 4<br><b>m:</b> 2<br><b>n:</b> 3"));
}
// 电极浮动框x7 位有效数字)/ y: 0 / num电极编号对齐原版 Plotly 电极 trace。
TEST(ScatterHoverTip, ElectrodeFloatingTipShowsXYNum) {
const QString t = electrodeHoverText(5.123837209632222, 4);
EXPECT_EQ(t, QStringLiteral("x: 5.123837<br>y: 0<br>num: 4"));
}