761417898 commented on code in PR #542:
URL: https://github.com/apache/tsfile/pull/542#discussion_r2209412816


##########
cpp/test/encoding/dictionary_codec_test.cc:
##########
@@ -80,21 +82,69 @@ TEST_F(DictionaryTest, DictionaryEncoderAndDecoder) {
     ASSERT_EQ(decoder.read_string(stream), "apple");
 }
 
-TEST_F(DictionaryTest, DictionaryEncoderAndDecoderLargeQuantities) {
+TEST_F(DictionaryTest, DictionaryEncoderAndDecoderOneItem) {
     DictionaryEncoder encoder;
     common::ByteStream stream(1024, common::MOD_DICENCODE_OBJ);
     encoder.init();
 
-    for (int64_t value = 1; value < 10000; value++) {
-        encoder.encode(std::to_string(value), stream);
+    encoder.encode("apple", stream);
+    encoder.flush(stream);
+
+    DictionaryDecoder decoder;
+    decoder.init();
+
+    ASSERT_TRUE(decoder.has_next(stream));
+    ASSERT_EQ(decoder.read_string(stream), "apple");
+
+    ASSERT_FALSE(decoder.has_next(stream));
+}
+
+TEST_F(DictionaryTest,
+       DictionaryEncoderAndDecoderLargeQuantitiesWithRandomStrings) {
+    DictionaryEncoder encoder;
+    common::ByteStream stream(1024, common::MOD_DICENCODE_OBJ);
+    encoder.init();
+
+    // Prepare random string generator
+    std::random_device rd;
+    std::mt19937 gen(rd());
+    std::uniform_int_distribution<> length_dist(5, 20);  // String length range
+    std::uniform_int_distribution<> char_dist(33,
+                                              126);  // Printable ASCII range
+
+    // Generate 10000 random strings
+    const int num_strings = 10000;
+    std::vector<std::string> test_strings;
+    std::unordered_set<std::string> string_set;  // For ensuring uniqueness
+
+    while (test_strings.size() < num_strings) {
+        int length = length_dist(gen);
+        std::string str;
+        str.reserve(length);
+
+        for (int i = 0; i < length; ++i) {
+            str.push_back(static_cast<char>(char_dist(gen)));
+        }
+
+        // Ensure string uniqueness
+        if (string_set.insert(str).second) {
+            test_strings.push_back(str);
+        }

Review Comment:
   ```
   
   TEST_F(DictionaryTest, DictionaryEncoderAndDecoderRepeatedItem) {
       DictionaryEncoder encoder;
       common::ByteStream stream(1024, common::MOD_DICENCODE_OBJ);
       encoder.init();
       for (char c = 'a'; c <= 'z'; c++) {
           for (int i = 0; i < 100; i++) {
               encoder.encode(std::string(c, 3), stream);
           }
       }
       encoder.flush(stream);
       DictionaryDecoder decoder;
       decoder.init();
       for (char c = 'a'; c <= 'z'; c++) {
           for (int i = 0; i < 100; i++) {
               ASSERT_EQ(decoder.read_string(stream), std::string(c, 3));
           }
       }
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to