33 lines
1.5 KiB
C++
33 lines
1.5 KiB
C++
#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"));
|
||
}
|
||
|
||
// 电极浮动框:x(7 位有效数字)/ 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"));
|
||
}
|