MCPcopy Create free account
hub / github.com/davisking/dlib / test

Function test

dlib/test/entropy_coder.cpp:30–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 typename decoder
29 >
30 std::string test (
31 const std::string& input
32 )
33 /*!
34 ensures
35 - encodes the data from in and then tries to decode it and returns
36 "" if it was successfully decoded else it returns the decoded string
37 !*/
38 {
39 ostringstream sout;
40 istringstream sin;
41 istringstream in;
42
43
44 in.str(input);
45
46 const unsigned long max_total = 65535;
47
48
49
50
51 unsigned long counts[256];
52 for (int i = 0; i < 256; ++i)
53 {
54 counts[i] = 1;
55 }
56
57
58 encoder e;
59
60
61
62 DLIB_TEST(e.stream_is_set() == false);
63
64 e.set_stream(sout);
65
66 DLIB_TEST(e.stream_is_set() == true);
67 DLIB_TEST(&e.get_stream() == &sout);
68
69 unsigned char ch;
70
71 unsigned long total = 256;
72
73 while (in.read((char*)&ch,1))
74 {
75 if (total > max_total)
76 {
77 total = 0;
78 for (int j = 0; j<256; ++j)
79 {
80 counts[j] >>= 1;
81 if (counts[j] == 0)
82 counts[j] = 1;
83 total += counts[j];
84
85 }
86 }
87

Callers

nothing calls this directly

Calls 6

strMethod · 0.45
readMethod · 0.45
encodeMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected