diff --git a/VECTOAux/AUXUITEST/AUXUITEST.vbproj b/VECTOAux/AUXUITEST/AUXUITEST.vbproj index d2da91b1962c19a541b5ed8f42dc224c19246170..516c281898f49af10cda78aed6ee532cf34ad4b3 100644 --- a/VECTOAux/AUXUITEST/AUXUITEST.vbproj +++ b/VECTOAux/AUXUITEST/AUXUITEST.vbproj @@ -75,13 +75,6 @@ <Import Include="System.Threading.Tasks" /> </ItemGroup> <ItemGroup> - <Compile Include="F_HVAC.vb"> - <SubType>Form</SubType> - </Compile> - <Compile Include="F_HVAC.Designer.vb"> - <DependentUpon>F_HVAC.vb</DependentUpon> - <SubType>Form</SubType> - </Compile> <Compile Include="LaunchPad.Designer.vb"> <DependentUpon>LaunchPad.vb</DependentUpon> </Compile> @@ -106,9 +99,6 @@ <Compile Include="Program.vb" /> </ItemGroup> <ItemGroup> - <EmbeddedResource Include="F_HVAC.resx"> - <DependentUpon>F_HVAC.vb</DependentUpon> - </EmbeddedResource> <EmbeddedResource Include="LaunchPad.resx"> <DependentUpon>LaunchPad.vb</DependentUpon> </EmbeddedResource> diff --git a/VECTOAux/AUXUITEST/LaunchPad.vb b/VECTOAux/AUXUITEST/LaunchPad.vb index dde92e05ed15198356030bbf322cbc06ecce9b2f..b135e84f2fd8e7758b941b91e3def441f9d46c8f 100644 --- a/VECTOAux/AUXUITEST/LaunchPad.vb +++ b/VECTOAux/AUXUITEST/LaunchPad.vb @@ -12,4 +12,13 @@ + Private Sub LaunchPad_Load(sender As Object, e As EventArgs) + + + + End Sub + + Private Sub LaunchPad_Activated(sender As Object, e As EventArgs) + + End Sub End Class \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb b/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb index 386669f17ba97b67ee6d1daf90199dbbc3d1285b..db5b96147b155cacee30ed9d8ba0de993f084e2e 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/AlternatorMap.vb @@ -161,4 +161,6 @@ Namespace Electrics End Structure End Class + + End Namespace \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliaries/Electrics/HVACInputs.vb b/VECTOAux/VectoAuxiliaries/Electrics/HVACInputs.vb index 3f42b1d6528981c1608e86164a2a85780197572a..2c43cba45a73e1d553892a7c8e03532b5fb0bdd4 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/HVACInputs.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/HVACInputs.vb @@ -5,4 +5,17 @@ Public Property Season As Integer Implements IHVACInputs.Season + Public Sub New() + + End Sub + + + Public Sub New(Region As Integer, Season As Integer) + + Me.Region = Region + Me.Season = Season + + End Sub + + End Class diff --git a/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb b/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb index c9ba870751bc571d51038f196657bab93fdd1314..80e18987c4e2c917eed30c70e1ee06429739217e 100644 --- a/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb +++ b/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb @@ -9,8 +9,6 @@ Namespace Hvac Public Property Region As Integer Public Property Season As Integer - - Public Sub New(ByVal map As IHVACMap, ByVal alternator As IAlternator, inputs As IHVACInputs) Me.map = map Me.alternator = alternator @@ -18,24 +16,40 @@ Namespace Hvac Me.Region = inputs.Region Me.Season = inputs.Season + End Sub Public Function Initialise() As Boolean Return alternator.Initialise() AndAlso map.Initialise() End Function - Public Function AverageMechanicalPowerDemandAtCrank(engineRPM As Integer) As Single + Public Function AverageMechanicalPowerDemandAtCrank() As Single + + Dim mechD As Single = map.GetMechanicalDemand(Region, Season) + + Dim pulleyGearEfficiency As Single = alternator.PulleyGearEfficiency + + + Return mechD / pulleyGearEfficiency - Return alternator.PulleyGearEfficiency End Function Function AverageElectricalPowerDemandAtAlternator() As Single + Return map.GetElectricalDemand(Region, Season) + End Function - Function AverageElectricalPowerDemandAtCrank() As Single + Function AverageElectricalPowerDemandAtCrank(engineRPM As Single) As Single + + Dim alternatorEfficiency As Single = alternator.GetEfficiency(engineRPM) + Dim hvacElectricalPowerDemand As Single = map.GetElectricalDemand(Region, Season) + + Dim result As Single = (hvacElectricalPowerDemand / alternatorEfficiency) / alternator.PulleyGearEfficiency + + Return result End Function diff --git a/VECTOAux/VectoAuxiliaries/Hvac/HVACMap.vb b/VECTOAux/VectoAuxiliaries/Hvac/HVACMap.vb index a3a14c2c6dfac0bdbcca74af90b4adb4e1a3aefc..d974bb6128fa976417118b0bc1cd1d205ffb5997 100644 --- a/VECTOAux/VectoAuxiliaries/Hvac/HVACMap.vb +++ b/VECTOAux/VectoAuxiliaries/Hvac/HVACMap.vb @@ -29,8 +29,7 @@ Namespace Hvac #End Region - - 'constants for .vaux headers + 'Constants for .vaux headers Private Const REGIONheader As String = "Region" Private Const SEASONheader As String = "Season" Private Const MECHDheader As String = "MechD" @@ -43,8 +42,9 @@ Namespace Hvac Private _electricalDemandLookupKW As Single Private _map As List(Of String()) - ' Public Property _mapHeaders As Dictionary(Of String, HVACMapParameter) + 'Public Property _mapHeaders As Dictionary(Of String, HVACMapParameter) Private _mapHeaders As Dictionary(Of String, HVACMapParameter) + Public Property MapHeaders As Dictionary(Of String, HVACMapParameter) Implements IHVACMap.MapHeaders Get Return Me._mapHeaders @@ -54,7 +54,6 @@ Namespace Hvac End Set End Property - 'Constructor ''' <summary> ''' Constructor @@ -62,57 +61,61 @@ Namespace Hvac ''' <param name="iMapPath"></param> ''' <remarks></remarks> Public Sub New(iMapPath As String) - _mapPath = iMapPath - MapHeaders = New Dictionary(Of String, HVACMapParameter)() - _map = New List(Of String()) - - InitialiseMapHeaders() - - Initialise() - - Dim result As Object = (From line In _map Where line(0) = "2") - - End Sub 'Initialisers and Map related Methods Public Function Initialise() As Boolean Implements IHVACMap.Initialise + MapHeaders = New Dictionary(Of String, HVACMapParameter)() + _map = New List(Of String()) + + InitialiseMapHeaders() + Dim myData As String Dim linesArray As String() + 'Check map file can be found. Try - myData = System.IO.File.ReadAllText(_mapPath, System.Text.Encoding.UTF8) - linesArray = (From s As String In myData.Split(vbLf) Select s.Trim).ToArray + Catch ex As FileNotFoundException + Throw New ArgumentException("The map file was not found") + End Try + linesArray = (From s As String In myData.Split(vbLf) Select s.Trim).ToArray - 'getValuesIntoMap - For Each line As String In linesArray - _map.Add(line.Split(","c)) - Next + 'getValuesIntoMap + Dim lineNumber As Integer = 0 + For Each line As String In linesArray - _mapDimensions = _map(0).Length + Dim values As String() = line.Split(","c) - 'Validate Map - If validateMap() = False Then - Throw New Exception("Unable to complete Load of HVAC MAP") + 'Test number of values + If values.Count <> _mapHeaders.Count Then + Throw New System.ArgumentException("Row contains inconsistant values") End If - 'Set Unique Values for headers which can be used as a selection device. + Dim intTest As Single + 'Check lines all contain valid rows ( Assume Single ) + For Each v As String In values + If lineNumber > 0 AndAlso Not Single.TryParse(v, intTest) Then + Throw New InvalidCastException("A non numeric value was found in the map file") + End If + Next - Catch ffe As FileNotFoundException - - Throw ffe + lineNumber += 1 + _map.Add(values) - Catch ex As Exception + Next - Throw ex + _mapDimensions = _map(0).Length - End Try + 'Validate Map + If validateMap() = False Then + Throw New Exception("Unable to complete Load of HVAC MAP") + End If Return True @@ -275,7 +278,7 @@ Namespace Hvac Dim search As String() = {region.ToString(), season.ToString(), "", ""} If (GetMapSubSet(search).Count <> 1) Then - Throw New Exception("Not Exactly one result returned for these inputs.") + Throw New ArgumentException("Not Exactly one result returned for these inputs.") End If 'get mechanical demand @@ -292,7 +295,7 @@ Namespace Hvac Dim search As String() = {region.ToString(), season.ToString(), "", ""} If (GetMapSubSet(search).Count <> 1) Then - Throw New Exception("Not Exactly one result returned for these inputs.") + Throw New ArgumentException("Not Exactly one result returned for these inputs.") End If 'get electrical demand diff --git a/VECTOAux/VectoAuxiliaries/UI/F_HVAC.vb b/VECTOAux/VectoAuxiliaries/UI/F_HVAC.vb index 424be599d8b7c92b717f32b02cf44c986c5fdc0f..7a76289512e1db47c4dbed60696ad0a45413336c 100644 --- a/VECTOAux/VectoAuxiliaries/UI/F_HVAC.vb +++ b/VECTOAux/VectoAuxiliaries/UI/F_HVAC.vb @@ -3,7 +3,6 @@ Imports System.Windows.Forms Namespace UI - Public Class F_HVAC 'Private Fields @@ -170,6 +169,8 @@ Namespace UI _map = New HVACMap(_mapPath) + _map.Initialise() + _mapFilter.Clear() For Each item As KeyValuePair(Of String, HVACMapParameter) In _map.GetMapHeaders _mapFilter.Add("") @@ -180,14 +181,10 @@ Namespace UI End Sub + Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click + Me.Close() + End Sub End Class - - - - - - - End Namespace diff --git a/VECTOAux/VectoAuxiliariesTests/Mocks/AlternatorMock.vb b/VECTOAux/VectoAuxiliariesTests/Mocks/AlternatorMock.vb index 67c6391ad9e653acbff480985f287b287ceab959..a4b7d041bddd6d1accf141ab37a7c563cf9be1f8 100644 --- a/VECTOAux/VectoAuxiliariesTests/Mocks/AlternatorMock.vb +++ b/VECTOAux/VectoAuxiliariesTests/Mocks/AlternatorMock.vb @@ -5,21 +5,25 @@ Namespace Mocks Public Class AlternatorMock Implements IAlternator + Private _gearPullyRatio As Single = 1 + Private _gearPullyEfficiency As Single = 1 + + Public Property PulleyGearRatio() As Single Implements IAlternator.PulleyGearRatio Get - Return 1.0 + Return _gearPullyRatio End Get Set(ByVal value As Single) - + _gearPullyRatio = value End Set End Property Public Property PulleyGearEfficiency() As Single Implements IAlternator.PulleyGearEfficiency Get - Return 1.0 + Return _gearPullyEfficiency End Get Set(ByVal value As Single) - + _gearPullyEfficiency = value End Set End Property diff --git a/VECTOAux/VectoAuxiliariesTests/Mocks/HVACMapMock.vb b/VECTOAux/VectoAuxiliariesTests/Mocks/HVACMapMock.vb index 7d3f80839fe5dd851529ef9712d48137ecf7519b..05affa7e1d73fe26b8a46af7432744c9c345db80 100644 --- a/VECTOAux/VectoAuxiliariesTests/Mocks/HVACMapMock.vb +++ b/VECTOAux/VectoAuxiliariesTests/Mocks/HVACMapMock.vb @@ -1,33 +1,287 @@ Imports VectoAuxiliaries.Hvac +Imports System.IO +Imports System.Windows.Forms + +'HVAC MAP ( Mocked Values ) + +'_map.Add("Region,Season,MechD,ElecD".Split(","c)) +'_map.Add("1,1,50,10".Split(","c)) +'_map.Add("1,2,50,11".Split(","c)) +'_map.Add("1,3,50,12".Split(","c)) +'_map.Add("1,4,50,13".Split(","c)) +'_map.Add("2,1,50,14".Split(","c)) +'_map.Add("2,2,50,15".Split(","c)) +'_map.Add("2,3,50,16".Split(","c)) +'_map.Add("2,4,50,17".Split(","c)) +'_map.Add("3,1,50,18".Split(","c)) +'_map.Add("3,2,50,19".Split(","c)) +'_map.Add("3,3,50,10".Split(","c)) +'_map.Add("3,4,50,11".Split(","c)) +'_map.Add("4,1,50,12".Split(","c)) +'_map.Add("4,2,50,13".Split(","c)) +'_map.Add("4,3,50,14".Split(","c)) +'_map.Add("4,4,50,15".Split(","c)) + Namespace Mocks Public Class HVACMapMock Implements IHVACMap + 'constants for .vaux headers + Private Const REGIONheader As String = "Region" + Private Const SEASONheader As String = "Season" + Private Const MECHDheader As String = "MechD" + Private Const ELECDheader As String = "ElecD" + + 'Private Fields + Private _mapDimensions As Integer + Private _mapPath As String + Private _mechanicalDemandLookupKW As Single + Private _electricalDemandLookupKW As Single + Private _map As New List(Of String()) + + ' Public Property _mapHeaders As Dictionary(Of String, HVACMapParameter) + Private _mapHeaders As New Dictionary(Of String, HVACMapParameter) Public Property MapHeaders As Dictionary(Of String, HVACMapParameter) Implements IHVACMap.MapHeaders + Get + Return Me._mapHeaders + End Get + Private Set(ByVal Value As Dictionary(Of String, HVACMapParameter)) + Me._mapHeaders = Value + End Set + End Property + + + 'Constructor + ''' <summary> + ''' Constructor + ''' </summary> + ''' <param name="iMapPath"></param> + ''' <remarks></remarks> + Public Sub New(iMapPath As String) + + _mapPath = iMapPath + + + + End Sub + + 'Initialisers and Map related Methods Public Function Initialise() As Boolean Implements IHVACMap.Initialise + + MapHeaders = New Dictionary(Of String, HVACMapParameter)() + + _map = New List(Of String()) + + InitialiseMapHeaders() + + _map.Add("Region,Season,MechD,ElecD".Split(","c)) + _map.Add("1,1,50,10".Split(","c)) + _map.Add("1,2,50,11".Split(","c)) + _map.Add("1,3,50,12".Split(","c)) + _map.Add("1,4,50,13".Split(","c)) + _map.Add("2,1,50,14".Split(","c)) + _map.Add("2,2,50,15".Split(","c)) + _map.Add("2,3,50,16".Split(","c)) + _map.Add("2,4,50,17".Split(","c)) + _map.Add("3,1,50,18".Split(","c)) + _map.Add("3,2,50,19".Split(","c)) + _map.Add("3,3,50,10".Split(","c)) + _map.Add("3,4,50,11".Split(","c)) + _map.Add("4,1,50,12".Split(","c)) + _map.Add("4,2,50,13".Split(","c)) + _map.Add("4,3,50,14".Split(","c)) + _map.Add("4,4,50,15".Split(","c)) + + _mapDimensions = _map(0).Length + + 'Make sure we have matching headers for our list of HVACMapParameterList + Dim i As Integer + + For i = 0 To _mapDimensions - 1 + + If Not MapHeaders.ContainsKey(_map(0)(i)) Then + MessageBox.Show("Map header {0} was not found in the prefdefined and expected header list", _map(0)(i)) + Return False + Else + 'Set ordinal position of respective header. + MapHeaders(_map(0)(i)).OrdinalPosition = i + + 'Get Unique Values associated with Headers. + MapHeaders(_map(0)(i)).UniqueDataValues = GetUniqueValuesByOrdinal(i) + + End If + + Next + Return True + End Function - Public Function GetMechanicalDemand(ByVal region As Integer, ByVal season As Integer) As Integer Implements IHVACMap.GetMechanicalDemand - Return 10 + + Private Function validateMap() As Boolean + + + + Return True + End Function + Private Sub InitialiseMapHeaders() + + 'Not all properties in the HVACMapParameter POCO are initialised here + 'As some can only be populated dynamically such as OrdinalPosition. + + 'Region + Dim region As New HVACMapParameter With {.Key = REGIONheader, + .Description = "Region Code", + .Max = 0, + .Min = 0, + .Name = "Regional Code", + .Notes = "", + .SystemType = GetType(Integer), + .SearchControlType = GetType(System.Windows.Forms.ComboBox)} + MapHeaders.Add(REGIONheader, region) + + 'Season + Dim season As New HVACMapParameter With {.Key = SEASONheader, + .Description = "Season Code", + .Max = 0, + .Min = 0, + .Name = "Season Code", + .Notes = "", + .SystemType = GetType(Integer), + .SearchControlType = GetType(System.Windows.Forms.ComboBox)} + MapHeaders.Add(SEASONheader, season) + + '************************************************************************************************* + ' Author. + ' + ' Add more inputs here - Ensure that these match exactly with the headers in the .vaux file. + ' + ' This could be done dynamically with a loadable configuration file, but takes more time + ' + '************************************************************************************************ + + 'MechD + Dim mechD As New HVACMapParameter With {.Key = MECHDheader, + .Description = "MechD", + .Max = 0, + .Min = 0, + .Name = "MechD", + .Notes = "", + .SystemType = GetType(Integer), + .IsOutput = True} + MapHeaders.Add(MECHDheader, mechD) + + + 'ElecD + Dim elecD As New HVACMapParameter With {.Key = ELECDheader, + .Description = "ElecD", + .Max = 0, + .Min = 0, + .Name = "ElecD", + .Notes = "", + .SystemType = GetType(Integer), + .IsOutput = True} + MapHeaders.Add(ELECDheader, elecD) + + End Sub + + + 'Public Map Enquiry Methods Public Function GetMapHeaders() As Dictionary(Of String, HVACMapParameter) Implements IHVACMap.GetMapHeaders - Throw New NotImplementedException - End Function + Return MapHeaders - Public Function GetMapSubSet(search() As String) As List(Of String()) Implements IHVACMap.GetMapSubSet - Throw New NotImplementedException End Function + Public Function GetMapSubSet(search As String()) As List(Of String()) Implements IHVACMap.GetMapSubSet + + 'Sanity Check + If (search.Length <> _mapDimensions) Then + Throw New Exception("The search array does not match the number elements in the map") + End If + + Dim reducer As New List(Of String()) + Dim matched As Boolean + Dim i As Integer ' For each data row + + For i = 1 To (_map.Count - 1) + matched = True + + Dim o As Integer ' For each ordinal column + For o = 0 To search.Length - 1 + 'Dont try and match it if it is an output or nothing, what would be the point? + If search(o) = Nothing Or search(o) = "" Or GetMapHeaders.ToArray()(o).Value.IsOutput Then + Continue For ' Get next ordinal + Else + 'Try and match + If search(o) <> _map(i)(o) Then + matched = False + End If + End If + + Next o + + If matched Then + reducer.Add(_map(i)) + End If + + Next i + + Return reducer + + End Function Public Function GetUniqueValuesByOrdinal(o As Integer) As List(Of String) Implements IHVACMap.GetUniqueValuesByOrdinal - Throw New NotImplementedException + + 'Sanity Check + If (o < 0 Or o >= _mapDimensions) Then + Throw New Exception(Format("Get Unique Values by ordinal ordinal passed {0} is outside the bounds of the array.", o)) + End If + + Dim results As List(Of String) = + (From r In _map Select r(o) Distinct).ToList() + + 'Remove Headers + results.Remove(results(0)) + + Return results + End Function + Public Function GetMechanicalDemand(region As Integer, season As Integer) As Integer Implements IHVACMap.GetMechanicalDemand + + Dim search As String() = {region.ToString(), season.ToString(), "", ""} + + If (GetMapSubSet(search).Count <> 1) Then + Throw New Exception("Not Exactly one result returned for these inputs.") + End If + + 'get mechanical demand + Dim resultStr As String = GetMapSubSet(search).First()(_mapHeaders(MECHDheader).OrdinalPosition) + + Dim resultInt As Integer = Integer.Parse(resultStr) + + Return resultInt + + End Function Public Function GetElectricalDemand(region As Integer, season As Integer) As Integer Implements IHVACMap.GetElectricalDemand - Return 1 + + Dim search As String() = {region.ToString(), season.ToString(), "", ""} + + If (GetMapSubSet(search).Count <> 1) Then + Throw New Exception("Not Exactly one result returned for these inputs.") + End If + + 'get electrical demand + Dim resultStr As String = GetMapSubSet(search).First()(_mapHeaders(ELECDheader).OrdinalPosition) + + Dim resultInt As Integer = Integer.Parse(resultStr) + + Return resultInt + End Function End Class + End Namespace \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/HVACMap.vaux b/VECTOAux/VectoAuxiliariesTests/TestFiles/HVACMap.vaux new file mode 100644 index 0000000000000000000000000000000000000000..78f0c44f27b7c44822373a444f9555754191f9eb --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/HVACMap.vaux @@ -0,0 +1,17 @@ +Region,Season,MechD,ElecD +1,1,50,10 +1,2,50,11 +1,3,50,12 +1,4,50,13 +2,1,50,14 +2,2,50,15 +2,3,50,16 +2,4,50,17 +3,1,50,18 +3,2,50,19 +3,3,50,10 +3,4,50,11 +4,1,50,12 +4,2,50,13 +4,3,50,14 +4,4,50,15 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap - ExtraBlankLines.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap - ExtraBlankLines.csv new file mode 100644 index 0000000000000000000000000000000000000000..8547bb485f96aa6f8387ef8f8b52c208aa25eeb5 --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap - ExtraBlankLines.csv @@ -0,0 +1,21 @@ +Region,Season,ElecD,MechD +1,1,4,8 +2,1,8,16 +3,1,12,24 +4,1,16,32 +5,1,20,40 +1,2,16,64 +2,2,32,128 +3,2,48,192 +4,2,64,256 +5,2,80,320 +1,3,4,8 +2,3,8,16 +3,3,12,24 +4,3,16,32 +5,3,20,40 +1,4,16,64 +2,4,32,128 +3,4,48,192 +4,4,64,256 +5,4,80,320 diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap - MissingHeader.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap - MissingHeader.csv new file mode 100644 index 0000000000000000000000000000000000000000..70189268f18f7d6d57be3e431f438d34000d30d5 --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap - MissingHeader.csv @@ -0,0 +1,20 @@ +1,1,4,8 +a,1,8,16 +3,1,12,24 +4,1,16,32 +5,1,20,40 +1,2,16,64 +2,2,32,128 +3,2,48,192 +4,2,64,256 +5,2,80,320 +1,3,4,8 +2,3,8,16 +3,3,12,24 +4,3,16,32 +5,3,20,40 +1,4,16,64 +2,4,32,128 +3,4,48,192 +4,4,64,256 +5,4,80,320 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap.csv index 432fb1f333b84d282d83c771b130228925ef8134..a9a598e5d15bff653c66626119939e5d01938de8 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/TestHvacMap.csv @@ -1,4 +1,4 @@ -Region,Season,Elec,Mech +Region,Season,ElecD,MechD 1,1,4,8 2,1,8,16 3,1,12,24 @@ -18,4 +18,4 @@ Region,Season,Elec,Mech 2,4,32,128 3,4,48,192 4,4,64,256 -5,4,80,320 +5,4,80,320 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapInvalidRowData.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapInvalidRowData.csv index cc09a28af85a7439771bdb590978e1db5ef86e4e..1a0199ff1c56b4cb4e602dd16786b967cd6c2543 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapInvalidRowData.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapInvalidRowData.csv @@ -1,4 +1,4 @@ -Region,Season,Elec,Mech +Region,Season,ElecD,MechD aa,1,4,8 2,1,8,16 3,1,12,24 diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapWrongColumns.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapWrongColumns.csv index 1e5d9c33990b3177a927cedd3a8f28cbe2409a2a..10a8b50663bf678d20c273fb3f7162a714367560 100644 --- a/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapWrongColumns.csv +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testHvacMapWrongColumns.csv @@ -1,4 +1,4 @@ -Region,Season,Elec +Region,Season,ElecD 1,1,4 2,1,8 3,1,12 diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandTests.vb index 98aa4ef4126f28b2ce4da70081569aeea6eede06..66e637dd97ea3eb2cf99bc20301bafd1e470e17c 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandTests.vb @@ -3,33 +3,40 @@ Imports VectoAuxiliaries.Hvac Imports VectoAuxiliariesTests.Mocks Imports VectoAuxiliaries.Electrics Imports NUnit.Framework +Imports VectoAuxiliaries Namespace UnitTests <TestFixture()> Public Class AverageHVACLoadDemandTests #Region "Helpers" + + Const HVACMAPTestData As String = "TestFiles\HVACMap.vaux" + Private Function GetAlternatorMock() As IAlternator Dim alt As IAlternator = New AlternatorMock() + alt.PulleyGearEfficiency = 0.8 + alt.PulleyGearRatio = 1.5 Return alt End Function Private Function GetHVACMapMock() As IHVACMap - Dim map As IHVACMap = New HVACMapMock() + Dim map As IHVACMap = New HVACMapMock(HVACMAPTestData) Return map End Function Private Function GetAverageHVACLoadDemandIntance() As AverageHVACLoadDemand Dim alt As IAlternator = GetAlternatorMock() Dim map As IHVACMap = GetHVACMapMock() - Dim target As AverageHVACLoadDemand = New AverageHVACLoadDemand(map, alt, Nothing) + Dim inputs As New HVACInputs(1, 1) + Dim target As AverageHVACLoadDemand = New AverageHVACLoadDemand(map, alt, inputs) Return target End Function Private Function GetInitialisedAverageHVACLoadDemandIntance() As AverageHVACLoadDemand Dim alt As IAlternator = GetAlternatorMock() Dim map As IHVACMap = GetHVACMapMock() - Dim target As AverageHVACLoadDemand = New AverageHVACLoadDemand(map, alt, Nothing) + Dim target As AverageHVACLoadDemand = New AverageHVACLoadDemand(map, alt, New HVACInputs(1, 1)) target.Initialise() Return target End Function @@ -42,33 +49,41 @@ Namespace UnitTests Assert.IsInstanceOf(GetType(AverageHVACLoadDemand), target) End Sub - <Test()> Public Sub InitialiseTest() Dim target As AverageHVACLoadDemand = GetAverageHVACLoadDemandIntance() Assert.IsTrue(target.Initialise()) End Sub - <Test()> Public Sub AverageMechanicalPowerAtCrankTest() + <Test()> + Public Sub AverageMechanicalPowerDemandAtCrankTest() + Dim target As AverageHVACLoadDemand = GetInitialisedAverageHVACLoadDemandIntance() - Dim expected As Integer = 10 - Dim actual As Integer = target.AverageMechanicalPowerDemandAtCrank(100) + Dim expected As Single = 62.5 + Dim actual As Single = target.AverageMechanicalPowerDemandAtCrank() + + Assert.AreEqual(expected, actual) + End Sub - <Test()> Public Sub AverageElectricalPowerAtAlternatorTest() + <Test()> Public Sub AverageElectricalPowerDemandAtAlternatorTest() Dim target As AverageHVACLoadDemand = GetInitialisedAverageHVACLoadDemandIntance() Dim expected As Integer = 10 - Dim actual As Integer = target.AverageMechanicalPowerDemandAtCrank(100) + Dim actual As Integer = target.AverageElectricalPowerDemandAtAlternator + Assert.AreEqual(expected, actual) + End Sub <Test()> Public Sub AverageElectricalPowerAtCrankTest() + Dim target As AverageHVACLoadDemand = GetInitialisedAverageHVACLoadDemandIntance() - Dim expected As Integer = 10 - Dim actual As Integer = target.AverageMechanicalPowerDemandAtCrank(100) + Dim expected As Single = 25 + Dim actual As Single = target.AverageElectricalPowerDemandAtCrank(100) + Assert.AreEqual(expected, actual) + End Sub End Class - End Namespace diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/HVACMapTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/HVACMapTests.vb index bd5e0d8f828c851c1e3f03afb169a51d99f8ec39..d53f1ec481ad258c4ab9b399b68a8e8fb86a086e 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/HVACMapTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/HVACMapTests.vb @@ -56,11 +56,9 @@ Namespace UnitTests Assert.IsTrue(target.Initialise()) End Sub - - <TestCase(3, 1, 24)> - <TestCase(3, 2, 192)> - <TestCase(3, 3, 24)> - <TestCase(3, 4, 192)> + <TestCase(1, 1, 8 )> + <TestCase(1, 3, 8 )> + <TestCase(5, 4, 320 )> _ Public Sub GetMechanicalDemandTest(ByVal region As Integer, ByVal season As Integer, result As Integer) Dim target As HVACMap = GetInitialisedMap() Dim expected As Integer = result @@ -68,10 +66,10 @@ Namespace UnitTests Assert.AreEqual(expected, actual) End Sub - <TestCase(3, 1, 12)> - <TestCase(3, 2, 48)> - <TestCase(3, 3, 12)> - <TestCase(3, 4, 48)> + + <TestCase(1, 1, 4)> + <TestCase(1, 3, 4)> + <TestCase(5, 4, 80)> _ Public Sub GetElectricalDemandTest(ByVal region As Integer, ByVal season As Integer, result As Integer) Dim target As HVACMap = GetInitialisedMap() Dim expected As Integer = result @@ -89,7 +87,6 @@ Namespace UnitTests End Class - End Namespace diff --git a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj index 73e9d2efc2b284418bbdfdf72f444e784958e956..99cf5a5de00702469d90fbae6ed73c877c55dd0d 100644 --- a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj +++ b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj @@ -60,6 +60,7 @@ </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> + <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" /> @@ -186,6 +187,13 @@ <Content Include="TestFiles\testHvacMapWrongColumns.csv"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> + <None Include="TestFiles\HVACMap.vaux" /> + <Content Include="TestFiles\TestHvacMap - ExtraBlankLines.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="TestFiles\TestHvacMap - MissingHeader.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> </ItemGroup> <ItemGroup> <ProjectReference Include="..\VectoAuxiliaries\VectoAuxiliaries.vbproj">