Skip to content

Commit 3316150

Browse files
committed
test new pack/unpack functions
1 parent 31df535 commit 3316150

File tree

3 files changed

+371
-18
lines changed

3 files changed

+371
-18
lines changed

tests/symmetry-tests.inc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,41 @@ function testArrayVsSingleSymmetry(array $samples, \Closure $readMethod, \Closur
6565
echo "--- single vs array symmetry: match = " . ($samples === $decodedSingles ? "YES" : "NO") . "\n";
6666
}
6767

68+
function testPackVsNormalSymmetry(array $samples, \Closure $readMethod, \Closure $writeMethod, \Closure $unpackMethod, \Closure $packMethod) : void{
69+
echo "--- single pack vs buffer read symmetry ---\n";
70+
foreach($samples as $sample){
71+
$packed = $packMethod($sample);
72+
73+
$reader = new ByteBufferReader($packed);
74+
$decoded = $readMethod($reader);
75+
76+
echo "($sample): match = " . ($sample === $decoded ? "YES" : "NO") . "\n";
77+
}
78+
echo "--- single buffer write vs unpack symmetry ---\n";
79+
foreach($samples as $sample){
80+
$writer = new ByteBufferWriter();
81+
$writeMethod($writer, $sample);
82+
83+
$data = $writer->getData();
84+
$decoded = $unpackMethod($data);
85+
echo "($sample): match = " . ($sample === $decoded ? "YES" : "NO") . "\n";
86+
}
87+
}
88+
6889
/**
6990
* @phpstan-template TValue
7091
* @phpstan-param TValue[] $samples
7192
* @phpstan-param \Closure(ByteBufferReader):TValue $readMethod
7293
* @phpstan-param \Closure(ByteBufferWriter,TValue):void $writeMethod
7394
* @phpstan-param \Closure(ByteBufferReader,int):array<TValue> $readArrayMethod
7495
* @phpstan-param \Closure(ByteBufferWriter,array<TValue>):void $writeArrayMethod
96+
* @phpstan-param \Closure(string):TValue $unpackMethod
97+
* @phpstan-param \Closure(TValue):string $packMethod
7598
*/
76-
function testFullSymmetry(string $label, array $samples, \Closure $readMethod, \Closure $writeMethod, \Closure $readArrayMethod, \Closure $writeArrayMethod) : void{
99+
function testFullSymmetry(string $label, array $samples, \Closure $readMethod, \Closure $writeMethod, \Closure $readArrayMethod, \Closure $writeArrayMethod, \Closure $unpackMethod, \Closure $packMethod) : void{
77100
echo "########## TEST " . $label . " ##########\n";
78101
testSingleSymmetry($samples, $readMethod, $writeMethod);
102+
testPackVsNormalSymmetry($samples, $readMethod, $writeMethod, $unpackMethod, $packMethod);
79103
testArraySymmetry($samples, $readArrayMethod, $writeArrayMethod);
80104
testArrayVsSingleSymmetry($samples, $readMethod, $writeMethod, $readArrayMethod, $writeArrayMethod);
81105
echo "########## END TEST " . $label . " ##########\n\n";

0 commit comments

Comments
 (0)