Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Convert tests to inline tests & update all structs (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno authored and Redth committed Aug 16, 2018
1 parent 7abdaad commit 459798f
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 337 deletions.
58 changes: 58 additions & 0 deletions Tests/Accelerometer_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Xamarin.Essentials;
using Xunit;

namespace Tests
{
public class Accelerometer_Tests
{
[Fact]
public void Accelerometer_Start() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Accelerometer.Stop());

[Fact]
public void Accelerometer_Stop() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Accelerometer.Start(SensorSpeed.Normal));

[Fact]
public void Accelerometer_IsMonitoring() =>
Assert.False(Accelerometer.IsMonitoring);

[Fact]
public void Accelerometer_IsSupported() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => 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());
}
}
}
}
68 changes: 0 additions & 68 deletions Tests/Acceleromter_Tests.cs

This file was deleted.

63 changes: 33 additions & 30 deletions Tests/Barometer_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,48 @@ namespace Tests
public class Barometer_Tests
{
[Fact]
public void IsSupported_On_NetStandard() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Barometer.IsSupported);

[Fact]
public void Monitor_On_NetStandard() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Barometer.Start(SensorSpeed.UI));
public void Barometer_Start() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Barometer.Stop());

[Fact]
public void Monitor_Off_NetStandard() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Barometer.Stop());
public void Barometer_Stop() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => 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<NotImplementedInReferenceAssemblyException>(() => 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());
}
}
}
}
83 changes: 32 additions & 51 deletions Tests/Compass_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,49 @@ namespace Tests
{
public class Compass_Tests
{
public Compass_Tests()
{
Compass.Stop();
}

[Fact]
public void IsSupported_On_NetStandard() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Compass.IsSupported);

[Fact]
public void Monitor_Null_Handler_On_NetStandard() =>
Assert.Throws<ArgumentNullException>(() => Compass.Start(SensorSpeed.Normal));
public void Compass_Start() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => Compass.Stop());

[Fact]
public void Monitor_On_NetStandard() =>
public void Compass_Stop() =>
Assert.Throws<NotImplementedInReferenceAssemblyException>(() => 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<NotImplementedInReferenceAssemblyException>(() => 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());
}
}
}
}

0 comments on commit 459798f

Please sign in to comment.