Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 0592bdc1 authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

fix: use cultureinvariant parse for environmental conditions map and...

fix: use cultureinvariant parse for environmental conditions map and pneumatics compressor map, adapt exception in testcase due to changes in parsing
parent 578b8550
Branches
Tags
No related merge requests found
...@@ -14,7 +14,6 @@ Imports System.Globalization ...@@ -14,7 +14,6 @@ Imports System.Globalization
Namespace Electrics Namespace Electrics
Public Class CombinedAlternator Public Class CombinedAlternator
Implements IAlternatorMap, ICombinedAlternator Implements IAlternatorMap, ICombinedAlternator
...@@ -27,7 +26,8 @@ Public Class CombinedAlternator ...@@ -27,7 +26,8 @@ Public Class CombinedAlternator
Private AverageAlternatorsEfficiency As AlternatorMapValues Private AverageAlternatorsEfficiency As AlternatorMapValues
'Interface Implementation 'Interface Implementation
Public Function GetEfficiency(ByVal CrankRPM As Single, ByVal Amps As Single) As AlternatorMapValues Implements IAlternatorMap.GetEfficiency Public Function GetEfficiency(ByVal CrankRPM As Single, ByVal Amps As Single) As AlternatorMapValues _
Implements IAlternatorMap.GetEfficiency
altSignals.CrankRPM = CrankRPM altSignals.CrankRPM = CrankRPM
altSignals.CurrentDemandAmps = Amps / Alternators.Count altSignals.CurrentDemandAmps = Amps / Alternators.Count
...@@ -47,8 +47,8 @@ Public Class CombinedAlternator ...@@ -47,8 +47,8 @@ Public Class CombinedAlternator
End If End If
Return alternatorMapValues Return alternatorMapValues
End Function End Function
Public Function Initialise() As Boolean Implements IAlternatorMap.Initialise Public Function Initialise() As Boolean Implements IAlternatorMap.Initialise
'From the map we construct this CombinedAlternator object and original CombinedAlternator Object 'From the map we construct this CombinedAlternator object and original CombinedAlternator Object
...@@ -71,7 +71,6 @@ Public Class CombinedAlternator ...@@ -71,7 +71,6 @@ Public Class CombinedAlternator
Next Next
Return True Return True
End Function End Function
'Constructors 'Constructors
...@@ -120,7 +119,6 @@ Public Class CombinedAlternator ...@@ -120,7 +119,6 @@ Public Class CombinedAlternator
efficiencyAverage = efficiencySum / (Alternators.Count * 9) efficiencyAverage = efficiencySum / (Alternators.Count * 9)
AverageAlternatorsEfficiency = New AlternatorMapValues(efficiencyAverage / 100) AverageAlternatorsEfficiency = New AlternatorMapValues(efficiencyAverage / 100)
End Sub End Sub
'Helpers 'Helpers
...@@ -151,8 +149,6 @@ Public Class CombinedAlternator ...@@ -151,8 +149,6 @@ Public Class CombinedAlternator
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 10, 53, 3)) map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 10, 53, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 68, 70, 3)) map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 68, 70, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 136, 62, 3)) map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 136, 62, 3))
End Sub End Sub
'Grid Management 'Grid Management
...@@ -175,8 +171,8 @@ Public Class CombinedAlternator ...@@ -175,8 +171,8 @@ Public Class CombinedAlternator
Return returnValue Return returnValue
End Function End Function
Public Function AddAlternator(rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean Public Function AddAlternator(rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
If Not AddNewAlternator(rows, feedback) Then If Not AddNewAlternator(rows, feedback) Then
...@@ -185,9 +181,10 @@ Public Class CombinedAlternator ...@@ -185,9 +181,10 @@ Public Class CombinedAlternator
End If End If
Return True Return True
End Function End Function
Public Function DeleteAlternator(alternatorName As String, ByRef feedback As String, CountValidation As Boolean) As Boolean
Public Function DeleteAlternator(alternatorName As String, ByRef feedback As String, CountValidation As Boolean) _
As Boolean
'Is this the last alternator, if so deny the user the right to remove it. 'Is this the last alternator, if so deny the user the right to remove it.
If CountValidation AndAlso Alternators.Count < 2 Then If CountValidation AndAlso Alternators.Count < 2 Then
...@@ -211,7 +208,6 @@ Public Class CombinedAlternator ...@@ -211,7 +208,6 @@ Public Class CombinedAlternator
feedback = String.Format("The alternator {0} could not be removed : {1}", alternatorName, feedback) feedback = String.Format("The alternator {0} could not be removed : {1}", alternatorName, feedback)
Return False Return False
End If End If
End Function End Function
'Public Function UpdateAlternator( gridIndex As Integer, rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean 'Public Function UpdateAlternator( gridIndex As Integer, rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
...@@ -252,22 +248,31 @@ Public Class CombinedAlternator ...@@ -252,22 +248,31 @@ Public Class CombinedAlternator
'2000 - IE Alt1,2000,10,50,3 '2000 - IE Alt1,2000,10,50,3
For row = 1 To 3 For row = 1 To 3
amps = alt.InputTable2000(row).Amps : eff = alt.InputTable2000(row).Eff amps = alt.InputTable2000(row).Amps
sb.Append(alt.AlternatorName + ",2000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000")) eff = alt.InputTable2000(row).Eff
sb.Append(
alt.AlternatorName + ",2000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," +
alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("") sb.AppendLine("")
Next Next
'4000 - IE Alt1,2000,10,50,3 '4000 - IE Alt1,2000,10,50,3
For row = 1 To 3 For row = 1 To 3
amps = alt.InputTable4000(row).Amps : eff = alt.InputTable4000(row).Eff amps = alt.InputTable4000(row).Amps
sb.Append(alt.AlternatorName + ",4000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000")) eff = alt.InputTable4000(row).Eff
sb.Append(
alt.AlternatorName + ",4000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," +
alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("") sb.AppendLine("")
Next Next
'6000 - IE Alt1,2000,10,50,3 '6000 - IE Alt1,2000,10,50,3
For row = 1 To 3 For row = 1 To 3
amps = alt.InputTable6000(row).Amps : eff = alt.InputTable6000(row).Eff amps = alt.InputTable6000(row).Amps
sb.Append(alt.AlternatorName + ",6000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000")) eff = alt.InputTable6000(row).Eff
sb.Append(
alt.AlternatorName + ",6000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," +
alt.PulleyRatio.ToString("0.000"))
sb.AppendLine("") sb.AppendLine("")
Next Next
...@@ -284,15 +289,14 @@ Public Class CombinedAlternator ...@@ -284,15 +289,14 @@ Public Class CombinedAlternator
End Using End Using
Return returnValue Return returnValue
End Function End Function
Private Function Load() As Boolean Private Function Load() As Boolean
If Not InitialiseMap(FilePath) Then Return False If Not InitialiseMap(FilePath) Then Return False
Return True Return True
End Function End Function
'Initialises the map, only valid when loadingUI for first time in edit mode or always in operational mode. 'Initialises the map, only valid when loadingUI for first time in edit mode or always in operational mode.
...@@ -304,7 +308,8 @@ Public Class CombinedAlternator ...@@ -304,7 +308,8 @@ Public Class CombinedAlternator
If File.Exists(filePath) Then If File.Exists(filePath) Then
Using sr As StreamReader = New StreamReader(filePath) Using sr As StreamReader = New StreamReader(filePath)
'get array og lines fron csv 'get array og lines fron csv
Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()), StringSplitOptions.RemoveEmptyEntries) Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()),
StringSplitOptions.RemoveEmptyEntries)
'Must have at least 2 entries in map to make it usable [dont forget the header row] 'Must have at least 2 entries in map to make it usable [dont forget the header row]
If (lines.Count() < 10) Then If (lines.Count() < 10) Then
...@@ -329,7 +334,10 @@ Public Class CombinedAlternator ...@@ -329,7 +334,10 @@ Public Class CombinedAlternator
End If End If
'add values to map 'add values to map
map.Add(New CombinedAlternatorMapRow(elements(0), CType(elements(1), Single), CType(elements(2), Single), CType(elements(3), Single), CType(elements(4), Single))) map.Add(New CombinedAlternatorMapRow(elements(0), Single.Parse(elements(1), CultureInfo.InvariantCulture),
Single.Parse(elements(2), CultureInfo.InvariantCulture),
Single.Parse(elements(3), CultureInfo.InvariantCulture),
Single.Parse(elements(4), CultureInfo.InvariantCulture)))
Else Else
firstline = False firstline = False
...@@ -342,12 +350,11 @@ Public Class CombinedAlternator ...@@ -342,12 +350,11 @@ Public Class CombinedAlternator
End If End If
Return returnValue Return returnValue
End Function End Function
'Can be used to send messages to Vecto. 'Can be used to send messages to Vecto.
Public Event AuxiliaryEvent(ByRef sender As Object, message As String, messageType As AdvancedAuxiliaryMessageType) Implements IAuxiliaryEvent.AuxiliaryEvent Public Event AuxiliaryEvent(ByRef sender As Object, message As String, messageType As AdvancedAuxiliaryMessageType) _
Implements IAuxiliaryEvent.AuxiliaryEvent
'This is used to generate a diagnostics output which enables the user to 'This is used to generate a diagnostics output which enables the user to
'Determine if they beleive the resulting map is what is expected 'Determine if they beleive the resulting map is what is expected
...@@ -404,10 +411,7 @@ Public Class CombinedAlternator ...@@ -404,10 +411,7 @@ Public Class CombinedAlternator
'Next 'Next
Return sb.ToString() Return sb.ToString()
End Function End Function
...@@ -428,15 +432,8 @@ Public Class CombinedAlternator ...@@ -428,15 +432,8 @@ Public Class CombinedAlternator
Next Next
Return True Return True
End Function End Function
End Class End Class
End Namespace End Namespace
Imports System.IO Imports System.Globalization
Imports System.IO
Namespace Hvac Namespace Hvac
Public Class EnvironmentalConditionsMap Public Class EnvironmentalConditionsMap
Implements IEnvironmentalConditionsMap Implements IEnvironmentalConditionsMap
...@@ -16,7 +16,6 @@ Namespace Hvac ...@@ -16,7 +16,6 @@ Namespace Hvac
Me.vectoDirectory = vectoDirectory Me.vectoDirectory = vectoDirectory
Initialise() Initialise()
End Sub End Sub
Public Function Initialise() As Boolean Implements IEnvironmentalConditionsMap.Initialise Public Function Initialise() As Boolean Implements IEnvironmentalConditionsMap.Initialise
...@@ -29,7 +28,8 @@ Namespace Hvac ...@@ -29,7 +28,8 @@ Namespace Hvac
Using sr As StreamReader = New StreamReader(filePath) Using sr As StreamReader = New StreamReader(filePath)
'get array og lines fron csv 'get array og lines fron csv
Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()), StringSplitOptions.RemoveEmptyEntries) Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()),
StringSplitOptions.RemoveEmptyEntries)
'Must have at least 1 entries to make it usable [dont forget the header row] 'Must have at least 1 entries to make it usable [dont forget the header row]
If (lines.Count() < 2) Then If (lines.Count() < 2) Then
...@@ -50,7 +50,10 @@ Namespace Hvac ...@@ -50,7 +50,10 @@ Namespace Hvac
End If End If
'Add environment condition 'Add environment condition
Dim newCondition As EnvironmentalCondition = New EnvironmentalCondition(elements(1), elements(2), elements(3)) Dim newCondition As EnvironmentalCondition = New EnvironmentalCondition(
Double.Parse(elements(1), CultureInfo.InvariantCulture),
Double.Parse(elements(2), CultureInfo.InvariantCulture),
Double.Parse(elements(3), CultureInfo.InvariantCulture))
_map.Add(newCondition) _map.Add(newCondition)
...@@ -66,15 +69,12 @@ Namespace Hvac ...@@ -66,15 +69,12 @@ Namespace Hvac
End If End If
Return True Return True
End Function End Function
Public Function GetEnvironmentalConditions() As List(Of IEnvironmentalCondition) Implements IEnvironmentalConditionsMap.GetEnvironmentalConditions Public Function GetEnvironmentalConditions() As List(Of IEnvironmentalCondition) _
Implements IEnvironmentalConditionsMap.GetEnvironmentalConditions
Return _map Return _map
End Function End Function
End Class End Class
End Namespace End Namespace
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
' '
' See the LICENSE.txt for the specific language governing permissions and limitations. ' See the LICENSE.txt for the specific language governing permissions and limitations.
Imports System.Globalization
Imports System.IO Imports System.IO
Namespace Pneumatics Namespace Pneumatics
...@@ -76,7 +77,10 @@ Namespace Pneumatics ...@@ -76,7 +77,10 @@ Namespace Pneumatics
'4 entries per line required '4 entries per line required
If (elements.Length <> 4) Then Throw New ArgumentException("Incorrect number of values in csv file") If (elements.Length <> 4) Then Throw New ArgumentException("Incorrect number of values in csv file")
'add values to map 'add values to map
map.Add(elements(0), New CompressorMapValues(elements(1), elements(2), elements(3))) map.Add(Integer.Parse(elements(0)),
New CompressorMapValues(Single.Parse(elements(1), CultureInfo.InvariantCulture),
Single.Parse(elements(2), CultureInfo.InvariantCulture),
Single.Parse(elements(3), CultureInfo.InvariantCulture)))
Else Else
firstline = False firstline = False
End If End If
......
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
Imports VectoAuxiliaries.Pneumatics Imports VectoAuxiliaries.Pneumatics
Namespace UnitTests Namespace UnitTests
<TestFixture()> <TestFixture()>
Public Class CompressorMapTests Public Class CompressorMapTests
Private Const GOODMAP As String = "TestFiles\testCompressorMap.acmp" Private Const GOODMAP As String = "TestFiles\testCompressorMap.acmp"
Private Const INVALIDPOWERCOMPRESSORONMAP As String = "TestFiles\testCompressorMapInvalidOnPower.acmp" Private Const INVALIDPOWERCOMPRESSORONMAP As String = "TestFiles\testCompressorMapInvalidOnPower.acmp"
Private Const INVALIDPOWERCOMPRESSOROFFMAP As String = "TestFiles\testCompressorMapInvalidOffPower.acmp" Private Const INVALIDPOWERCOMPRESSOROFFMAP As String = "TestFiles\testCompressorMapInvalidOffPower.acmp"
...@@ -58,28 +56,28 @@ Namespace UnitTests ...@@ -58,28 +56,28 @@ Namespace UnitTests
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidRpmThrowsExceptionTest() Public Sub InitialisationInvalidRpmThrowsExceptionTest()
Dim path As String = INVALIDRPMMAP Dim path As String = INVALIDRPMMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidFlowRateThrowsExceptionTest() Public Sub InitialisationInvalidFlowRateThrowsExceptionTest()
Dim path As String = INVALIDFLOWRATEMAP Dim path As String = INVALIDFLOWRATEMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidPowerCompressorOnThrowsExceptionTest() Public Sub InitialisationInvalidPowerCompressorOnThrowsExceptionTest()
Dim path As String = INVALIDPOWERCOMPRESSORONMAP Dim path As String = INVALIDPOWERCOMPRESSORONMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
target.Initialise() target.Initialise()
End Sub End Sub
<Test(), ExpectedException("System.InvalidCastException")> <Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidPowerCompressorOffThrowsExceptionTest() Public Sub InitialisationInvalidPowerCompressorOffThrowsExceptionTest()
Dim path As String = INVALIDPOWERCOMPRESSOROFFMAP Dim path As String = INVALIDPOWERCOMPRESSOROFFMAP
Dim target As CompressorMap = New CompressorMap(path) Dim target As CompressorMap = New CompressorMap(path)
...@@ -111,9 +109,6 @@ Namespace UnitTests ...@@ -111,9 +109,6 @@ Namespace UnitTests
End Sub End Sub
<Test()> <Test()>
Public Sub GetPowerCompressorOnInterpolaitionTest() Public Sub GetPowerCompressorOnInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap() Dim target As CompressorMap = GetInitialiseMap()
...@@ -123,8 +118,6 @@ Namespace UnitTests ...@@ -123,8 +118,6 @@ Namespace UnitTests
End Sub End Sub
<Test()> <Test()>
Public Sub GetPowerCompressorOffInterpolaitionTest() Public Sub GetPowerCompressorOffInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap() Dim target As CompressorMap = GetInitialiseMap()
...@@ -134,7 +127,6 @@ Namespace UnitTests ...@@ -134,7 +127,6 @@ Namespace UnitTests
End Sub End Sub
<Test()> <Test()>
Public Sub InterpMiddle() Public Sub InterpMiddle()
...@@ -144,10 +136,6 @@ Namespace UnitTests ...@@ -144,10 +136,6 @@ Namespace UnitTests
Dim actual = target.GetFlowRate(1750) Dim actual = target.GetFlowRate(1750)
Assert.AreEqual(actual, 300) Assert.AreEqual(actual, 300)
End Sub End Sub
End Class End Class
End Namespace End Namespace
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment