-
-
Notifications
You must be signed in to change notification settings - Fork 40
Refactor: Separate Out Complex Conjugation Tests #245
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
Changes from all commits
8967e82
c6fec7d
9b521e0
e6c24f1
84d694d
23837de
3a910d4
999182f
6f2d341
c4d89b2
93dd8a0
0e8b48f
3fcf89b
cadac64
99b6c0a
1f6365b
50ee46d
f5e66f1
d677792
4d022ca
fba37a1
1948769
6307f89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -389,60 +389,6 @@ PMComplexTest >> testHash [ | |
| self assert: aComplex copy hash equals: aComplex hash | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem like refactoring. |
||
| PMComplexTest >> testIsComplexConjugateOfConjugateComplex [ | ||
|
|
||
| self assert: ((3 + 2i) isComplexConjugateOf: (3 - 2i)) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfConjugateComplexAndReal [ | ||
|
|
||
| self assert: ((5 + 0i) isComplexConjugateOf: 5) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfConjugateRealAndComplex [ | ||
|
|
||
| self assert: (5 isComplexConjugateOf: (5 - 0i)) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfDifferentReal [ | ||
|
|
||
| self deny: (-5 isComplexConjugateOf: 5) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfNonConjugateComplexAndReal [ | ||
|
|
||
| self deny: ((5 + 3i) isComplexConjugateOf: 5) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfNonConjugateDifferentComplex [ | ||
|
|
||
| self deny: ((-0.5 - 1i) isComplexConjugateOf: (3 - 2i)) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfNonConjugateRealAndComplex [ | ||
|
|
||
| self deny: (5 isComplexConjugateOf: (5 - 3i)) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfSameComplex [ | ||
|
|
||
| self deny: ((3 - 2i) isComplexConjugateOf: (3 - 2i)) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexConjugateOfSameReal [ | ||
|
|
||
| self assert: (5 isComplexConjugateOf: 5) | ||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testIsComplexNumberOnComplex [ | ||
|
|
||
|
|
@@ -783,6 +729,72 @@ PMComplexTest >> testTanh [ | |
| self assert: (c2 imaginary closeTo: c tanh imaginary). | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugateHasEqualRealPartAndAnImaginaryPartWithEqualMagnitudeButOppositeSign [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those long test names are very hard to read even if I can see all of it (and System Browser will hide most of the name because of the window size). I really prefer this name: Why?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bit more to complex conjugation e.g. it is distributive over the binary operations for example hence: I would say but if you insist I'm happy to go with what you suggest.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, there is the value or idea of Tests as documentation c.f. XUnit Test Patterns by Géerard Mezsaros |
||
| | z | | ||
| z := 3 + 2 i. | ||
|
|
||
| self assert: z complexConjugate equals: 3 - 2 i | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the code would be more readable if we don't create a variable here: self assert: (3 + 2i) complexConjugate equals: (3 - 2i).Complex numbers are native to Pharo, they should be used like any other numbers. | a b |
a := 4.
b := -4.
self assert: a negated equals: b.I would just write self assert: 4 negated equals: -4So the same logic should apply to complex numbers
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To sum up, I propose the following: testComplexConjugate
self assert: (3 + 2i) complexConjugate equals: (3 - 2i).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method with that name already exists but it is not good... testComplexConjugate
| z complexConjugateOfZ expected |
z := 5 - 6 i.
complexConjugateOfZ := z complexConjugate .
expected := 5 + 6 i.
self assert: complexConjugateOfZ equals: expected.I propose to replace it with a more readable one-line version: testComplexConjugate
self assert: (5 - 6i) complexConjugate equals: (5 + 6i).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will open a separate issue for that
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Issue #246 |
||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugateOfAPureRealNumberIsItself [ | ||
| | z | | ||
| z := 5 + 0 i. | ||
|
|
||
| self assert: z complexConjugate equals: 5. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not good. First, the same comment about test name as above. Second, about the temporary variable, same comment as above - I would not use it because it is unnecessary and make the code harder to read (of course, this is subjective). Third (!), this test is misleading. The reason why this test passes is because I would do the following:
NumberTest >> testComplexConjugate
self assert: 5 complexConjugate equals: 5 |
||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugationIsAnInvolution [ | ||
| | z | | ||
| z := -9 + 24 i. | ||
|
|
||
| self assert: z complexConjugate complexConjugate equals: -9 + 24 i | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugationIsDistributiveOverAddition [ | ||
| | z w | | ||
| z := -3 + 6 i. | ||
| w := 10 - 4 i. | ||
|
|
||
| self assert: (z + w) complexConjugate equals: (z complexConjugate + w complexConjugate) | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugationIsDistributiveOverDivision [ | ||
| | z w | | ||
| z := 6 - 15 i. | ||
| w := 10 + 5 i. | ||
|
|
||
| self assert: (z / w) complexConjugate equals: (z complexConjugate / w complexConjugate) | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugationIsNotSymmetric [ | ||
| | z | | ||
| z := 3 - 2 i. | ||
|
|
||
| self deny: z complexConjugate equals: z | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatComplexConjugationPreservesModulus [ | ||
| | z | | ||
| z := 3 - 4 i. | ||
|
|
||
| self assert: z complexConjugate abs equals: 5 | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testThatTwoEntirelyDifferentComplexNumbersAreNotComplexConjugatesOfEachOther [ | ||
| | z | | ||
| z := -0.5 - 1 i. | ||
|
|
||
| self deny: z complexConjugate equals: (3 - 2i) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove ALL those tests. There is no need to pollute the code with 6 tests that can not possibly fail (a) if |
||
| ] | ||
|
|
||
| { #category : #tests } | ||
| PMComplexTest >> testTimesPolynomial [ | ||
| | c poly | | ||
|
|
@@ -810,6 +822,22 @@ PMComplexTest >> testTwoComplexNumbersWithDifferentRealPartsAreNotEqual [ | |
| self deny: z equals: w. | ||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testWeCanIdentifyTwoComplexNumbersAsBeingComplexConjugatesOfEachOther [ | ||
| | z | | ||
| z := 3 - 2 i. | ||
|
|
||
| self assert: (z isComplexConjugateOf: (3 + 2 i)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the same reasons as discussed above, I would name this test testIsComplexConjugateOf
self assert: ((3 - 2i) isComplexConjugateOf: (3 + 2i)).But this was already in the tests that you propose to remove. Also, look at those tests that you propose to remove... they cover many important scenario:
If we keep the |
||
| ] | ||
|
|
||
| { #category : #'testing - complex conjugation' } | ||
| PMComplexTest >> testWeCanIdentifyTwoComplexNumbersAsNotBeingComplexConjugatesOfEachOther [ | ||
| | z | | ||
| z := -4 - 8 i. | ||
|
|
||
| self deny: (z isComplexConjugateOf: 13 + 12 i) | ||
| ] | ||
|
|
||
| { #category : #'testing - expressing complex numbers' } | ||
| PMComplexTest >> testWeCanWriteComplexNumbersWhoseRealAndImaginaryPartsAreFractions [ | ||
| | z | | ||
|
|
||
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.
Does this need to a method? It's only used by a Matrix to check it is Hermitian. I don't feel it's needed. Is there evidence to the contrary?
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.
Yes, this method is needed for double dispatch.
I added it in this commit: 7d77acf
The idea is that both
NumberandPMComplexshould answer to the messageisComplexConjugateOf:Because we need to apply it to matrices where we do not know if the values are real or complex
That being said, perhaps, we could simply define a
complexConjugatemethod for theNumberclassIt would always return self
Then instead of
isComplexConjugateOf:insidePMMatrix >> isHermitian, we could writenumber = otherNumber complexConjugateI will open a separate issue for that
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.
Issue #247