-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix the wrong type error of == fuction #9
base: release
Are you sure you want to change the base?
Conversation
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 have a couple suggestions here, plus I think tests should be added.
@@ -177,7 +177,7 @@ class FixedPixelSpaceOrdinalScaleSpec implements OrdinalScaleSpec { | |||
} | |||
|
|||
@override | |||
bool operator ==(Object other) => other is SimpleOrdinalScaleSpec; | |||
bool operator ==(Object other) => other is FixedPixelSpaceOrdinalScaleSpec; |
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 think this should compare not only the type but also any fields defined so something like:
@override
bool operator ==(Object other) {
if (other is FixedPixelSpaceOrdinalScaleSpec) {
return pixelSpaceBetweenBars ==
(other as FixedPixelSpaceOrdinalScaleSpec).pixelSpaceBetweenBars;
} else {
return false;
}
}
@@ -198,7 +198,7 @@ class FixedPixelOrdinalScaleSpec implements OrdinalScaleSpec { | |||
} | |||
|
|||
@override | |||
bool operator ==(Object other) => other is SimpleOrdinalScaleSpec; | |||
bool operator ==(Object other) => other is FixedPixelOrdinalScaleSpec; |
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.
Dito here:
@override
bool operator ==(Object other) {
if (other is FixedPixelOrdinalScaleSpec) {
return pixels == (other as FixedPixelOrdinalScaleSpec).pixels;
} else {
return false;
}
}
@dreamnice, I don't think the I've got a proposal for a test file I suggest it should be placed in a in directory "test/chart/cartesina/axis/spec". Below is a start I think it would be good if we added tests for the other classed in the file:
|
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.
Need to update hashCode methods
@@ -177,7 +177,7 @@ class FixedPixelSpaceOrdinalScaleSpec implements OrdinalScaleSpec { | |||
} | |||
|
|||
@override | |||
bool operator ==(Object other) => other is SimpleOrdinalScaleSpec; | |||
bool operator ==(Object other) => other is FixedPixelSpaceOrdinalScaleSpec; | |||
|
|||
@override | |||
int get hashCode => 37; |
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.
This should return a hashCode based on pixelSpaceBetweenBars since that field is now used in operator ==
.
@@ -198,7 +198,7 @@ class FixedPixelOrdinalScaleSpec implements OrdinalScaleSpec { | |||
} | |||
|
|||
@override | |||
bool operator ==(Object other) => other is SimpleOrdinalScaleSpec; | |||
bool operator ==(Object other) => other is FixedPixelOrdinalScaleSpec; | |||
|
|||
@override | |||
int get hashCode => 37; |
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.
This should return a hashCode based on the pixels field.
FYI: Here's a couple ways I run just one test file:
To run all of the tests in a single project:
And to run all of the tests in charts_cf:
|
Looks good, txs! When you have time, will you be able to add support for hashCode and tests? |
Can you tell me what the hashCode means, I have never used it before. |
Every dart pbject inherits hashCode from Object and is primarily used by HashMap. https://api.dart.dev/stable/2.8.4/dart-core/Object/hashCode.html |
No description provided.