Skip to content

Commit

Permalink
feature/compress-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Raul Mauricio Uñate Castro committed Jul 6, 2024
1 parent e79d9bb commit c45796d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public function testCompress()
$this->assertNotEmpty($valueCompressed, 'The compressed value should not be empty');

// Validate that the size of the compressed data is smaller than the original
$this->assertTrue(Str::length($valueCompressed) < Str::length($exampleInput), 'The compressed size should be smaller than the original size');
$this->assertTrue(strlen($valueCompressed) < strlen($exampleInput), 'The compressed size should be smaller than the original size');
}

public function testDecompress()
Expand Down
18 changes: 12 additions & 6 deletions tests/Support/SupportStringableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,28 +716,34 @@ public function testContainsAll()
public function testCompress()
{
// Example input: a JSON message repeated many times
$exampleInput = $this->stringable(json_encode(['message' => str_repeat('Laravel Framework', 20)]));
$exampleInput = json_encode(['message' => str_repeat('Laravel Framework', 20)]);

// Create a new instance of Stringable with the example input
$stringable = new Stringable($exampleInput);

// Compress the input
$valueCompressed = $exampleInput->compress();
$valueCompressed = $stringable->compress();

// Ensure the compressed value is not empty
$this->assertNotEmpty($valueCompressed, 'The compressed value should not be empty');

// Validate that the size of the compressed data is smaller than the original
$this->assertTrue($this->stringable($valueCompressed)->length() < $this->stringable($exampleInput)->length(), 'The compressed size should be smaller than the original size');
$this->assertTrue(strlen($valueCompressed) < strlen($exampleInput), 'The compressed size should be smaller than the original size');
}

public function testDecompress()
{
// Example input: a JSON message repeated many times
$exampleInput = $this->stringable(json_encode(['message' => str_repeat('Laravel Framework', 20)]));
$exampleInput = json_encode(['message' => str_repeat('Laravel Framework', 20)]);

// Create a new instance of Stringable with the example input
$stringable = new Stringable($exampleInput);

// Compress the input to prepare for decompression test
$valueCompressed = $exampleInput->compress();
$valueCompressed = $stringable->compress();

// Decompress the output
$valueUncompressed = $exampleInput->decompress();
$valueUncompressed = (new Stringable($valueCompressed))->decompress();

// Ensure the decompressed input matches the original
$this->assertEquals($exampleInput, $valueUncompressed, 'The decompressed value should match the original input');
Expand Down

0 comments on commit c45796d

Please sign in to comment.