|
1 | 1 | using System; |
| 2 | +using System.Globalization; |
2 | 3 | using System.Net; |
| 4 | +using System.Threading; |
3 | 5 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
4 | 6 | using Skybrud.Essentials.Strings; |
5 | 7 | using Skybrud.Essentials.Strings.Extensions; |
@@ -169,6 +171,55 @@ public void ParseInt64Array() { |
169 | 171 |
|
170 | 172 | } |
171 | 173 |
|
| 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 | + |
172 | 223 | [TestMethod] |
173 | 224 | public void ParseGuidArray() { |
174 | 225 |
|
|
0 commit comments