File: StatisticsDataTest.cpp

package info (click to toggle)
yuview 2.14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,712 kB
  • sloc: cpp: 62,506; python: 788; xml: 54; makefile: 6
file content (79 lines) | stat: -rw-r--r-- 2,342 bytes parent folder | download
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
78
79
#include <QtTest>

#include "statistics/StatisticsData.h"

class StatisticsDataTest : public QObject
{
  Q_OBJECT

public:
  StatisticsDataTest()  = default;
  ~StatisticsDataTest() = default;

private slots:
  void testPixelValueRetrieval1();
  void testPixelValueRetrieval2();
};

void StatisticsDataTest::testPixelValueRetrieval1()
{
  stats::StatisticsData data;

  constexpr auto typeID     = 0;
  constexpr auto frameIndex = 0;

  stats::StatisticsType valueType(
      typeID, "Something", stats::color::ColorMapper({0, 10}, stats::color::PredefinedType::Jet));
  valueType.render = true;
  data.addStatType(valueType);

  QCOMPARE(data.needsLoading(frameIndex), ItemLoadingState::LoadingNeeded);
  QCOMPARE(data.getTypesThatNeedLoading(frameIndex).size(), std::size_t(1));
  QCOMPARE(data.getTypesThatNeedLoading(frameIndex).at(0), typeID);

  // Load data
  data.setFrameIndex(frameIndex);
  data[typeID].addBlockValue(8, 8, 16, 16, 7);

  const auto dataInsideRect = data.getValuesAt(QPoint(10, 12));
  QCOMPARE(dataInsideRect.size(), 1);
  QCOMPARE(dataInsideRect.at(0), QStringPair({"Something", "7"}));

  const auto dataOutside = data.getValuesAt(QPoint(0, 0));
  QCOMPARE(dataOutside.size(), 1);
  QCOMPARE(dataOutside.at(0), QStringPair({"Something", "-"}));
}

void StatisticsDataTest::testPixelValueRetrieval2()
{
  stats::StatisticsData data;

  constexpr auto typeID     = 0;
  constexpr auto frameIndex = 0;

  using VectorScaling = int;
  stats::StatisticsType valueType(typeID, "Something", VectorScaling(4));
  valueType.render = true;
  data.addStatType(valueType);

  QCOMPARE(data.needsLoading(frameIndex), ItemLoadingState::LoadingNeeded);
  QCOMPARE(data.getTypesThatNeedLoading(frameIndex).size(), std::size_t(1));
  QCOMPARE(data.getTypesThatNeedLoading(frameIndex).at(0), typeID);

  // Load data
  data.setFrameIndex(frameIndex);
  data[typeID].addBlockVector(8, 8, 16, 16, 5, 13);

  const auto dataInsideRect = data.getValuesAt(QPoint(10, 12));
  QCOMPARE(dataInsideRect.size(), 1);
  // This is wrong
  QCOMPARE(dataInsideRect.at(0), QStringPair({"Something", "(1.25,3.25)"}));

  const auto dataOutside = data.getValuesAt(QPoint(0, 0));
  QCOMPARE(dataOutside.size(), 1);
  QCOMPARE(dataOutside.at(0), QStringPair({"Something", "-"}));
}

QTEST_MAIN(StatisticsDataTest)

#include "StatisticsDataTest.moc"