File: test_fingerprint_compressor.cpp

package info (click to toggle)
chromaprint 1.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,676 kB
  • sloc: cpp: 5,976; ansic: 2,521; python: 657; makefile: 167; sh: 93
file content (77 lines) | stat: -rw-r--r-- 2,198 bytes parent folder | download | duplicates (5)
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
#include <gtest/gtest.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include "image.h"
#include "classifier.h"
#include "fingerprint_compressor.h"
#include "utils.h"
#include "test_utils.h"

using namespace chromaprint;

TEST(FingerprintCompressor, OneItemOneBit)
{
	FingerprintCompressor compressor;

	uint32_t fingerprint[] = { 1 };
	std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));

	char expected[] = { 0, 0, 0, 1, 1 };
	CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
}

TEST(FingerprintCompressor, OneItemThreeBits)
{
	FingerprintCompressor compressor;

	uint32_t fingerprint[] = { 7 };
	std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));

	char expected[] = { 0, 0, 0, 1, 73, 0 };
	CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
}

TEST(FingerprintCompressor, OneItemOneBitExcept)
{
	FingerprintCompressor compressor;

	uint32_t fingerprint[] = { 1<<6 };
	std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));

	char expected[] = { 0, 0, 0, 1, 7, 0 };
	CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
}

TEST(FingerprintCompressor, OneItemOneBitExcept2)
{
	FingerprintCompressor compressor;

	uint32_t fingerprint[] = { 1<<8 };
	std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));

	char expected[] = { 0, 0, 0, 1, 7, 2 };
	CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
}

TEST(FingerprintCompressor, TwoItems)
{
	FingerprintCompressor compressor;

	uint32_t fingerprint[] = { 1, 0 };
	std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 2));

	char expected[] = { 0, 0, 0, 2, 65, 0 };
	CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
}

TEST(FingerprintCompressor, TwoItemsNoChange)
{
	FingerprintCompressor compressor;

	uint32_t fingerprint[] = { 1, 1 };
	std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 2));

	char expected[] = { 0, 0, 0, 2, 1, 0 };
	CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
}