diff --git a/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb b/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb index ba5437a451a80fe4b2bb9b94d59f31fb8e0fd564..f034e40ea2250cdbc32d831fb0294bb88979c3a9 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb @@ -2,9 +2,6 @@ Namespace Electrics - - - ''' <summary> ''' Alternator Efficiency Map - ''' </summary> @@ -86,30 +83,29 @@ Namespace Electrics ''' <remarks></remarks> Public Function GetEfficiency(ByVal rpm As Integer, ByVal amps As Integer) As AlternatorMapValues - Dim results As AlternatorMapValues + Dim key As New AlternatorMapKey(amps, rpm) - Return results + Return GetValueOrInterpolate(key) End Function - ''' <summary> ''' Returns a AlternatorMapValues instance containing the entries at a given key, or new interpolated values ''' </summary> ''' <returns>AlternatorMapValues</returns> - ''' <remarks>Throws exception if rpm are outside map</remarks> + ''' <remarks>Throws exception if Rpm or Amps are outside the map </remarks> Private Function GetValueOrInterpolate(mapKey As AlternatorMapKey) As AlternatorMapValues 'check the rpm is within the map - 'Dim min As AlternatorMapKey = map.Keys.Min() - 'Dim max As AlternatorMapKey = map.Keys.Max() + Dim min As AlternatorMapKey = map.Keys.Min() + Dim max As AlternatorMapKey = map.Keys.Max() - 'If mapKey.amps < 0 OrElse mapKey.amps > max.amps OrElse mapKey.rpm < 0 OrElse mapKey.rpm > max.rpm Then - ' Throw New ArgumentOutOfRangeException(String.Format("Extrapolation - Amp/Rpm Values should should be in the range {0} to {1}", min.ToString(), max.ToString())) - 'End If + If mapKey.amps < min.amps Or mapKey.amps > max.amps Or mapKey.rpm < min.rpm Or mapKey.rpm > max.rpm Then + Throw New ArgumentOutOfRangeException(String.Format("Extrapolation - Amp/Rpm Values should should be in the range {0} to {1}", min.ToString(), max.ToString())) + End If 'Check if the rpm is in the current memo 'If supplied present key, we can just return the values @@ -124,6 +120,7 @@ Namespace Electrics Dim ampsPre As AlternatorMapValues Dim ampsPost As AlternatorMapValues + 'Pre and Post Data Points Dim intRpmPre As Integer Dim intRpmPost As Integer Dim intAmpsPre As Integer @@ -140,8 +137,18 @@ Namespace Electrics ampsPre = map(New AlternatorMapKey(intAmpsPost, intRpmPre)) ampsPost = map(New AlternatorMapKey(intAmpsPost, intRpmPost)) - - '********** A-B Efficiency ( Lower Amps ) ************ + '************************************************************************* + 'The following biaxial linear interpolation formula was provided + 'by Engineering. See example below. + ' + ' 1500 2000 4000 + ' 10 A-B <=Interpolated Horizontally + ' (C-D)-(A-B) <=Interpolated Virtically + ' 27 C-D <=Interpolated Horizontally + ' + '************************************************************************ + ' + '*** A-B Efficiency ( Lower Using Lower Amps ) 'get the delta values for rpm and the values Dim dRpm As Integer = intRpmPost - intRpmPre Dim dRpmEfficiency As Single = rpmPost.Efficiency - rpmPre.Efficiency @@ -152,7 +159,7 @@ Namespace Electrics 'calculate the new values Dim AB_Efficiency As Single = ((mapKey.rpm - intRpmPre) * rpmEfficiencySlope) + rpmPre.Efficiency - '********** C-D Efficiency ( Higher Amps ) ************ + '*** C-D Efficiency ( Using Higher Amps ) 'get the delta values for rpm and the values dRpm = intRpmPost - intRpmPre dRpmEfficiency = ampsPost.Efficiency - ampsPre.Efficiency @@ -176,30 +183,16 @@ Namespace Electrics Dim ABCDEfficiency As Single = ((mapKey.amps - intAmpsPre) * ampsEfficiencySlope) + AB_Efficiency - Return New AlternatorMapValues(ABCDEfficiency) + Return New AlternatorMapValues(ABCDEfficiency) End Function - ''' <summary> - ''' Encapsulates Efficiency and Maximum Regeneration Power values for Alternator - ''' </summary> - 'Public Structure AlternatorMapValues - - - ' Public ReadOnly Efficiency As Single - - ' Public Sub New(ByVal efficiency As Single) - ' Me.Efficiency = efficiency - ' End Sub - - ' End Structure - Private Structure AlternatorMapKey - + Implements IComparable Public amps As Integer Public rpm As Integer @@ -220,6 +213,37 @@ Namespace Electrics End Function + Public Function CompareTo(obj As Object) As Integer Implements IComparable.CompareTo + + + Dim compared As AlternatorMapKey = CType(obj, AlternatorMapKey) + + Dim otherAlternatorMapKey As AlternatorMapKey = CType(obj, AlternatorMapKey) + + 'Same Place + If (Me.amps = otherAlternatorMapKey.amps AndAlso Me.rpm = otherAlternatorMapKey.rpm) Then + + Return 0 + + End If + + 'smaller + If (Me.amps > otherAlternatorMapKey.amps) Or (Me.rpm > otherAlternatorMapKey.rpm) Then + + Return 1 + + Else + + Return -1 + + End If + + + + + End Function + + End Structure diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMap.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMap.csv index 7364287ceb235929fdf69c349a44d70ea646bdde..3968d6970a965b8b74a3ca36fd811373527bfd8e 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMap.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMap.csv @@ -1,36 +1,36 @@ Amp,RPM,Efficiency -10,1500,61.50 -27,1500,70.00 -53,1500,19.47 +10,1500,0.615 +27,1500,0.70 +53,1500,0.1947 63,1500,0.00 68,1500,0.00 125,1500,0.00 136,1500,0.00 -10,2000,62.00 -27,2000,70.00 -53,2000,30.00 -63,2000,14.62 -68,2000,6.92 +10,2000,0.62 +27,2000,0.70 +53,2000,0.30 +63,2000,0.1462 +68,2000,0.692 125,2000,0.00 136,2000,0.00 -10,4000,64.00 -27,4000,67.21 -53,4000,72.11 -63,4000,74.00 -68,4000,73.52 -125,4000,68.00 -136,4000,66.94 -10,6000,53.00 -27,6000,57.98 -53,6000,65.60 -63,6000,68.53 -68,6000,70.00 -125,6000,63.29 -136,6000,62.00 -10,7000,47.50 -27,7000,53.37 -53,7000,62.35 -63,7000,65.80 -68,7000,68.24 -125,7000,60.94 -136,7000,59.53 +10,4000,0.64 +27,4000,0.6721 +53,4000,0.7211 +63,4000,0.7400 +68,4000,0.7352 +125,4000,0.6800 +136,4000,0.6694 +10,6000,0.5300 +27,6000,0.5798 +53,6000,0.6560 +63,6000,0.6853 +68,6000,0.7000 +125,6000,0.6329 +136,6000,0.6200 +10,7000,0.4750 +27,7000,0.5337 +53,7000,0.6235 +63,7000,0.6580 +68,7000,0.6824 +125,7000,0.6094 +136,7000,0.5953 diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapNotEnoughRows.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapNotEnoughRows.csv index da49b26114702bd60f0ce35683646345a8848989..8559a177d5ccf653b62957063eabdc08d8498924 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapNotEnoughRows.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapNotEnoughRows.csv @@ -1,2 +1,2 @@ Amp,RPM,Efficiency -10,1500,61.50 +10,1500,0.6150 diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapReadOnly.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapReadOnly.csv index 4db17f503d7c665f1565f010e8624901b21a4dd3..f751f106cd9c5904829a992b325abb0a853a920c 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapReadOnly.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapReadOnly.csv @@ -1,36 +1,35 @@ -Amp,RPM,Efficiency -10,1500,61.50 -27,1500,70.00 -53,1500,19.47 +10,1500,0.615 +27,1500,0.70 +53,1500,0.1947 63,1500,0.00 68,1500,0.00 125,1500,0.00 136,1500,0.00 -10,2000,62.00 -27,2000,70.00 -53,2000,30.00 -63,2000,14.62 -68,2000,6.92 +10,2000,0.62 +27,2000,0.70 +53,2000,0.30 +63,2000,0.1462 +68,2000,0.692 125,2000,0.00 136,2000,0.00 -10,4000,64.00 -27,4000,67.21 -53,4000,72.11 -63,4000,74.00 -68,4000,73.52 -125,4000,68.00 -136,4000,66.94 -10,6000,53.00 -27,6000,57.98 -53,6000,65.60 -63,6000,68.53 -68,6000,70.00 -125,6000,63.29 -136,6000,62.00 -10,7000,47.50 -27,7000,53.37 -53,7000,62.35 -63,7000,65.80 -68,7000,68.24 -125,7000,60.94 -136,7000,59.53 \ No newline at end of file +10,4000,0.64 +27,4000,0.6721 +53,4000,0.7211 +63,4000,0.7400 +68,4000,0.7352 +125,4000,0.6800 +136,4000,0.6694 +10,6000,0.5300 +27,6000,0.5798 +53,6000,0.6560 +63,6000,0.6853 +68,6000,0.7000 +125,6000,0.6329 +136,6000,0.6200 +10,7000,0.4750 +27,7000,0.5337 +53,7000,0.6235 +63,7000,0.6580 +68,7000,0.6824 +125,7000,0.6094 +136,7000,0.5953 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidEfficiency.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidEfficiency.csv index 8bb39752f4dc82e5c3a17e5980d10097130551a3..a6f19d07213a7f31b7e1adc07206bef5f9de4f3b 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidEfficiency.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidEfficiency.csv @@ -1,36 +1,36 @@ Amp,RPM,Efficiency -10,1500,zzzz -27,1500,70.00 -53,1500,19.47 +10,1500,zzz +27,1500,0.70 +53,1500,0.1947 63,1500,0.00 68,1500,0.00 125,1500,0.00 136,1500,0.00 -10,2000,62.00 -27,2000,70.00 -53,2000,30.00 -63,2000,14.62 -68,2000,6.92 +10,2000,0.62 +27,2000,0.70 +53,2000,0.30 +63,2000,0.1462 +68,2000,0.692 125,2000,0.00 136,2000,0.00 -10,4000,64.00 -27,4000,67.21 -53,4000,72.11 -63,4000,74.00 -68,4000,73.52 -125,4000,68.00 -136,4000,66.94 -10,6000,53.00 -27,6000,57.98 -53,6000,65.60 -63,6000,68.53 -68,6000,70.00 -125,6000,63.29 -136,6000,62.00 -10,7000,47.50 -27,7000,53.37 -53,7000,62.35 -63,7000,65.80 -68,7000,68.24 -125,7000,60.94 -136,7000,59.53 \ No newline at end of file +10,4000,0.64 +27,4000,0.6721 +53,4000,0.7211 +63,4000,0.7400 +68,4000,0.7352 +125,4000,0.6800 +136,4000,0.6694 +10,6000,0.5300 +27,6000,0.5798 +53,6000,0.6560 +63,6000,0.6853 +68,6000,0.7000 +125,6000,0.6329 +136,6000,0.6200 +10,7000,0.4750 +27,7000,0.5337 +53,7000,0.6235 +63,7000,0.6580 +68,7000,0.6824 +125,7000,0.6094 +136,7000,0.5953 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidRpm.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidRpm.csv index af117b403332d7b8da4f10b78a5b2f7d4c9d2d7c..5430c8d6c476a730c2acc9023fba43e7e41d3493 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidRpm.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testAlternatorMapWithInvalidRpm.csv @@ -1,36 +1,36 @@ Amp,RPM,Efficiency -zzz,1500,61.50 -27,1500,70.00 -53,1500,19.47 +zzz,1500,0.615 +27,1500,0.70 +53,1500,0.1947 63,1500,0.00 68,1500,0.00 125,1500,0.00 136,1500,0.00 -10,2000,62.00 -27,2000,70.00 -53,2000,30.00 -63,2000,14.62 -68,2000,6.92 +10,2000,0.62 +27,2000,0.70 +53,2000,0.30 +63,2000,0.1462 +68,2000,0.692 125,2000,0.00 136,2000,0.00 -10,4000,64.00 -27,4000,67.21 -53,4000,72.11 -63,4000,74.00 -68,4000,73.52 -125,4000,68.00 -136,4000,66.94 -10,6000,53.00 -27,6000,57.98 -53,6000,65.60 -63,6000,68.53 -68,6000,70.00 -125,6000,63.29 -136,6000,62.00 -10,7000,47.50 -27,7000,53.37 -53,7000,62.35 -63,7000,65.80 -68,7000,68.24 -125,7000,60.94 -136,7000,59.53 \ No newline at end of file +10,4000,0.64 +27,4000,0.6721 +53,4000,0.7211 +63,4000,0.7400 +68,4000,0.7352 +125,4000,0.6800 +136,4000,0.6694 +10,6000,0.5300 +27,6000,0.5798 +53,6000,0.6560 +63,6000,0.6853 +68,6000,0.7000 +125,6000,0.6329 +136,6000,0.6200 +10,7000,0.4750 +27,7000,0.5337 +53,7000,0.6235 +63,7000,0.6580 +68,7000,0.6824 +125,7000,0.6094 +136,7000,0.5953 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AlternatorMapTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AlternatorMapTests.vb index 075557974b176d56dec62cb685805f57ebe08c66..5335041f3313b3efdb72a3b7308bb71b0b04f1bb 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/AlternatorMapTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/AlternatorMapTests.vb @@ -9,6 +9,7 @@ Namespace UnitTests Private Const _GOODMAP As String = "TestFiles\testAlternatorMap.csv" Private Const _INVALIDRPMMAP As String = "TestFiles\testAlternatorMapWithInvalidRpm.csv" + Private Const _INVALIDAMPSMAP As String = "TestFiles\testAlternatorMapWithInvalidAmps.csv" Private Const _IVALIDEFFICIENCYMAP As String = "TestFiles\testAlternatorMapWithInvalidEfficiency.csv" Private Const _INVALIDPOWERMAP As String = "TestFiles\testAlternatorMapWithInvalidPower.csv" @@ -57,76 +58,74 @@ Namespace UnitTests End Sub <Test(), ExpectedException("System.InvalidCastException")> - Public Sub InitialiseInvalidEfficiencyThrowsExceptionTest() - Dim path As String = _IVALIDEFFICIENCYMAP + Public Sub InitialiseInvalidAmpsThrowsExceptionTest() + Dim path As String = _INVALIDAMPSMAP Dim target As AlternatorMap = New AlternatorMap(path) target.Initialise() End Sub <Test(), ExpectedException("System.InvalidCastException")> - Public Sub InitialiseInvalidPowerThrowsExceptionTest() - Dim path As String = _INVALIDPOWERMAP + Public Sub InitialiseInvalidEfficiencyThrowsExceptionTest() + Dim path As String = _IVALIDEFFICIENCYMAP Dim target As AlternatorMap = New AlternatorMap(path) target.Initialise() End Sub + <TestCase(2300, 15)> _ + Public Sub GetEfficiencyInterpolationTest(ByVal rpm As Integer, ByVal amps As Integer) - <Test()> - Public Sub GetEfficiencyKeyPassedTest() - 'Dim target As AlternatorMap = GetInitialisedMap() - 'Dim expected As Single = 0.1 - 'target.GetEfficiency() - 'Dim value As Single = target.GetEfficiency(100) - 'Assert.AreEqual(expected, value) - - 'expected = 0.9 - 'value = target.GetEfficiency(900) - 'Assert.AreEqual(expected, value) - - Assert.Fail() - End Sub - - <Test()> - Public Sub GetEfficiencyInterpolationTest() - 'Dim target As AlternatorMap = GetInitialisedMap() - 'Dim expected As Single = 0.15 - 'Dim value As Single = target.GetEfficiency(150) - 'Assert.AreEqual(expected, value) - - 'expected = 0.85 - 'value = target.GetEfficiency(850) - 'Assert.AreEqual(expected, value) + Dim target As AlternatorMap = GetInitialisedMap() + Dim expected As Single = 0.6444162 + Dim value As Single = target.GetEfficiency(rpm, amps).Efficiency + Assert.AreEqual(expected, value) + Assert.AreEqual(expected, value) - Assert.Fail() End Sub - <TestCase(0)> - <TestCase(1000)> + + <TestCase(0, 0)> _ + <TestCase(0, 1500)> _ + <TestCase(10, 0)> _ + <TestCase(136, 8000)> _ + <TestCase(200, 7000)> _ <ExpectedException("System.ArgumentOutOfRangeException")> _ - Public Sub GetEfficiencyRpmOutOfRangeThrowsExceptionTest(ByVal rpm As Integer) - 'Dim target As AlternatorMap = GetInitialisedMap() - 'Dim value As Single = target.GetEfficiency(rpm) + Public Sub GetEfficiencyRpmOutOfRangeThrowsExceptionTest(ByVal amps As Integer, ByVal rpm As Integer) - Assert.Fail() + Dim target As AlternatorMap = GetInitialisedMap() + Dim value As AlternatorMapValues = target.GetEfficiency(rpm, amps) End Sub + <TestCase(10, 1500)> _ + Public Sub GetEfficiencyOnLowerBoundary(ByVal amps As Integer, ByVal rpm As Integer) + Dim target As AlternatorMap = GetInitialisedMap() + Dim actual As Single = target.GetEfficiency(rpm, amps).Efficiency + Dim expected As Single = 0.615 + Assert.AreEqual(expected, actual) + End Sub + <TestCase(27, 2000)> _ + Public Sub GetEfficiencyOnInterimBoundary(ByVal amps As Integer, ByVal rpm As Integer) + Dim target As AlternatorMap = GetInitialisedMap() + Dim actual As Single = target.GetEfficiency(rpm, amps).Efficiency + Dim expected As Single = 0.7 + Assert.AreEqual(expected, actual) + End Sub + <TestCase(136, 7000)> _ + Public Sub GetEfficiencyTopBoundary(ByVal amps As Integer, ByVal rpm As Integer) - <TestCase(0)> - <TestCase(1000)> - <ExpectedException("System.ArgumentOutOfRangeException")> - Public Sub GetPowerRpmOutOfRangeThrowsExceptionTest(ByVal rpm As Integer) - 'Dim target As AlternatorMap = GetInitialisedMap() - 'Dim value As Single = target.GetMaximumRegenerationPower(rpm) + Dim target As AlternatorMap = GetInitialisedMap() + Dim actual As Single = target.GetEfficiency(rpm, amps).Efficiency + Dim expected As Single = 0.5953 - Assert.Fail() + Assert.AreEqual(expected, actual) End Sub + #Region "Helpers" Private Function GetInitialisedMap() As AlternatorMap @@ -144,4 +143,5 @@ Namespace UnitTests #End Region End Class + End Namespace \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj index ef12b2cf408454781c0da23bc4298eb6da038e97..2c1e4d7c7f2d488362f33b89be8da3c6a45ba0f8 100644 --- a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj +++ b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj @@ -126,7 +126,6 @@ </EmbeddedResource> </ItemGroup> <ItemGroup> - <None Include="ClassDiagram1.cd" /> <None Include="My Project\Application.myapp"> <Generator>MyApplicationCodeGenerator</Generator> <LastGenOutput>Application.Designer.vb</LastGenOutput>