-
Notifications
You must be signed in to change notification settings - Fork 19.9k
Create Complex Numbers Utils #5128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5128 +/- ##
============================================
+ Coverage 37.36% 37.52% +0.15%
- Complexity 2350 2374 +24
============================================
Files 517 518 +1
Lines 15618 15671 +53
Branches 2971 2976 +5
============================================
+ Hits 5836 5880 +44
- Misses 9495 9498 +3
- Partials 287 293 +6 ☔ View full report in Codecov by Sentry. |
public static ComplexNumber add(ComplexNumber num1, ComplexNumber num2) { | ||
return new ComplexNumber(num1.REAL + num2.REAL, num1.IMAGINARY + num2.IMAGINARY); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you decide to make it a static
method? In the standard implementation of Complex
add
is an object method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to make it a static method for a few reasons:
Uniformity in Code: The file MatrixUtil.java, which is similar to this, uses static methods for the operations.
Ease of Expansion: Creating independent static methods makes it easier to add more advanced operations for complex numbers than integrating additional code into the ComplexNumber class itself.
Clarity: I find it easier to conceptualize operations as direct interactions between two entities, A and B (i.e., how do you add them), rather than how one adds B to A.
These are my reasons, but if you believe it should be an instance method, I would be happy to make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making them static
you loose all of the object oriented magic. The whole thing could be then simpler, because the ComplexNumberUtil
would not be needed. Furthermore, you have marked both of the fields REAL
and IMAGINARY
as final
, so it is pretty clear that the add
method will not change them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the missing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the defined functions just on single inputs might not be enough. Please express the important tests as parametrized tests. Start first with add
.
Furthermore I would still highly recommend to reach the legendary 100% coverage here.
src/test/java/com/thealgorithms/maths/ComplexNumberUtilTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Piotr Idzik <[email protected]>
Co-authored-by: Piotr Idzik <[email protected]>
95cae76
to
3495410
Compare
Co-authored-by: Piotr Idzik <[email protected]>
Co-authored-by: Piotr Idzik <[email protected]>
6f12753
to
592f443
Compare
There is some build error. Also please update your branch. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution! |
Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution! |
clang-format -i --style=file path/to/your/file.java
Overview
This contribution introduces algorithms for performing arithmetic and trigonometric operations on complex numbers.
Key Features of the Code