overriden == for MeasuredState

This commit is contained in:
Vadim 2023-06-09 23:22:21 +02:00
parent 422ac9d528
commit 7fdacfac37
2 changed files with 26 additions and 5 deletions

View file

@ -1,4 +1,4 @@
abstract class MeteringCommunicationState {
sealed class MeteringCommunicationState {
const MeteringCommunicationState();
}
@ -6,11 +6,11 @@ class InitState extends MeteringCommunicationState {
const InitState();
}
abstract class SourceState extends MeteringCommunicationState {
sealed class SourceState extends MeteringCommunicationState {
const SourceState();
}
abstract class ScreenState extends MeteringCommunicationState {
sealed class ScreenState extends MeteringCommunicationState {
const ScreenState();
}
@ -18,7 +18,7 @@ class MeasureState extends SourceState {
const MeasureState();
}
abstract class MeasuredState extends ScreenState {
sealed class MeasuredState extends ScreenState {
final double? ev100;
const MeasuredState(this.ev100);
@ -26,8 +26,28 @@ abstract class MeasuredState extends ScreenState {
class MeteringInProgressState extends MeasuredState {
const MeteringInProgressState(super.ev100);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is MeteringInProgressState && other.ev100 == ev100;
}
@override
int get hashCode => Object.hash(ev100, runtimeType);
}
class MeteringEndedState extends MeasuredState {
const MeteringEndedState(super.ev100);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is MeteringEndedState && other.ev100 == ev100;
}
@override
int get hashCode => Object.hash(ev100, runtimeType);
}

View file

@ -67,6 +67,8 @@ void main() {
'Multiple consequtive in progress events',
build: () => bloc,
act: (bloc) async {
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(1));
bloc.add(const MeteringInProgressEvent(null));
bloc.add(const MeteringInProgressEvent(null));
@ -75,7 +77,6 @@ void main() {
expect: () => [
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', 1),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', null),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', null),
isA<MeteringInProgressState>().having((state) => state.ev100, 'ev100', 2),
],
);