Changeset View
Changeset View
Standalone View
Standalone View
autotests/unit/codecs/positioncodectest.cpp
Show All 29 Lines | |||||
30 | { | 30 | { | ||
31 | Q_OBJECT | 31 | Q_OBJECT | ||
32 | public: | 32 | public: | ||
33 | PositionCodecTest() = default; | 33 | PositionCodecTest() = default; | ||
34 | ~PositionCodecTest() = default; | 34 | ~PositionCodecTest() = default; | ||
35 | private Q_SLOTS: | 35 | private Q_SLOTS: | ||
36 | void initTestCase(); | 36 | void initTestCase(); | ||
37 | void checkEncodeOutput(); | 37 | void checkEncodeOutput(); | ||
38 | void checkEncodeOutput2(); | ||||
39 | void checkEncodeOutput3(); | ||||
38 | private: | 40 | private: | ||
39 | QVector<PositionInfo> m_data; | 41 | QVector<PositionInfo> m_data; | ||
42 | QVector<PositionInfo> m_data2; | ||||
43 | QVector<PositionInfo> m_data3; | ||||
40 | }; | 44 | }; | ||
41 | 45 | | |||
42 | QTEST_MAIN ( PositionCodecTest ) | 46 | QTEST_MAIN ( PositionCodecTest ) | ||
43 | 47 | | |||
44 | void PositionCodecTest::initTestCase() | 48 | void PositionCodecTest::initTestCase() | ||
45 | { | 49 | { | ||
46 | m_data.clear(); | 50 | m_data.clear(); | ||
47 | m_data.reserve(100); | 51 | m_data.reserve(100); | ||
48 | for(int i = 0; i < 100; ++i) | 52 | for(int i = 0; i < 100; ++i) | ||
49 | { | 53 | { | ||
50 | PositionInfo info; | 54 | PositionInfo info; | ||
51 | info.docId = (i + 1) * 4711; | 55 | info.docId = (i + 1) * 4711; | ||
52 | info.positions.reserve(3000); | 56 | info.positions.reserve(3000); | ||
53 | for (int j = 0; j < 3000; j++) | 57 | for (int j = 0; j < 3000; j++) | ||
54 | info.positions.append(((j + 1) * 42) / info.docId); | 58 | info.positions.append((j + 1) * (i * 2)); | ||
55 | m_data.append(info); | 59 | m_data.append(info); | ||
56 | } | 60 | } | ||
61 | | ||||
62 | m_data2.clear(); | ||||
63 | m_data2.reserve(5000); | ||||
64 | for (int i = 0; i < 5000; i++) { | ||||
65 | PositionInfo info; | ||||
66 | info.docId = i; | ||||
67 | info.positions = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||||
68 | | ||||
69 | m_data2.append(info); | ||||
70 | } | ||||
71 | | ||||
72 | m_data3.clear(); | ||||
73 | m_data3.reserve(200); | ||||
74 | for (int i = 0; i < 200; i++) { | ||||
75 | PositionInfo info; | ||||
76 | info.docId = i; | ||||
77 | info.positions.reserve(30000); // > 2^14 -> 3 byte VarInt32 | ||||
78 | for (int j = 0; j < 30000; j++) | ||||
79 | info.positions.append((j + 1) * 200); // increment 200 -> 2 byte DiffVarInt32 | ||||
80 | | ||||
81 | m_data3.append(info); | ||||
82 | } | ||||
57 | } | 83 | } | ||
58 | 84 | | |||
59 | void PositionCodecTest::checkEncodeOutput() | 85 | void PositionCodecTest::checkEncodeOutput() | ||
60 | { | 86 | { | ||
61 | PositionCodec pc; | 87 | PositionCodec pc; | ||
62 | const QByteArray ba = pc.encode(m_data); | 88 | const QByteArray ba = pc.encode(m_data); | ||
63 | QCOMPARE(ba.size(), 301000); | 89 | QCOMPARE(ba.size(), 409000); | ||
64 | const QByteArray md5 = QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex(); | 90 | const QByteArray md5 = QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex(); | ||
65 | QCOMPARE(md5, QByteArray("d44a606d301937bef105411c0ee77a88")); | 91 | QCOMPARE(md5, QByteArray("ae49eb3279bdda36ef91d29ce3c94c2c")); | ||
66 | // and now decode the whole stuff | 92 | // and now decode the whole stuff | ||
67 | QVector<PositionInfo> decodedData = pc.decode(ba); | 93 | QVector<PositionInfo> decodedData = pc.decode(ba); | ||
68 | QCOMPARE(m_data, decodedData); | 94 | QCOMPARE(m_data, decodedData); | ||
69 | } | 95 | } | ||
70 | 96 | | |||
97 | void PositionCodecTest::checkEncodeOutput2() | ||||
98 | { | ||||
99 | PositionCodec pc; | ||||
100 | const QByteArray ba = pc.encode(m_data2); | ||||
101 | QCOMPARE(ba.size(), (8 + 1 + 10) * 5000); // DocId, VarInt32 len, DiffVarInt position | ||||
102 | const QByteArray md5 = QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex(); | ||||
103 | QCOMPARE(md5, QByteArray("2f3710246331002e2332dce560ccd783")); | ||||
104 | // and now decode the whole stuff | ||||
105 | QVector<PositionInfo> decodedData = pc.decode(ba); | ||||
106 | QCOMPARE(m_data2, decodedData); | ||||
107 | } | ||||
108 | | ||||
109 | void PositionCodecTest::checkEncodeOutput3() | ||||
110 | { | ||||
111 | PositionCodec pc; | ||||
112 | const QByteArray ba = pc.encode(m_data3); | ||||
113 | QCOMPARE(ba.size(), (8 + 3 + (2 * 30000)) * 200); // DocId, VarInt32 len, DiffVarInt position | ||||
114 | const QByteArray md5 = QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex(); | ||||
115 | QCOMPARE(md5, QByteArray("79e942003c082073b4cee8e376fffdaa")); | ||||
116 | // and now decode the whole stuff | ||||
117 | QVector<PositionInfo> decodedData = pc.decode(ba); | ||||
118 | QCOMPARE(m_data3, decodedData); | ||||
119 | } | ||||
120 | | ||||
71 | #include "positioncodectest.moc" | 121 | #include "positioncodectest.moc" |