Skip to content

Add complex-numbers exercise - #1053

Merged
homersimpsons merged 6 commits into
exercism:mainfrom
resu-xuniL:add-complex-numbers
Sep 25, 2026
Merged

homersimpsons merged 6 commits into
exercism:mainfrom
resu-xuniL:add-complex-numbers

Conversation

@resu-xuniL

@resu-xuniL resu-xuniL commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Hello!
Here is complex-numbers exercise for validation:

  • Generate exercice files with configlet create
  • Create test and example files
  • Set the difficulty rank to 6
  • Add GitHub handle to config.json

Is difficulty rank 6 OK?

I'm not really pleased with the 8 last tests:
I had to create the addR subR mulR divR methods to manage a real number.

I looked how the javascript track managed it: they are passing the real number as a complex number (so they can use only 4 methods, one for each arithmetic operation)

    xtest('Subtract real number from complex number', () => {
      const expected = new ComplexNumber(1, 7);
      const actual = new ComplexNumber(5, 7).sub(new ComplexNumber(4, 0));

      expect(actual.real).toBeCloseTo(expected.real);
      expect(actual.imag).toBeCloseTo(expected.imag);
    });

    xtest('Subtract complex number from real number', () => {
      const expected = new ComplexNumber(-1, -7);
      const actual = new ComplexNumber(4, 0).sub(new ComplexNumber(5, 7));

      expect(actual.real).toBeCloseTo(expected.real);
      expect(actual.imag).toBeCloseTo(expected.imag);
    });

Should we do the same thing? i.e. get rid of the 4 methods I created (the ones finishing with a capital R) and keeping only the 4 methods add sub mul div such as in the Javascript track ?

This would gives:

    public function testOperationsBetweenRealNumbersAndComplexNumbersSubtractRealNumberFromComplexNumber(): void
    {
        $realNumber = new ComplexNumbers(4); // --> instead of: $realNumber = 4;
        $ComplexNumber = new ComplexNumbers(5, 7);
        $expected = new ComplexNumbers(1, 7);

        $this->assertEquals($expected, $ComplexNumber->sub($realNumber));
        // --> instead of: $this->assertEquals($expected, $ComplexNumber->subR($ComplexNumber, $realNumber));
    }


    public function testOperationsBetweenRealNumbersAndComplexNumbersSubtractComplexNumberFromRealNumber(): void
    {
        $realNumber = new ComplexNumbers(4); // --> instead of: $realNumber = 4;
        $ComplexNumber = new ComplexNumbers(5, 7);
        $expected = new ComplexNumbers(-1, -7);

        $this->assertEquals($expected, $realNumber->sub($ComplexNumber)); 
        // --> instead of: $this->assertEquals($expected, $ComplexNumber->subR($realNumber, $ComplexNumber));
    }

What do you think ?

@IsaacG

IsaacG commented Sep 22, 2026

Copy link
Copy Markdown
Member

+cc @exercism/php

@mk-mxp

mk-mxp commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

@IsaacG It's on the radar, but time is scarce...
@resu-xuniL I'll take a look these days, as soon as time is available.

@mk-mxp mk-mxp added x:action/create Work on something from scratch 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/large Large amount of work x:rep/large Large amount of reputation labels Sep 22, 2026
@homersimpsons

homersimpsons commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

About CI:

@IsaacG

IsaacG commented Sep 24, 2026

Copy link
Copy Markdown
Member

Re: i18n, see exercism/problem-specifications#2686

TL;DR: finalize the PR and get approval first. Once it's ready to merge, a label is used to trigger the translation, which should do a bunch of i18n work and clear the CI.

@homersimpsons homersimpsons left a comment •

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.

Everything looks good except for the interface we are proposing to the student. Let's align this with other tracks and it is good to go in my opinion.

Thanks @resu-xuniL

Comment thread exercises/practice/complex-numbers/.meta/example.php Outdated
@homersimpsons homersimpsons added the ready-to-translate The English in this PR is final; queue its translations label Sep 25, 2026
exercism-i18n Bot added a commit to exercism/i18n that referenced this pull request Sep 25, 2026
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@exercism-i18n

exercism-i18n Bot commented Sep 25, 2026

Copy link
Copy Markdown

This PR has been translated 🚀

@homersimpsons
homersimpsons merged commit 602cafe into exercism:main Sep 25, 2026
20 of 21 checks passed
@homersimpsons

homersimpsons commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Merged, thanks @resu-xuniL @IsaacG and @mk-mxp for all your relevant inputs.

Note that I'm rather impressed on how fast the translation went, the French translation looks okay to me exercism/i18n@78e4ebe.

@resu-xuniL
resu-xuniL deleted the add-complex-numbers branch September 25, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-translate The English in this PR is final; queue its translations x:action/create Work on something from scratch x:knowledge/elementary Little Exercism knowledge required x:module/practice-exercise Work on Practice Exercises x:rep/large Large amount of reputation x:size/large Large 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.

4 participants