CameraContainerBloc equality tests

This commit is contained in:
Vadim 2023-06-20 08:26:25 +02:00
parent 33274ad1f6
commit d09b533a2d
3 changed files with 118 additions and 0 deletions

View file

@ -62,4 +62,14 @@ class CameraErrorState extends CameraContainerState {
final CameraErrorType error;
const CameraErrorState(this.error);
@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
if (other.runtimeType != runtimeType) return false;
return other is CameraErrorState && other.error == error;
}
@override
int get hashCode => Object.hash(error, runtimeType);
}

View file

@ -0,0 +1,44 @@
// ignore_for_file: prefer_const_constructors
import 'package:lightmeter/screens/metering/components/camera_container/event_container_camera.dart';
import 'package:test/test.dart';
void main() {
group(
'`ZoomChangedEvent`',
() {
final a = ZoomChangedEvent(1.0);
final b = ZoomChangedEvent(1.0);
final c = ZoomChangedEvent(2.0);
test('==', () {
expect(a == b && b == a, true);
expect(a != c && c != a, true);
expect(b != c && c != b, true);
});
test('hashCode', () {
expect(a.hashCode == b.hashCode, true);
expect(a.hashCode != c.hashCode, true);
expect(b.hashCode != c.hashCode, true);
});
},
);
group(
'`ExposureOffsetChangedEvent`',
() {
final a = ExposureOffsetChangedEvent(1.0);
final b = ExposureOffsetChangedEvent(1.0);
final c = ExposureOffsetChangedEvent(2.0);
test('==', () {
expect(a == b && b == a, true);
expect(a != c && c != a, true);
expect(b != c && c != b, true);
});
test('hashCode', () {
expect(a.hashCode == b.hashCode, true);
expect(a.hashCode != c.hashCode, true);
expect(b.hashCode != c.hashCode, true);
});
},
);
}

View file

@ -0,0 +1,64 @@
// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';
import 'package:lightmeter/screens/metering/components/camera_container/models/camera_error_type.dart';
import 'package:lightmeter/screens/metering/components/camera_container/state_container_camera.dart';
import 'package:test/test.dart';
void main() {
group(
'`CameraActiveState`',
() {
final a = CameraActiveState(
zoomRange: RangeValues(1, 7),
currentZoom: 1,
exposureOffsetRange: RangeValues(-4, 4),
currentExposureOffset: 0,
exposureOffsetStep: 0.167,
);
final b = CameraActiveState(
zoomRange: RangeValues(1, 7),
currentZoom: 1,
exposureOffsetRange: RangeValues(-4, 4),
currentExposureOffset: 0,
exposureOffsetStep: 0.167,
);
final c = CameraActiveState(
zoomRange: RangeValues(1, 4),
currentZoom: 3,
exposureOffsetRange: RangeValues(-2, 2),
currentExposureOffset: 0,
exposureOffsetStep: 0.167,
);
test('==', () {
expect(a == b && b == a, true);
expect(a != c && c != a, true);
expect(b != c && c != b, true);
});
test('hashCode', () {
expect(a.hashCode == b.hashCode, true);
expect(a.hashCode != c.hashCode, true);
expect(b.hashCode != c.hashCode, true);
});
},
);
group(
'`CameraErrorState`',
() {
final a = CameraErrorState(CameraErrorType.noCamerasDetected);
final b = CameraErrorState(CameraErrorType.noCamerasDetected);
final c = CameraErrorState(CameraErrorType.other);
test('==', () {
expect(a == b && b == a, true);
expect(a != c && c != a, true);
expect(b != c && c != b, true);
});
test('hashCode', () {
expect(a.hashCode == b.hashCode, true);
expect(a.hashCode != c.hashCode, true);
expect(b.hashCode != c.hashCode, true);
});
},
);
}