38#include <gtest/gtest.h>
68 char * str =
const_cast<char*
>(text.c_str());
81 EXPECT_EQ(desc.
pos, 0);
82 EXPECT_EQ(desc.
level, 0);
89 EXPECT_EQ(desc.
pos, 5);
90 EXPECT_EQ(desc.
level, 3);
194 EXPECT_NE(
pred,
nullptr);
197 EXPECT_EQ(
pred,
nullptr);
209 EXPECT_TRUE(ss.str().empty());
217 LLINK(&node) =
nullptr;
218 RLINK(&node) =
nullptr;
230 LLINK(&node) =
nullptr;
231 RLINK(&node) =
nullptr;
238 EXPECT_TRUE(
output.find(
"start-prefix") != string::npos);
239 EXPECT_TRUE(
output.find(
"start-key") != string::npos);
240 EXPECT_TRUE(
output.find(
"\"5\"") != string::npos);
241 EXPECT_TRUE(
output.find(
"TAG 0") != string::npos);
249 LLINK(&node) =
nullptr;
250 RLINK(&node) =
nullptr;
256 EXPECT_TRUE(
output.find(
"start-prefix") != string::npos);
257 EXPECT_TRUE(
output.find(
"start-key") != string::npos);
269 LLINK(&node) =
nullptr;
270 RLINK(&node) =
nullptr;
276 EXPECT_TRUE(ss.str().find(
"$\\backslash$n") != string::npos);
284 LLINK(&node) =
nullptr;
285 RLINK(&node) =
nullptr;
291 EXPECT_TRUE(ss.str().find(
"\\$") != string::npos);
299 LLINK(&node) =
nullptr;
300 RLINK(&node) =
nullptr;
306 EXPECT_TRUE(ss.str().find(
"\\&") != string::npos);
314 LLINK(&node) =
nullptr;
315 RLINK(&node) =
nullptr;
321 EXPECT_TRUE(ss.str().find(
"\\#") != string::npos);
329 LLINK(&node) =
nullptr;
330 RLINK(&node) =
nullptr;
336 EXPECT_TRUE(ss.str().find(
"\\%") != string::npos);
344 LLINK(&node) =
nullptr;
345 RLINK(&node) =
nullptr;
351 EXPECT_TRUE(ss.str().find(
"$\\square$") != string::npos);
359 LLINK(&node) =
nullptr;
360 RLINK(&node) =
nullptr;
366 EXPECT_TRUE(ss.str().find(
"$\\backslash$") != string::npos);
374 LLINK(&node) =
nullptr;
375 RLINK(&node) =
nullptr;
381 EXPECT_TRUE(ss.str().find(
"$\\prime\\prime$") != string::npos);
389 LLINK(&node) =
nullptr;
390 RLINK(&node) =
nullptr;
396 EXPECT_TRUE(ss.str().find(
"$\\neg$") != string::npos);
406 LLINK(&node1) =
nullptr;
407 RLINK(&node1) =
nullptr;
408 LLINK(&node2) =
nullptr;
409 RLINK(&node2) =
nullptr;
411 stringstream ss1, ss2;
417 EXPECT_TRUE(ss1.str().find(
"$\\{$") != string::npos);
418 EXPECT_TRUE(ss2.str().find(
"$\\}$") != string::npos);
437 EXPECT_TRUE(
output.find(
"start-prefix") != string::npos);
440 EXPECT_TRUE(
output.find(
"start-key") != string::npos);
443 EXPECT_TRUE(
output.find(
"TAG") != string::npos);
462 EXPECT_TRUE(
output.find(
"start-prefix") != string::npos);
463 EXPECT_TRUE(
output.find(
"start-key") != string::npos);
475 stringstream ss1, ss2;
484 EXPECT_TRUE(ss1.str().find(
"start-prefix") != string::npos);
485 EXPECT_TRUE(ss2.str().find(
"start-prefix") != string::npos);
488 EXPECT_NE(ss1.str(), ss2.str());
511 EXPECT_EQ(
output.substr(0, 12),
"start-prefix");
527 EXPECT_TRUE(
output.find(
"\nstart-key ") != string::npos);
538 LLINK(&node) =
nullptr;
539 RLINK(&node) =
nullptr;
547 EXPECT_TRUE(
output.find(
"TAG 0 \"x\" S 0 -20") != string::npos);
582 root.get_key().second = 3;
590 LLINK(&left) =
nullptr;
591 RLINK(&left) =
nullptr;
592 LLINK(&right) =
nullptr;
593 RLINK(&right) =
nullptr;
602 EXPECT_TRUE(
output.find(
"TAG") != string::npos);
603 EXPECT_TRUE(
output.find(
"\"a\"") != string::npos);
604 EXPECT_TRUE(
output.find(
"\"b\"") != string::npos);
625 LLINK(&node) =
nullptr;
626 RLINK(&node) =
nullptr;
634 EXPECT_FALSE(ss.str().empty());
644 node.
get_key().first =
"verylongsymbolname";
646 LLINK(&node) =
nullptr;
647 RLINK(&node) =
nullptr;
661 LLINK(&node) =
nullptr;
662 RLINK(&node) =
nullptr;
668 EXPECT_TRUE(ss.str().find(
"\"0\"") != string::npos);
675 node.
get_key().second = 1000000;
676 LLINK(&node) =
nullptr;
677 RLINK(&node) =
nullptr;
683 EXPECT_TRUE(ss.str().find(
"\"1000000\"") != string::npos);
692 const char * text =
"hello world";
694 char * str =
const_cast<char*
>(text);
703 EXPECT_TRUE(
output.find(
"start-prefix") != string::npos);
704 EXPECT_TRUE(
output.find(
"start-key") != string::npos);
707 size_t tag_count = 0;
709 while ((pos =
output.find(
"TAG", pos)) != string::npos)
717 EXPECT_GE(tag_count, 1u);
726 ::testing::InitGoogleTest(&argc, argv);
727 return RUN_ALL_TESTS();
Huffman coding for data compression.
Node for binary search tree.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
const size_t & size() const
Returns the cardinality of the set.
Freq_Node *& get_freq_root()
Returns the root of the frequency tree.
BinNode< std::string > *& get_root()
Returns the root of the Huffman decoding tree.
void read_input(char *input, const bool &with_freqs=false)
Read a NUL-terminated character std::string, count frequencies and build the prefix tree.
Huffman_Encoder_Engine create_encoder(const string &text)
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
void destroyRec(Node *&root) noexcept
Free all the memory occupied by the tree root
Huffman tree visualization for btreepic LaTeX package.
void reset_huffman_btreepic_state() noexcept
Reset global state for a new tree processing.
Freq_Node * pred
Predecessor node in level-order traversal.
long double get_offset(size_t index) noexcept
Get safe offset value with bounds checking.
@ NO_OFFSET
No offset applied.
size_t num_digits(const int &n)
Compute number of decimal digits in an integer.
DynMapTree< Freq_Node *, Infix_Desc, Treap > infix_table
Map from node pointer to infix position descriptor.
int minimal_gap
Minimum gap (in nodes) before applying offset adjustment.
void huffman_to_btreepic(Freq_Node *p, const bool with_level_adjust=false)
Generate btreepic specification for a Huffman tree.
std::ostream * output_ptr
Output stream pointer for btreepic commands.
Level_Table level_table
Map from node pointer to level traversal descriptor.
TEST_F(HuffmanBtreepicTest, InfixDescDefaultConstruction)
Descriptor for infix (in-order) traversal position.
Offset offset
Applied offset direction.
int level
Tree level (0 = root)
int pos
In-order position (0-based)
Descriptor for level-order traversal information.
bool is_left
True if this node is a left child.
Freq_Node * level_succ
Next node in level-order traversal.