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) switch (axis)
{ {
case TelescopeAxes.axisPrimary: case TelescopeAxes.axisPrimary:
if (rate == 0) switch (rate.Compare(0))
{ {
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qe#"), Times.Once); case ComparisonResult.Equals:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qw#"), Times.Once); _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); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Me#"), Times.Once);
} break;
else case ComparisonResult.Lower:
{ _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mw#"), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mw#"), Times.Once); break;
} }
break; break;
case TelescopeAxes.axisSecondary: case TelescopeAxes.axisSecondary:
if (rate == 0) switch (rate.Compare(0))
{ {
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qn#"), Times.Once); case ComparisonResult.Equals:
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Qs#"), Times.Once); _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); _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Mn#"), Times.Once);
} break;
else case ComparisonResult.Lower:
{ _sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Ms#"), Times.Once);
_sharedResourcesWrapperMock.Verify(x => x.SendBlind("#:Ms#"), Times.Once); break;
} }
break; break;
default: 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 false;
return true; 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\EquatorialCoordinates.cs" />
<Compile Include="AstroMaths\HorizonCoordinates.cs" /> <Compile Include="AstroMaths\HorizonCoordinates.cs" />
<Compile Include="AstroMaths\IAstroMaths.cs" /> <Compile Include="AstroMaths\IAstroMaths.cs" />
<Compile Include="ComparisonResult.cs" />
<Compile Include="DoubleExtensions.cs" /> <Compile Include="DoubleExtensions.cs" />
<Compile Include="StringExtensions.cs" /> <Compile Include="StringExtensions.cs" />
<Compile Include="Telescope.cs" /> <Compile Include="Telescope.cs" />
+49 -48
View File
@@ -1290,56 +1290,57 @@ namespace ASCOM.Meade.net
switch (axis) switch (axis)
{ {
case TelescopeAxes.axisPrimary: case TelescopeAxes.axisPrimary:
if (rate == 0) switch (rate.Compare(0))
{ {
_movingPrimary = false; case ComparisonResult.Equals:
_sharedResourcesWrapper.SendBlind("#:Qe#"); _movingPrimary = false;
//:Qe# Halt eastward Slews _sharedResourcesWrapper.SendBlind("#:Qe#");
//Returns: Nothing //:Qe# Halt eastward Slews
_sharedResourcesWrapper.SendBlind("#:Qw#"); //Returns: Nothing
//:Qw# Halt westward Slews _sharedResourcesWrapper.SendBlind("#:Qw#");
//Returns: Nothing //: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
{
_sharedResourcesWrapper.SendBlind("#:Mw#");
//:Mw# Move Telescope West at current slew rate
//Returns: Nothing
_movingPrimary = true;
}
_sharedResourcesWrapper.SendBlind("#:Me#");
//:Me# Move Telescope East at current slew rate
//Returns: Nothing
_movingPrimary = true;
break;
case ComparisonResult.Lower:
_sharedResourcesWrapper.SendBlind("#:Mw#");
//:Mw# Move Telescope West at current slew rate
//Returns: Nothing
_movingPrimary = true;
break;
}
break; break;
case TelescopeAxes.axisSecondary: case TelescopeAxes.axisSecondary:
if (rate == 0) switch (rate.Compare(0))
{ {
_movingSecondary = false; case ComparisonResult.Equals:
_sharedResourcesWrapper.SendBlind("#:Qn#"); _movingSecondary = false;
//:Qn# Halt northward Slews _sharedResourcesWrapper.SendBlind("#:Qn#");
//Returns: Nothing //:Qn# Halt northward Slews
_sharedResourcesWrapper.SendBlind("#:Qs#"); //Returns: Nothing
//:Qs# Halt southward Slews _sharedResourcesWrapper.SendBlind("#:Qs#");
//Returns: Nothing //:Qs# Halt southward Slews
} //Returns: Nothing
else if (rate > 0) break;
{ case ComparisonResult.Greater:
_sharedResourcesWrapper.SendBlind("#:Mn#"); _sharedResourcesWrapper.SendBlind("#:Mn#");
//:Mn# Move Telescope North at current slew rate //:Mn# Move Telescope North at current slew rate
//Returns: Nothing //Returns: Nothing
_movingSecondary = true; _movingSecondary = true;
} break;
else case ComparisonResult.Lower:
{ _sharedResourcesWrapper.SendBlind("#:Ms#");
_sharedResourcesWrapper.SendBlind("#:Ms#"); //:Ms# Move Telescope South at current slew rate
//:Ms# Move Telescope South at current slew rate //Returns: Nothing
//Returns: Nothing _movingSecondary = true;
_movingSecondary = true; break;
} }
break; break;
@@ -1857,7 +1858,7 @@ namespace ASCOM.Meade.net
{ {
CheckConnected("SlewToTargetAsync"); CheckConnected("SlewToTargetAsync");
if (TargetDeclination == InvalidParameter || TargetRightAscension == InvalidParameter) if (TargetDeclination.Equals(InvalidParameter) || TargetRightAscension.Equals(InvalidParameter))
throw new InvalidOperationException("No target selected to slew to."); throw new InvalidOperationException("No target selected to slew to.");
DoSlewAsync(true); DoSlewAsync(true);
@@ -1938,7 +1939,7 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
if (_targetDeclination == InvalidParameter) if (_targetDeclination.Equals(InvalidParameter))
throw new InvalidOperationException("Target not set"); throw new InvalidOperationException("Target not set");
//var result = SerialPort.CommandTerminated("#:Gd#", "#"); //var result = SerialPort.CommandTerminated("#:Gd#", "#");
@@ -1993,7 +1994,7 @@ namespace ASCOM.Meade.net
{ {
get get
{ {
if (_targetRightAscension == InvalidParameter) if (_targetRightAscension.Equals(InvalidParameter))
throw new InvalidOperationException("Target not set"); throw new InvalidOperationException("Target not set");
//var result = SerialPort.CommandTerminated("#:Gr#", "#"); //var result = SerialPort.CommandTerminated("#:Gr#", "#");
+1 -1
View File
@@ -11,6 +11,6 @@
<ShowUnexecutedTestsMenuOption>true</ShowUnexecutedTestsMenuOption> <ShowUnexecutedTestsMenuOption>true</ShowUnexecutedTestsMenuOption>
<ShowIgnoredTestsMenuOption>false</ShowIgnoredTestsMenuOption> <ShowIgnoredTestsMenuOption>false</ShowIgnoredTestsMenuOption>
</TestsWindowMenuOptions> </TestsWindowMenuOptions>
<TestsWindowSplitterDistance>451</TestsWindowSplitterDistance> <TestsWindowSplitterDistance>544</TestsWindowSplitterDistance>
</Settings> </Settings>
</SolutionConfiguration> </SolutionConfiguration>