Skip to content

Variable length quantity#995

Open
A-O-Emmanuel wants to merge 5 commits into
exercism:mainfrom
A-O-Emmanuel:variable-length-quantity
Open

Variable length quantity#995
A-O-Emmanuel wants to merge 5 commits into
exercism:mainfrom
A-O-Emmanuel:variable-length-quantity

Conversation

@A-O-Emmanuel
Copy link
Copy Markdown
Contributor

This PR updates the PHP track implementation of variable-length-quantity to bring it fully in line with the current canonical data from problem-specifications.

✅ Summary of Changes

  1. Ran configlet sync for the exercise
    Updated exercise metadata using:
    configlet sync -u -e variable-length-quantity --yes --docs --filepaths --metadata --tests include

Ensured Markdown instructions and .meta files reflect the latest canonical content.

Resolved the previously unsynced instructions.md.

  1. Cleaned up strict types comments
    Removed unnecessary // strict_types comments from:

Test file

Example solution

Preserved the directive itself (declare(strict_types=1);) as required for PHP track consistency.

Left the comment intact in the student stub file, per track conventions.

  1. Synced test metadata
    Added missing UUIDs to test DocBlocks.

Updated all #[TestDox] annotations to match canonical descriptions exactly.

Ensured every test case corresponds 1:1 with the canonical JSON.

  1. Updated test method names
    Renamed all test methods to reflect the full canonical description for clarity and consistency.

Ensured naming is deterministic and generator‑friendly.

  1. Added exercise to bin/auto-sync.txt
    Inserted variable-length-quantity alphabetically to keep the file properly ordered.

Ensures future syncs will include this exercise automatically.

  1. Reviewed, adjusted, and ordered test cases
    Verified all test cases match canonical order.

Removed outdated patterns and ensured full alignment with current problem-specifications.

Confirmed no missing or duplicated tests.

  1. Added contributor entry
    Added my GitHub handle to .meta/config.json as a contributor to this exercise.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

Copy link
Copy Markdown
Contributor

@mk-mxp mk-mxp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! A lot of decimal to hex conversion to do here. Fixing the numbers should make all tests pass now.

Well, OK, you have to remove the 32 bit limit from the example.php. That was before we could expect people to have 64 bit machines...

#[TestDox('Encode a series of integers, producing a series of bytes. -> asymmetric triple byte')]
public function testEncodeSeriesOfIntegersProducingSeriesOfBytesAsymmetricTripleByte(): void
{
$this->assertEquals([0x87, 0xAB, 0x1C], vlq_encode([0x1D6DC]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([0x87, 0xAB, 0x1C], vlq_encode([0x1D6DC]));
$this->assertEquals([0x87, 0xAB, 0x1C], vlq_encode([0x1D59C]));

$this->assertEquals([0x00], vlq_decode([0x00]));
$this->assertEquals([0x40], vlq_decode([0x40]));
$this->assertEquals([0x7f], vlq_decode([0x7f]));
$this->assertEquals([0x81, 0xD5, 0xEE, 0x04], vlq_encode([0x357F34]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([0x81, 0xD5, 0xEE, 0x04], vlq_encode([0x357F34]));
$this->assertEquals([0x81, 0xD5, 0xEE, 0x04], vlq_encode([0x357704]));

#[TestDox('Encode a series of integers, producing a series of bytes. -> asymmetric quintuple byte')]
public function testEncodeSeriesOfIntegersProducingSeriesOfBytesAsymmetricQuintupleByte(): void
{
$this->assertEquals([0x88, 0xB3, 0x95, 0xC2, 0x05], vlq_encode([0x8665C205]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([0x88, 0xB3, 0x95, 0xC2, 0x05], vlq_encode([0x8665C205]));
$this->assertEquals([0x88, 0xB3, 0x95, 0xC2, 0x05], vlq_encode([0x86656105]));

#[TestDox('Decode a series of bytes, producing a series of integers. -> two bytes')]
public function testDecodeSeriesOfBytesProducingSeriesOfIntegersTwoBytes(): void
{
$this->assertEquals([8192], vlq_decode([0xC0, 0x00]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([8192], vlq_decode([0xC0, 0x00]));
$this->assertEquals([0x2000], vlq_decode([0xC0, 0x00]));

public function testDecodeSeriesOfBytesProducingSeriesOfIntegersThreeBytes(): void
{
$this->expectException(OverflowException::class);
$this->assertEquals([2097151], vlq_decode([0xFF, 0xFF, 0x7F]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([2097151], vlq_decode([0xFF, 0xFF, 0x7F]));
$this->assertEquals([0x1FFFFF], vlq_decode([0xFF, 0xFF, 0x7F]));

#[TestDox('Decode a series of bytes, producing a series of integers. -> four bytes')]
public function testDecodeSeriesOfBytesProducingSeriesOfIntegersFourBytes(): void
{
$this->assertEquals([2097152], vlq_decode([0x81, 0x80, 0x80, 0x00]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([2097152], vlq_decode([0x81, 0x80, 0x80, 0x00]));
$this->assertEquals([0x200000], vlq_decode([0x81, 0x80, 0x80, 0x00]));

0xff, 0xff, 0xff, 0x7f, 0x00,
0xff, 0x7f, 0x81, 0x80, 0x00,
];
$this->assertEquals([4294967295], vlq_decode([0x8F, 0xFF, 0xFF, 0xFF, 0x7F]));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals([4294967295], vlq_decode([0x8F, 0xFF, 0xFF, 0xFF, 0x7F]));
$this->assertEquals([0xFFFFFFFF], vlq_decode([0x8F, 0xFF, 0xFF, 0xFF, 0x7F]));

public function testDecodeSeriesOfBytesProducingSeriesOfIntegersMultipleValues(): void
{
$this->assertEquals(
[8192, 1193046, 268435455, 0, 16383, 16384],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[8192, 1193046, 268435455, 0, 16383, 16384],
[0x2000, 0x123456, 0xFFFFFFF, 0, 0x3FFF, 0x4000],

@mk-mxp mk-mxp added x:action/sync Sync content with its latest version x:knowledge/elementary Little Exercism knowledge required x:module/practice-exercise Work on Practice Exercises x:type/content Work on content (e.g. exercises, concepts) x:size/medium Medium amount of work x:rep/medium Medium amount of reputation labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:action/sync Sync content with its latest version x:knowledge/elementary Little Exercism knowledge required x:module/practice-exercise Work on Practice Exercises x:rep/medium Medium amount of reputation x:size/medium Medium amount of work x:type/content Work on content (e.g. exercises, concepts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants