Code inspections

This commit is contained in:
2019-10-01 20:57:49 +01:00
parent 23960d8c7c
commit babb2a7492
6 changed files with 95 additions and 71 deletions
@@ -1154,33 +1154,33 @@ namespace Meade.net.Telescope.UnitTests
switch (axis)
{
case TelescopeAxes.axisPrimary:
if (rate == 0)
switch (rate.Compare(0))
{
case ComparisonResult.Equals:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qe#"), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qw#"), Times.Once);
}
else if (rate > 0)
{
break;
case ComparisonResult.Greater:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Me#"), Times.Once);
}
else
{
break;
case ComparisonResult.Lower:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mw#"), Times.Once);
break;
}
break;
case TelescopeAxes.axisSecondary:
if (rate == 0)
switch (rate.Compare(0))
{
case ComparisonResult.Equals:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qn#"), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qs#"), Times.Once);
}
else if (rate > 0)
{
break;
case ComparisonResult.Greater:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mn#"), Times.Once);
}
else
{
break;
case ComparisonResult.Lower:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Ms#"), Times.Once);
break;
}
break;
default:
+9
View File
@@ -0,0 +1,9 @@
namespace ASCOM.Meade.net
{
public enum ComparisonResult
{
Lower,
Equals,
Greater
}
}
+13
View File
@@ -10,5 +10,18 @@ namespace ASCOM.Meade.net
return false;
return true;
}
public static ComparisonResult Compare(this double value, double comparison)
{
var result = value.CompareTo(comparison);
if (result < 0)
return ComparisonResult.Lower;
if (result == 0)
return ComparisonResult.Equals;
return ComparisonResult.Greater;
}
}
}
@@ -118,6 +118,7 @@
<Compile Include="AstroMaths\EquatorialCoordinates.cs" />
<Compile Include="AstroMaths\HorizonCoordinates.cs" />
<Compile Include="AstroMaths\IAstroMaths.cs" />
<Compile Include="ComparisonResult.cs" />
<Compile Include="DoubleExtensions.cs" />
<Compile Include="StringExtensions.cs" />
<Compile Include="Telescope.cs" />
+19 -18
View File
@@ -1290,8 +1290,9 @@ namespace ASCOM.Meade.net
switch (axis)
{
case TelescopeAxes.axisPrimary:
if (rate == 0)
switch (rate.Compare(0))
{
case ComparisonResult.Equals:
_movingPrimary = false;
_sharedResourcesWrapper.SendBlind("#:Qe#");
//:Qe# Halt eastward Slews
@@ -1299,26 +1300,26 @@ namespace ASCOM.Meade.net
_sharedResourcesWrapper.SendBlind("#:Qw#");
//:Qw# Halt westward Slews
//Returns: Nothing
}
else if (rate > 0)
{
break;
case ComparisonResult.Greater:
_sharedResourcesWrapper.SendBlind("#:Me#");
//:Me# Move Telescope East at current slew rate
//Returns: Nothing
_movingPrimary = true;
}
else
{
break;
case ComparisonResult.Lower:
_sharedResourcesWrapper.SendBlind("#:Mw#");
//:Mw# Move Telescope West at current slew rate
//Returns: Nothing
_movingPrimary = true;
break;
}
break;
case TelescopeAxes.axisSecondary:
if (rate == 0)
switch (rate.Compare(0))
{
case ComparisonResult.Equals:
_movingSecondary = false;
_sharedResourcesWrapper.SendBlind("#:Qn#");
//:Qn# Halt northward Slews
@@ -1326,20 +1327,20 @@ namespace ASCOM.Meade.net
_sharedResourcesWrapper.SendBlind("#:Qs#");
//:Qs# Halt southward Slews
//Returns: Nothing
}
else if (rate > 0)
{
break;
case ComparisonResult.Greater:
_sharedResourcesWrapper.SendBlind("#:Mn#");
//:Mn# Move Telescope North at current slew rate
//Returns: Nothing
_movingSecondary = true;
}
else
{
break;
case ComparisonResult.Lower:
_sharedResourcesWrapper.SendBlind("#:Ms#");
//:Ms# Move Telescope South at current slew rate
//Returns: Nothing
_movingSecondary = true;
break;
}
break;
@@ -1857,7 +1858,7 @@ namespace ASCOM.Meade.net
{
CheckConnected("SlewToTargetAsync");
if (TargetDeclination == InvalidParameter || TargetRightAscension == InvalidParameter)
if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter))
throw new InvalidOperationException("No target selected to slew to.");
DoSlewAsync(true);
@@ -1938,7 +1939,7 @@ namespace ASCOM.Meade.net
{
get
{
if (_targetDeclination == InvalidParameter)
if (_targetDeclination.Equals(InvalidParameter))
throw new InvalidOperationException("Target not set");
//var result = SerialPort.CommandTerminated("#:Gd#", "#");
@@ -1993,7 +1994,7 @@ namespace ASCOM.Meade.net
{
get
{
if (_targetRightAscension == InvalidParameter)
if (_targetRightAscension.Equals(InvalidParameter))
throw new InvalidOperationException("Target not set");
//var result = SerialPort.CommandTerminated("#:Gr#", "#");
+1 -1
View File
@@ -11,6 +11,6 @@
<ShowUnexecutedTestsMenuOption>true</ShowUnexecutedTestsMenuOption>
<ShowIgnoredTestsMenuOption>false</ShowIgnoredTestsMenuOption>
</TestsWindowMenuOptions>
<TestsWindowSplitterDistance>451</TestsWindowSplitterDistance>
<TestsWindowSplitterDistance>544</TestsWindowSplitterDistance>
</Settings>
</SolutionConfiguration>