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
No related tags found
No related merge requests found
......@@ -14,7 +14,6 @@ Imports System.Globalization
Namespace Electrics
Public Class CombinedAlternator
Implements IAlternatorMap, ICombinedAlternator
......@@ -27,7 +26,8 @@ Public Class CombinedAlternator
Private AverageAlternatorsEfficiency As AlternatorMapValues
'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.CurrentDemandAmps = Amps / Alternators.Count
......@@ -47,8 +47,8 @@ Public Class CombinedAlternator
End If
Return alternatorMapValues
End Function
Public Function Initialise() As Boolean Implements IAlternatorMap.Initialise
'From the map we construct this CombinedAlternator object and original CombinedAlternator Object
......@@ -71,7 +71,6 @@ Public Class CombinedAlternator
Next
Return True
End Function
'Constructors
......@@ -120,7 +119,6 @@ Public Class CombinedAlternator
efficiencyAverage = efficiencySum / (Alternators.Count * 9)
AverageAlternatorsEfficiency = New AlternatorMapValues(efficiencyAverage / 100)
End Sub
'Helpers
......@@ -151,8 +149,6 @@ Public Class CombinedAlternator
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 10, 53, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 68, 70, 3))
map.Add(New CombinedAlternatorMapRow("Alt2", 6000, 136, 62, 3))
End Sub
'Grid Management
......@@ -175,8 +171,8 @@ Public Class CombinedAlternator
Return returnValue
End Function
Public Function AddAlternator(rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
If Not AddNewAlternator(rows, feedback) Then
......@@ -185,9 +181,10 @@ Public Class CombinedAlternator
End If
Return True
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.
If CountValidation AndAlso Alternators.Count < 2 Then
......@@ -211,7 +208,6 @@ Public Class CombinedAlternator
feedback = String.Format("The alternator {0} could not be removed : {1}", alternatorName, feedback)
Return False
End If
End Function
'Public Function UpdateAlternator( gridIndex As Integer, rows As List(Of ICombinedAlternatorMapRow), ByRef feedback As String) As Boolean
......@@ -252,22 +248,31 @@ Public Class CombinedAlternator
'2000 - IE Alt1,2000,10,50,3
For row = 1 To 3
amps = alt.InputTable2000(row).Amps : eff = alt.InputTable2000(row).Eff
sb.Append(alt.AlternatorName + ",2000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"))
amps = alt.InputTable2000(row).Amps
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("")
Next
'4000 - IE Alt1,2000,10,50,3
For row = 1 To 3
amps = alt.InputTable4000(row).Amps : eff = alt.InputTable4000(row).Eff
sb.Append(alt.AlternatorName + ",4000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"))
amps = alt.InputTable4000(row).Amps
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("")
Next
'6000 - IE Alt1,2000,10,50,3
For row = 1 To 3
amps = alt.InputTable6000(row).Amps : eff = alt.InputTable6000(row).Eff
sb.Append(alt.AlternatorName + ",6000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"))
amps = alt.InputTable6000(row).Amps
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("")
Next
......@@ -284,15 +289,14 @@ Public Class CombinedAlternator
End Using
Return returnValue
End Function
Private Function Load() As Boolean
If Not InitialiseMap(FilePath) Then Return False
Return True
End Function
'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
If File.Exists(filePath) Then
Using sr As StreamReader = New StreamReader(filePath)
'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]
If (lines.Count() < 10) Then
......@@ -329,7 +334,10 @@ Public Class CombinedAlternator
End If
'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
firstline = False
......@@ -342,12 +350,11 @@ Public Class CombinedAlternator
End If
Return returnValue
End Function
'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
'Determine if they beleive the resulting map is what is expected
......@@ -404,10 +411,7 @@ Public Class CombinedAlternator
'Next
Return sb.ToString()
End Function
......@@ -428,15 +432,8 @@ Public Class CombinedAlternator
Next
Return True
End Function
End Class
End Namespace
Imports System.IO
Imports System.Globalization
Imports System.IO
Namespace Hvac
Public Class EnvironmentalConditionsMap
Implements IEnvironmentalConditionsMap
......@@ -16,7 +16,6 @@ Namespace Hvac
Me.vectoDirectory = vectoDirectory
Initialise()
End Sub
Public Function Initialise() As Boolean Implements IEnvironmentalConditionsMap.Initialise
......@@ -29,7 +28,8 @@ Namespace Hvac
Using sr As StreamReader = New StreamReader(filePath)
'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]
If (lines.Count() < 2) Then
......@@ -50,7 +50,10 @@ Namespace Hvac
End If
'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)
......@@ -66,15 +69,12 @@ Namespace Hvac
End If
Return True
End Function
Public Function GetEnvironmentalConditions() As List(Of IEnvironmentalCondition) Implements IEnvironmentalConditionsMap.GetEnvironmentalConditions
Public Function GetEnvironmentalConditions() As List(Of IEnvironmentalCondition) _
Implements IEnvironmentalConditionsMap.GetEnvironmentalConditions
Return _map
End Function
End Class
End Namespace
......@@ -9,6 +9,7 @@
'
' See the LICENSE.txt for the specific language governing permissions and limitations.
Imports System.Globalization
Imports System.IO
Namespace Pneumatics
......@@ -76,7 +77,10 @@ Namespace Pneumatics
'4 entries per line required
If (elements.Length <> 4) Then Throw New ArgumentException("Incorrect number of values in csv file")
'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
firstline = False
End If
......
......@@ -2,10 +2,8 @@
Imports VectoAuxiliaries.Pneumatics
Namespace UnitTests
<TestFixture()>
Public Class CompressorMapTests
Private Const GOODMAP As String = "TestFiles\testCompressorMap.acmp"
Private Const INVALIDPOWERCOMPRESSORONMAP As String = "TestFiles\testCompressorMapInvalidOnPower.acmp"
Private Const INVALIDPOWERCOMPRESSOROFFMAP As String = "TestFiles\testCompressorMapInvalidOffPower.acmp"
......@@ -58,28 +56,28 @@ Namespace UnitTests
target.Initialise()
End Sub
<Test(), ExpectedException("System.InvalidCastException")>
<Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidRpmThrowsExceptionTest()
Dim path As String = INVALIDRPMMAP
Dim target As CompressorMap = New CompressorMap(path)
target.Initialise()
End Sub
<Test(), ExpectedException("System.InvalidCastException")>
<Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidFlowRateThrowsExceptionTest()
Dim path As String = INVALIDFLOWRATEMAP
Dim target As CompressorMap = New CompressorMap(path)
target.Initialise()
End Sub
<Test(), ExpectedException("System.InvalidCastException")>
<Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidPowerCompressorOnThrowsExceptionTest()
Dim path As String = INVALIDPOWERCOMPRESSORONMAP
Dim target As CompressorMap = New CompressorMap(path)
target.Initialise()
End Sub
<Test(), ExpectedException("System.InvalidCastException")>
<Test(), ExpectedException("System.FormatException")>
Public Sub InitialisationInvalidPowerCompressorOffThrowsExceptionTest()
Dim path As String = INVALIDPOWERCOMPRESSOROFFMAP
Dim target As CompressorMap = New CompressorMap(path)
......@@ -111,9 +109,6 @@ Namespace UnitTests
End Sub
<Test()>
Public Sub GetPowerCompressorOnInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap()
......@@ -123,8 +118,6 @@ Namespace UnitTests
End Sub
<Test()>
Public Sub GetPowerCompressorOffInterpolaitionTest()
Dim target As CompressorMap = GetInitialiseMap()
......@@ -134,7 +127,6 @@ Namespace UnitTests
End Sub
<Test()>
Public Sub InterpMiddle()
......@@ -144,10 +136,6 @@ Namespace UnitTests
Dim actual = target.GetFlowRate(1750)
Assert.AreEqual(actual, 300)
End Sub
End Class
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