-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathZstdTest.php
More file actions
96 lines (68 loc) · 2.6 KB
/
ZstdTest.php
File metadata and controls
96 lines (68 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Utopia\Tests\Storage\Compression\Algorithms;
use PHPUnit\Framework\TestCase;
use Utopia\Storage\Compression\Algorithms\Zstd;
class ZstdTest extends TestCase
{
protected Zstd $object;
public function setUp(): void
{
$this->object = new Zstd();
}
public function tearDown(): void
{
}
public function testName(): void
{
$this->assertEquals($this->object->getName(), 'zstd');
}
public function testCompressDecompressWithText()
{
$demo = 'This is a demo string';
$demoSize = \mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = \mb_strlen($data, '8bit');
$this->assertEquals(21, $demoSize);
$this->assertEquals(30, $dataSize);
$this->assertEquals($demo, $this->object->decompress($data));
}
public function testCompressDecompressWithLargeText()
{
$demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/lorem.txt');
$demoSize = mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($demoSize, 386795);
$this->assertEquals($dataSize, 56324);
$this->assertGreaterThan($dataSize, $demoSize);
$data = $this->object->decompress($data);
$dataSize = mb_strlen($data, '8bit');
$this->assertEquals($dataSize, 386795);
}
public function testCompressDecompressWithJPGImage()
{
$demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/kitten-1.jpg');
$demoSize = \mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = \mb_strlen($data, '8bit');
$this->assertEquals(599639, $demoSize);
$this->assertEquals(599663, $dataSize);
$this->assertGreaterThan($demoSize, $dataSize);
$data = $this->object->decompress($data);
$dataSize = \mb_strlen($data, '8bit');
$this->assertEquals(599639, $dataSize);
}
public function testCompressDecompressWithPNGImage()
{
$demo = \file_get_contents(__DIR__.'/../../../resources/disk-b/kitten-1.png');
$demoSize = \mb_strlen($demo, '8bit');
$data = $this->object->compress($demo);
$dataSize = \mb_strlen($data, '8bit');
$this->assertEquals(3038056, $demoSize);
$this->assertEquals(3038138, $dataSize);
$this->assertGreaterThan($demoSize, $dataSize);
$data = $this->object->decompress($data);
$dataSize = \mb_strlen($data, '8bit');
$this->assertEquals(3038056, $dataSize);
}
}