src/net/tools/huffman_trie/huffman/huffman_builder_unittest.cc
TEST(HuffmanBuilderTest, OptimalCodeOrder) {
  HuffmanBuilder builder;
  HuffmanRepresentationTable encoding;
  for (uint8_t i = 0; i <= 127; i++) {
    for (uint8_t j = 0; j <= (i + 1); j++) {
      builder.RecordUsage(i);
    }
  }

  encoding = builder.ToTable();
  for (uint8_t i = 0; i <= 127; i++) {
    // The representation for |i| should be longer or have the same length as
    // all following representations because they have a higher frequency and
    // therefor should never get a longer representation.
    for (uint8_t j = i; j <= 127; j++) {
      // A representation for the values should exist in the table.
      ASSERT_NE(encoding.find(i), encoding.cend());
      ASSERT_NE(encoding.find(j), encoding.cend());

      EXPECT_GE(encoding[i].number_of_bits, encoding[j].number_of_bits);
    }
  }
}
// Test that the representations have optimal order by checking that characters
// with higher counts get shorter (or equal length) representations than those
// with lower counts.
Test that the representations have optimal order by checking that characters
with higher counts get shorter (or equal length) representations than those
with lower counts.
Test that the representations have optimal order by checking that characters with higher counts get shorter ( or equal length ) representations than those with lower counts .
TEST(HuffmanBuilderTest, OptimalCodeOrder) {
  HuffmanBuilder builder;
  HuffmanRepresentationTable encoding;
  for (uint8_t i = 0; i <= 127; i++) {
    for (uint8_t j = 0; j <= (i + 1); j++) {
      builder.RecordUsage(i);
    }
  }
  encoding = builder.ToTable();
  for (uint8_t i = 0; i <= 127; i++) {
    for (uint8_t j = i; j <= 127; j++) {
      ASSERT_NE(encoding.find(i), encoding.cend());
      ASSERT_NE(encoding.find(j), encoding.cend());
      EXPECT_GE(encoding[i].number_of_bits, encoding[j].number_of_bits);
    }
  }
}
TEST ( HuffmanBuilderTest , OptimalCodeOrder ) { HuffmanBuilder builder ; HuffmanRepresentationTable encoding ; for ( uint8_t i = 0 ; i <= 127 ; i ++ ) { for ( uint8_t j = 0 ; j <= ( i + 1 ) ; j ++ ) { builder . RecordUsage ( i ) ; } } encoding = builder . ToTable ( ) ; for ( uint8_t i = 0 ; i <= 127 ; i ++ ) { for ( uint8_t j = i ; j <= 127 ; j ++ ) { ASSERT_NE ( encoding . find ( i ) , encoding . cend ( ) ) ; ASSERT_NE ( encoding . find ( j ) , encoding . cend ( ) ) ; EXPECT_GE ( encoding [ i ] . number_of_bits , encoding [ j ] . number_of_bits ) ; } } }
Test that the representations have optimal order by checking that characters
with higher counts get shorter (or equal length) representations than those
with lower counts.
Test that the representations have optimal order by checking that characters with higher counts get shorter ( or equal length ) representations than those with lower counts .
// The representation for |i| should be longer or have the same length as // all following representations because they have a higher frequency and // therefor should never get a longer representation. // A representation for the values should exist in the table.