diff --git a/Tests/Accelerometer_Tests.cs b/Tests/Accelerometer_Tests.cs new file mode 100644 index 000000000..de8d6a893 --- /dev/null +++ b/Tests/Accelerometer_Tests.cs @@ -0,0 +1,58 @@ +using Xamarin.Essentials; +using Xunit; + +namespace Tests +{ + public class Accelerometer_Tests + { + [Fact] + public void Accelerometer_Start() => + Assert.Throws(() => Accelerometer.Stop()); + + [Fact] + public void Accelerometer_Stop() => + Assert.Throws(() => Accelerometer.Start(SensorSpeed.Normal)); + + [Fact] + public void Accelerometer_IsMonitoring() => + Assert.False(Accelerometer.IsMonitoring); + + [Fact] + public void Accelerometer_IsSupported() => + Assert.Throws(() => Accelerometer.IsSupported); + + [Theory] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true)] + [InlineData(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, false)] + public void Accelerometer_Comparison( + float x1, + float y1, + float z1, + float x2, + float y2, + float z2, + bool equals) + { + var data1 = new AccelerometerData(x1, y1, z1); + var data2 = new AccelerometerData(x2, y2, z2); + if (equals) + { + Assert.True(data1.Equals(data2)); + Assert.True(data1 == data2); + Assert.False(data1 != data2); + Assert.Equal(data1, data2); + Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); + } + else + { + Assert.False(data1.Equals(data2)); + Assert.False(data1 == data2); + Assert.True(data1 != data2); + Assert.NotEqual(data1, data2); + Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); + } + } + } +} diff --git a/Tests/Acceleromter_Tests.cs b/Tests/Acceleromter_Tests.cs deleted file mode 100644 index 0dc0c1055..000000000 --- a/Tests/Acceleromter_Tests.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Xamarin.Essentials; -using Xunit; - -namespace Tests -{ - public class Accelerometer_Tests - { - public Accelerometer_Tests() - { - Accelerometer.Stop(); - } - - [Fact] - public void IsSupported_On_NetStandard() => - Assert.Throws(() => Accelerometer.IsSupported); - - [Fact] - public void Monitor_On_NetStandard() => - Assert.Throws(() => Accelerometer.Start(SensorSpeed.Normal)); - - [Fact] - public void IsMonitoring_Default_On_NetStandard() => - Assert.False(Accelerometer.IsMonitoring); - - [Fact] - public void AccelerometerData_Equals_AreSameCopy() - { - var data = new AccelerometerData(0, 0, 0); - var copy = data; - var res = data.Equals(copy); - Assert.True(res); - } - - [Fact] - public void AccelerometerData_Equals_AreSameValues() - { - var data = new AccelerometerData(0, 0, 0); - var copy = new AccelerometerData(0, 0, 0); - Assert.True(data.Equals(copy)); - } - - [Fact] - public void AccelerometerData_Equals_AreDifferent() - { - var data = new AccelerometerData(0, 0, 0); - var copy = new AccelerometerData(0, 0, 1); - Assert.False(data.Equals(copy)); - } - - [Fact] - public void AccelerometerData_Equals_Operator_AreSameValues() - { - var data = new AccelerometerData(0, 0, 0); - var copy = new AccelerometerData(0, 0, 0); - Assert.True(data == copy); - Assert.False(data != copy); - } - - [Fact] - public void AccelerometerData_Equals_Operator_AreDifferent() - { - var data = new AccelerometerData(0, 0, 0); - var copy = new AccelerometerData(0, 0, 1); - Assert.False(data == copy); - Assert.True(data != copy); - } - } -} diff --git a/Tests/Barometer_Tests.cs b/Tests/Barometer_Tests.cs index 0ae1053a9..d6e0ca4dd 100644 --- a/Tests/Barometer_Tests.cs +++ b/Tests/Barometer_Tests.cs @@ -7,45 +7,48 @@ namespace Tests public class Barometer_Tests { [Fact] - public void IsSupported_On_NetStandard() => - Assert.Throws(() => Barometer.IsSupported); - - [Fact] - public void Monitor_On_NetStandard() => - Assert.Throws(() => Barometer.Start(SensorSpeed.UI)); + public void Barometer_Start() => + Assert.Throws(() => Barometer.Stop()); [Fact] - public void Monitor_Off_NetStandard() => - Assert.Throws(() => Barometer.Stop()); + public void Barometer_Stop() => + Assert.Throws(() => Barometer.Start(SensorSpeed.Normal)); [Fact] - public void IsMonitoring_Default_On_NetStandard() => + public void Barometer_IsMonitoring() => Assert.False(Barometer.IsMonitoring); [Fact] - public void BarometerData_Comparison_Equal() - { - var device1 = new BarometerData(0); - var device2 = new BarometerData(0); - - Assert.True(device1.Equals(device2)); - Assert.True(device1 == device2); - Assert.False(device1 != device2); - Assert.Equal(device1, device2); - Assert.Equal(device1.GetHashCode(), device2.GetHashCode()); - } + public void Barometer_IsSupported() => + Assert.Throws(() => Barometer.IsSupported); - [Fact] - public void BarometerData_Comparison_NotEqual() + [Theory] + [InlineData(0.0, 0.0, true)] + [InlineData(0.0, 1.0, false)] + public void BarometerData_Comparison( + double pressure1, + double pressure2, + bool equals) { - var device1 = new BarometerData(0); - var device2 = new BarometerData(1); - - Assert.False(device1.Equals(device2)); - Assert.False(device1 == device2); - Assert.True(device1 != device2); - Assert.NotEqual(device1, device2); - Assert.NotEqual(device1.GetHashCode(), device2.GetHashCode()); + var data1 = new BarometerData(pressure1); + var data2 = new BarometerData(pressure2); + + if (equals) + { + Assert.True(data1.Equals(data2)); + Assert.True(data1 == data2); + Assert.False(data1 != data2); + Assert.Equal(data1, data2); + Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); + } + else + { + Assert.False(data1.Equals(data2)); + Assert.False(data1 == data2); + Assert.True(data1 != data2); + Assert.NotEqual(data1, data2); + Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); + } } } } diff --git a/Tests/Compass_Tests.cs b/Tests/Compass_Tests.cs index d9a15f450..2b29772b8 100644 --- a/Tests/Compass_Tests.cs +++ b/Tests/Compass_Tests.cs @@ -6,68 +6,49 @@ namespace Tests { public class Compass_Tests { - public Compass_Tests() - { - Compass.Stop(); - } - - [Fact] - public void IsSupported_On_NetStandard() => - Assert.Throws(() => Compass.IsSupported); - [Fact] - public void Monitor_Null_Handler_On_NetStandard() => - Assert.Throws(() => Compass.Start(SensorSpeed.Normal)); + public void Compass_Start() => + Assert.Throws(() => Compass.Stop()); [Fact] - public void Monitor_On_NetStandard() => + public void Compass_Stop() => Assert.Throws(() => Compass.Start(SensorSpeed.Normal)); [Fact] - public void IsMonitoring_Default_On_NetStandard() => + public void Compass_IsMonitoring() => Assert.False(Compass.IsMonitoring); [Fact] - public void CompassData_Equals_AreSameCopy() - { - var data = new CompassData(0); - var copy = data; - var res = data.Equals(copy); - Assert.True(res); - } - - [Fact] - public void CompassData_Equals_AreSameValues() - { - var data = new CompassData(0); - var copy = new CompassData(0); - Assert.True(data.Equals(copy)); - } - - [Fact] - public void CompassData_Equals_AreDifferent() - { - var data = new CompassData(0); - var copy = new CompassData(1); - Assert.False(data.Equals(copy)); - } - - [Fact] - public void CompassData_Equals_Operator_AreSameValues() - { - var data = new CompassData(0); - var copy = new CompassData(0); - Assert.True(data == copy); - Assert.False(data != copy); - } + public void Compass_IsSupported() => + Assert.Throws(() => Compass.IsSupported); - [Fact] - public void CompassData_Equals_Operator_AreDifferent() + [Theory] + [InlineData(0.0, 0.0, true)] + [InlineData(0.0, 1.0, false)] + public void CompassData_Comparison( + double heading1, + double heading2, + bool equals) { - var data = new CompassData(0); - var copy = new CompassData(1); - Assert.False(data == copy); - Assert.True(data != copy); + var data1 = new CompassData(heading1); + var data2 = new CompassData(heading2); + + if (equals) + { + Assert.True(data1.Equals(data2)); + Assert.True(data1 == data2); + Assert.False(data1 != data2); + Assert.Equal(data1, data2); + Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); + } + else + { + Assert.False(data1.Equals(data2)); + Assert.False(data1 == data2); + Assert.True(data1 != data2); + Assert.NotEqual(data1, data2); + Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); + } } } } diff --git a/Tests/Gyroscope_Tests.cs b/Tests/Gyroscope_Tests.cs index 18745c56d..52079cf6b 100644 --- a/Tests/Gyroscope_Tests.cs +++ b/Tests/Gyroscope_Tests.cs @@ -5,64 +5,54 @@ namespace Tests { public class Gyroscope_Tests { - public Gyroscope_Tests() - { - Gyroscope.Stop(); - } - [Fact] - public void IsSupported_On_NetStandard() => - Assert.Throws(() => Gyroscope.IsSupported); + public void Gyroscope_Start() => + Assert.Throws(() => Gyroscope.Stop()); [Fact] - public void Monitor_On_NetStandard() => + public void Gyroscope_Stop() => Assert.Throws(() => Gyroscope.Start(SensorSpeed.Normal)); [Fact] - public void IsMonitoring_Default_On_NetStandard() => + public void Gyroscope_IsMonitoring() => Assert.False(Gyroscope.IsMonitoring); [Fact] - public void GyroscopeData_Equals_AreSameCopy() - { - var data = new GyroscopeData(0, 0, 0); - var copy = data; - var res = data.Equals(copy); - Assert.True(res); - } - - [Fact] - public void GyroscopeData_Equals_AreSameValues() - { - var data = new GyroscopeData(0, 0, 0); - var copy = new GyroscopeData(0, 0, 0); - Assert.True(data.Equals(copy)); - } - - [Fact] - public void GyroscopeData_Equals_AreDifferent() - { - var data = new GyroscopeData(0, 0, 0); - var copy = new GyroscopeData(0, 0, 1); - Assert.False(data.Equals(copy)); - } - - [Fact] - public void GyroscopeData_Equals_Operator_AreSame() - { - var data = new GyroscopeData(0, 0, 0); - var copy = new GyroscopeData(0, 0, 0); - Assert.True(data == copy); - Assert.False(data != copy); - } - - [Fact] - public void GyroscopeData_Equals_Operator_AreDifferent() + public void Gyroscope_IsSupported() => + Assert.Throws(() => Gyroscope.IsSupported); + + [Theory] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true)] + [InlineData(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, false)] + public void GyroscopeData_Comparison( + float x1, + float y1, + float z1, + float x2, + float y2, + float z2, + bool equals) { - var data = new GyroscopeData(0, 0, 0); - var copy = new GyroscopeData(0, 0, 1); - Assert.False(data == copy); - Assert.True(data != copy); + var data1 = new GyroscopeData(x1, y1, z1); + var data2 = new GyroscopeData(x2, y2, z2); + if (equals) + { + Assert.True(data1.Equals(data2)); + Assert.True(data1 == data2); + Assert.False(data1 != data2); + Assert.Equal(data1, data2); + Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); + } + else + { + Assert.False(data1.Equals(data2)); + Assert.False(data1 == data2); + Assert.True(data1 != data2); + Assert.NotEqual(data1, data2); + Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); + } } } } diff --git a/Tests/Magnetometer_Tests.cs b/Tests/Magnetometer_Tests.cs index 7981a508e..59e788022 100644 --- a/Tests/Magnetometer_Tests.cs +++ b/Tests/Magnetometer_Tests.cs @@ -5,64 +5,54 @@ namespace Tests { public class Magnetometer_Tests { - public Magnetometer_Tests() - { - Magnetometer.Stop(); - } - [Fact] - public void IsSupported_On_NetStandard() => - Assert.Throws(() => Magnetometer.IsSupported); + public void Magnetometer_Start() => + Assert.Throws(() => Magnetometer.Stop()); [Fact] - public void Monitor_On_NetStandard() => + public void Magnetometer_Stop() => Assert.Throws(() => Magnetometer.Start(SensorSpeed.Normal)); [Fact] - public void IsMonitoring_Default_On_NetStandard() => + public void Magnetometer_IsMonitoring() => Assert.False(Magnetometer.IsMonitoring); [Fact] - public void MagnetometerData_Equals_AreSameCopy() - { - var data = new MagnetometerData(0, 0, 0); - var copy = data; - var res = data.Equals(copy); - Assert.True(res); - } - - [Fact] - public void MagnetometerData_Equals_AreSameValues() - { - var data = new MagnetometerData(0, 0, 0); - var copy = new MagnetometerData(0, 0, 0); - Assert.True(data.Equals(copy)); - } - - [Fact] - public void MagnetometerData_Equals_AreDifferent() - { - var data = new MagnetometerData(0, 0, 0); - var copy = new MagnetometerData(0, 0, 1); - Assert.False(data.Equals(copy)); - } - - [Fact] - public void MagnetometerData_Equals_Operator_AreSameValues() - { - var data = new MagnetometerData(0, 0, 0); - var copy = new MagnetometerData(0, 0, 0); - Assert.True(data == copy); - Assert.False(data != copy); - } + public void Magnetometer_IsSupported() => + Assert.Throws(() => Magnetometer.IsSupported); - [Fact] - public void MagnetometerData_Equals_Operator_AreDifferent() + [Theory] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true)] + [InlineData(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, false)] + public void MagnetometerData_Comparison( + float x1, + float y1, + float z1, + float x2, + float y2, + float z2, + bool equals) { - var data = new MagnetometerData(0, 0, 0); - var copy = new MagnetometerData(0, 0, 1); - Assert.False(data == copy); - Assert.True(data != copy); + var data1 = new MagnetometerData(x1, y1, z1); + var data2 = new MagnetometerData(x2, y2, z2); + if (equals) + { + Assert.True(data1.Equals(data2)); + Assert.True(data1 == data2); + Assert.False(data1 != data2); + Assert.Equal(data1, data2); + Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); + } + else + { + Assert.False(data1.Equals(data2)); + Assert.False(data1 == data2); + Assert.True(data1 != data2); + Assert.NotEqual(data1, data2); + Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); + } } } } diff --git a/Tests/OrientationSensor_Tests.cs b/Tests/OrientationSensor_Tests.cs index 1c3e16f9a..64262309c 100644 --- a/Tests/OrientationSensor_Tests.cs +++ b/Tests/OrientationSensor_Tests.cs @@ -6,46 +6,56 @@ namespace Tests public class OrientationSensor_Tests { [Fact] - public void OrientationSensorData_Equals_AreSameCopy() - { - var data = new OrientationSensorData(0, 0, 0, 0); - var copy = data; - var res = data.Equals(copy); - Assert.True(res); - } + public void OrientationSensor_Start() => + Assert.Throws(() => OrientationSensor.Stop()); [Fact] - public void OrientationSensorData_Equals_AreSameValues() - { - var data = new OrientationSensorData(0, 0, 0, 0); - var copy = new OrientationSensorData(0, 0, 0, 0); - Assert.True(data.Equals(copy)); - } + public void OrientationSensor_Stop() => + Assert.Throws(() => OrientationSensor.Start(SensorSpeed.Normal)); [Fact] - public void OrientationSensorData_Equals_AreDifferent() - { - var data = new OrientationSensorData(0, 0, 0, 0); - var copy = new OrientationSensorData(0, 0, 0, 1); - Assert.False(data.Equals(copy)); - } + public void OrientationSensor_IsMonitoring() => + Assert.False(OrientationSensor.IsMonitoring); [Fact] - public void OrientationSensorData_Equals_Operator_AreSameValues() - { - var data = new OrientationSensorData(0, 0, 0, 0); - var copy = new OrientationSensorData(0, 0, 0, 0); - Assert.True(data == copy); - Assert.False(data != copy); - } + public void OrientationSensor_IsSupported() => + Assert.Throws(() => OrientationSensor.IsSupported); - [Fact] - public void OrientationSensorData_Equals_Operator_AreDifferent() + [Theory] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, true)] + [InlineData(0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, false)] + [InlineData(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, false)] + public void OrientationSensorData_Comparison( + float x1, + float y1, + float z1, + float w1, + float x2, + float y2, + float z2, + float w2, + bool equals) { - var data = new OrientationSensorData(0, 0, 0, 0); - var copy = new OrientationSensorData(0, 0, 0, 1); - Assert.False(data == copy); - Assert.True(data != copy); + var data1 = new OrientationSensorData(x1, y1, z1, w1); + var data2 = new OrientationSensorData(x2, y2, z2, w2); + if (equals) + { + Assert.True(data1.Equals(data2)); + Assert.True(data1 == data2); + Assert.False(data1 != data2); + Assert.Equal(data1, data2); + Assert.Equal(data1.GetHashCode(), data2.GetHashCode()); + } + else + { + Assert.False(data1.Equals(data2)); + Assert.False(data1 == data2); + Assert.True(data1 != data2); + Assert.NotEqual(data1, data2); + Assert.NotEqual(data1.GetHashCode(), data2.GetHashCode()); + } } } } diff --git a/Xamarin.Essentials/Accelerometer/Accelerometer.shared.cs b/Xamarin.Essentials/Accelerometer/Accelerometer.shared.cs index e1cfaaccd..71526d47a 100644 --- a/Xamarin.Essentials/Accelerometer/Accelerometer.shared.cs +++ b/Xamarin.Essentials/Accelerometer/Accelerometer.shared.cs @@ -85,16 +85,11 @@ internal AccelerometerData(float x, float y, float z) => public Vector3 Acceleration { get; } - public override bool Equals(object obj) - { - if (obj == null) - return false; - if (!(obj is AccelerometerData compassData)) - return false; - return Equals(compassData); - } + public override bool Equals(object obj) => + (obj is AccelerometerData data) && Equals(data); - public bool Equals(AccelerometerData other) => Acceleration.Equals(other.Acceleration); + public bool Equals(AccelerometerData other) => + Acceleration.Equals(other.Acceleration); public static bool operator ==(AccelerometerData left, AccelerometerData right) => Equals(left, right); @@ -102,6 +97,7 @@ public override bool Equals(object obj) public static bool operator !=(AccelerometerData left, AccelerometerData right) => !Equals(left, right); - public override int GetHashCode() => Acceleration.GetHashCode(); + public override int GetHashCode() => + Acceleration.GetHashCode(); } } diff --git a/Xamarin.Essentials/Barometer/Barometer.shared.cs b/Xamarin.Essentials/Barometer/Barometer.shared.cs index 4488cca10..0e8d03fa1 100644 --- a/Xamarin.Essentials/Barometer/Barometer.shared.cs +++ b/Xamarin.Essentials/Barometer/Barometer.shared.cs @@ -86,16 +86,8 @@ internal BarometerData(double pressure) => public static bool operator !=(BarometerData left, BarometerData right) => !Equals(left, right); - public override bool Equals(object obj) - { - if (obj == null) - return false; - - if (!(obj is BarometerData barometerData)) - return false; - - return Equals(barometerData); - } + public override bool Equals(object obj) => + (obj is BarometerData data) && Equals(data); public bool Equals(BarometerData other) => Pressure.Equals(other.Pressure); diff --git a/Xamarin.Essentials/Compass/Compass.shared.cs b/Xamarin.Essentials/Compass/Compass.shared.cs index 52ed4b9aa..4670d0323 100644 --- a/Xamarin.Essentials/Compass/Compass.shared.cs +++ b/Xamarin.Essentials/Compass/Compass.shared.cs @@ -82,16 +82,11 @@ internal CompassData(double headingMagneticNorth) => public double HeadingMagneticNorth { get; } - public override bool Equals(object obj) - { - if (obj == null) - return false; - if (!(obj is CompassData compassData)) - return false; - return Equals(compassData); - } + public override bool Equals(object obj) => + (obj is CompassData data) && Equals(data); - public bool Equals(CompassData other) => HeadingMagneticNorth.Equals(other.HeadingMagneticNorth); + public bool Equals(CompassData other) => + HeadingMagneticNorth.Equals(other.HeadingMagneticNorth); public static bool operator ==(CompassData left, CompassData right) => Equals(left, right); @@ -99,6 +94,7 @@ public override bool Equals(object obj) public static bool operator !=(CompassData left, CompassData right) => !Equals(left, right); - public override int GetHashCode() => HeadingMagneticNorth.GetHashCode(); + public override int GetHashCode() => + HeadingMagneticNorth.GetHashCode(); } } diff --git a/Xamarin.Essentials/Gyroscope/Gyroscope.shared.cs b/Xamarin.Essentials/Gyroscope/Gyroscope.shared.cs index f2f6302db..b7e75d046 100644 --- a/Xamarin.Essentials/Gyroscope/Gyroscope.shared.cs +++ b/Xamarin.Essentials/Gyroscope/Gyroscope.shared.cs @@ -86,16 +86,11 @@ internal GyroscopeData(float x, float y, float z) => public Vector3 AngularVelocity { get; } - public override bool Equals(object obj) - { - if (obj == null) - return false; - if (!(obj is GyroscopeData compassData)) - return false; - return Equals(compassData); - } + public override bool Equals(object obj) => + (obj is GyroscopeData data) && Equals(data); - public bool Equals(GyroscopeData other) => AngularVelocity.Equals(other.AngularVelocity); + public bool Equals(GyroscopeData other) => + AngularVelocity.Equals(other.AngularVelocity); public static bool operator ==(GyroscopeData left, GyroscopeData right) => Equals(left, right); @@ -103,6 +98,7 @@ public override bool Equals(object obj) public static bool operator !=(GyroscopeData left, GyroscopeData right) => !Equals(left, right); - public override int GetHashCode() => AngularVelocity.GetHashCode(); + public override int GetHashCode() => + AngularVelocity.GetHashCode(); } } diff --git a/Xamarin.Essentials/Magnetometer/Magnetometer.shared.cs b/Xamarin.Essentials/Magnetometer/Magnetometer.shared.cs index d2ec9f7f9..890314ea5 100644 --- a/Xamarin.Essentials/Magnetometer/Magnetometer.shared.cs +++ b/Xamarin.Essentials/Magnetometer/Magnetometer.shared.cs @@ -86,16 +86,11 @@ internal MagnetometerData(float x, float y, float z) => public Vector3 MagneticField { get; } - public override bool Equals(object obj) - { - if (obj == null) - return false; - if (!(obj is MagnetometerData compassData)) - return false; - return Equals(compassData); - } + public override bool Equals(object obj) => + (obj is MagnetometerData data) && Equals(data); - public bool Equals(MagnetometerData other) => MagneticField.Equals(other.MagneticField); + public bool Equals(MagnetometerData other) => + MagneticField.Equals(other.MagneticField); public static bool operator ==(MagnetometerData left, MagnetometerData right) => Equals(left, right); @@ -103,6 +98,7 @@ public override bool Equals(object obj) public static bool operator !=(MagnetometerData left, MagnetometerData right) => !Equals(left, right); - public override int GetHashCode() => MagneticField.GetHashCode(); + public override int GetHashCode() => + MagneticField.GetHashCode(); } } diff --git a/Xamarin.Essentials/OrientationSensor/OrientationSensor.shared.cs b/Xamarin.Essentials/OrientationSensor/OrientationSensor.shared.cs index 9d78282c4..028c014c7 100644 --- a/Xamarin.Essentials/OrientationSensor/OrientationSensor.shared.cs +++ b/Xamarin.Essentials/OrientationSensor/OrientationSensor.shared.cs @@ -86,23 +86,19 @@ internal OrientationSensorData(float x, float y, float z, float w) => public Quaternion Orientation { get; } - public override bool Equals(object obj) - { - if (obj == null) - return false; - if (!(obj is OrientationSensorData compassData)) - return false; - return Equals(compassData); - } + public override bool Equals(object obj) => + (obj is OrientationSensorData data) && Equals(data); - public bool Equals(OrientationSensorData other) => Orientation.Equals(other.Orientation); + public bool Equals(OrientationSensorData other) => + Orientation.Equals(other.Orientation); public static bool operator ==(OrientationSensorData left, OrientationSensorData right) => - Equals(left, right); + Equals(left, right); public static bool operator !=(OrientationSensorData left, OrientationSensorData right) => !Equals(left, right); - public override int GetHashCode() => Orientation.GetHashCode(); + public override int GetHashCode() => + Orientation.GetHashCode(); } }