|
14 | 14 |
|
15 | 15 | #include <gmock/gmock.h> |
16 | 16 | #include <gtest/gtest.h> |
| 17 | +#include "absl/status/status.h" |
| 18 | +#include "absl/strings/cord.h" |
| 19 | +#include <nlohmann/json.hpp> |
17 | 20 | #include "tensorstore/driver/n5/compressor.h" |
18 | | -#include "tensorstore/internal/json_gtest.h" |
19 | | -#include "tensorstore/util/status.h" |
20 | 21 | #include "tensorstore/util/status_testutil.h" |
21 | 22 |
|
22 | 23 | namespace { |
23 | 24 |
|
24 | 25 | using ::tensorstore::MatchesStatus; |
25 | 26 | using ::tensorstore::internal_n5::Compressor; |
26 | 27 |
|
| 28 | +absl::Cord GetInput() { |
| 29 | + return absl::Cord( |
| 30 | + "Sed ut perspiciatis unde omnis iste natus error sit voluptatem " |
| 31 | + "accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae " |
| 32 | + "ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt " |
| 33 | + "explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut " |
| 34 | + "odit aut fugit, sed quia consequuntur magni dolores eos qui ratione " |
| 35 | + "voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum " |
| 36 | + "quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam " |
| 37 | + "eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat " |
| 38 | + "voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam " |
| 39 | + "corporis suscipit laboriosam, nisi ut aliquid ex ea commodi " |
| 40 | + "consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate " |
| 41 | + "velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum " |
| 42 | + "fugiat quo voluptas nulla pariatur?"); |
| 43 | +} |
| 44 | + |
27 | 45 | // Tests that a small input round trips. |
28 | 46 | TEST(ZstdCompressorTest, SmallRoundtrip) { |
29 | 47 | auto compressor = |
30 | 48 | Compressor::FromJson({{"type", "zstd"}, {"level", 6}}).value(); |
31 | | - const absl::Cord input("The quick brown fox jumped over the lazy dog."); |
| 49 | + const absl::Cord input = GetInput(); |
32 | 50 | absl::Cord encode_result, decode_result; |
33 | | - TENSORSTORE_ASSERT_OK(compressor->Encode(input, &encode_result, 1)); |
| 51 | + TENSORSTORE_ASSERT_OK(compressor->Encode(GetInput(), &encode_result, 1)); |
34 | 52 | TENSORSTORE_ASSERT_OK(compressor->Decode(encode_result, &decode_result, 1)); |
35 | 53 | EXPECT_EQ(input, decode_result); |
36 | 54 | } |
37 | 55 |
|
38 | | -// Tests that specifying a level of 1 gives the same result as not specifying a |
| 56 | +// Tests that specifying a level of 3 gives the same result as not specifying a |
39 | 57 | // level. |
40 | 58 | TEST(ZstdCompressorTest, DefaultLevel) { |
41 | 59 | auto compressor1 = Compressor::FromJson({{"type", "zstd"}}).value(); |
42 | 60 | auto compressor2 = |
43 | | - Compressor::FromJson({{"type", "zstd"}, {"level", 1}}).value(); |
44 | | - const absl::Cord input("The quick brown fox jumped over the lazy dog."); |
| 61 | + Compressor::FromJson({{"type", "zstd"}, {"level", 3}}).value(); |
| 62 | + const absl::Cord input = GetInput(); |
45 | 63 | absl::Cord encode_result1, encode_result2; |
46 | 64 | TENSORSTORE_ASSERT_OK(compressor1->Encode(input, &encode_result1, 1)); |
47 | 65 | TENSORSTORE_ASSERT_OK(compressor2->Encode(input, &encode_result2, 1)); |
48 | 66 | EXPECT_EQ(encode_result1, encode_result2); |
49 | 67 | } |
50 | 68 |
|
51 | | -// Tests that specifying a level of 9 works. |
| 69 | +// Tests that the default level is different from level 1. |
52 | 70 | TEST(ZstdCompressorTest, NonDefaultLevel) { |
| 71 | + auto compressor1 = Compressor::FromJson({{"type", "zstd"}}).value(); |
| 72 | + auto compressor2 = |
| 73 | + Compressor::FromJson({{"type", "zstd"}, {"level", 1}}).value(); |
| 74 | + const absl::Cord input = GetInput(); |
| 75 | + absl::Cord encode_result1, encode_result2; |
| 76 | + TENSORSTORE_ASSERT_OK(compressor1->Encode(input, &encode_result1, 1)); |
| 77 | + TENSORSTORE_ASSERT_OK(compressor2->Encode(input, &encode_result2, 1)); |
| 78 | + EXPECT_NE(encode_result1, encode_result2); |
| 79 | +} |
| 80 | + |
| 81 | +// Tests that specifying a level 22 works. |
| 82 | +TEST(ZstdCompressorTest, Level22) { |
53 | 83 | auto compressor = |
54 | | - Compressor::FromJson({{"type", "zstd"}, {"level", 9}}).value(); |
55 | | - const absl::Cord input("The quick brown fox jumped over the lazy dog."); |
| 84 | + Compressor::FromJson({{"type", "zstd"}, {"level", 22}}).value(); |
| 85 | + const absl::Cord input = GetInput(); |
56 | 86 | absl::Cord encode_result; |
57 | 87 | TENSORSTORE_ASSERT_OK(compressor->Encode(input, &encode_result, 1)); |
58 | 88 | absl::Cord decode_result; |
|
0 commit comments