Skip to content

Commit 5d1d7de

Browse files
committed
Added more unit tests
1 parent bb4b0b4 commit 5d1d7de

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/UnitTestProject1/Strings/StringTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Globalization;
23
using System.Net;
4+
using System.Threading;
35
using Microsoft.VisualStudio.TestTools.UnitTesting;
46
using Skybrud.Essentials.Strings;
57
using Skybrud.Essentials.Strings.Extensions;
@@ -169,6 +171,55 @@ public void ParseInt64Array() {
169171

170172
}
171173

174+
[TestMethod]
175+
public void ParseDouble() {
176+
177+
Assert.AreEqual(0, StringUtils.ParseDouble(null), "Check #1 failed");
178+
Assert.AreEqual(0, StringUtils.ParseDouble(""), "Check #2 failed");
179+
180+
Assert.AreEqual(3.14, StringUtils.ParseDouble("3.14"), "Check #3 failed");
181+
182+
// Danish decimal separator is treated as thousand separator due to invariant culture
183+
Assert.AreEqual(314, StringUtils.ParseDouble("3,14"), "Check #4 failed");
184+
Assert.AreEqual(3140, StringUtils.ParseDouble("3,140"), "Check #5 failed");
185+
186+
}
187+
188+
[TestMethod]
189+
public void ParseDoubleDanish() {
190+
191+
CultureInfo culture = CultureInfo.CurrentUICulture;
192+
Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
193+
194+
ParseDouble();
195+
196+
Thread.CurrentThread.CurrentCulture = culture;
197+
198+
}
199+
200+
[TestMethod]
201+
public void ParseDoubleArray() {
202+
203+
double[] result = StringUtils.ParseDoubleArray("3.14 -1.234567");
204+
205+
Assert.AreEqual(2, result.Length, "Check #1 failed");
206+
Assert.AreEqual(3.14, result[0], "Check #2 failed");
207+
Assert.AreEqual(-1.234567, result[1], "Check #2 failed");
208+
209+
}
210+
211+
[TestMethod]
212+
public void ParseDoubleArrayDanish() {
213+
214+
CultureInfo culture = CultureInfo.CurrentUICulture;
215+
Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK");
216+
217+
ParseDoubleArray();
218+
219+
Thread.CurrentThread.CurrentCulture = culture;
220+
221+
}
222+
172223
[TestMethod]
173224
public void ParseGuidArray() {
174225

0 commit comments

Comments
 (0)