public void StringInterop() { var v = new double4(4.5d, -4d, -8.5d, -5d); var s0 = v.ToString(); var s1 = v.ToString("#"); var v0 = double4.Parse(s0); var v1 = double4.Parse(s1, "#"); Assert.AreEqual(v, v0); Assert.AreEqual(v, v1); var b0 = double4.TryParse(s0, out v0); var b1 = double4.TryParse(s1, "#", out v1); Assert.That(b0); Assert.That(b1); Assert.AreEqual(v, v0); Assert.AreEqual(v, v1); b0 = double4.TryParse(null, out v0); Assert.False(b0); b0 = double4.TryParse("", out v0); Assert.False(b0); b0 = double4.TryParse(s0 + ", 0", out v0); Assert.False(b0); Assert.Throws <NullReferenceException>(() => { double4.Parse(null); }); Assert.Throws <FormatException>(() => { double4.Parse(""); }); Assert.Throws <FormatException>(() => { double4.Parse(s0 + ", 0"); }); var s2 = v.ToString(";", CultureInfo.InvariantCulture); Assert.That(s2.Length > 0); var s3 = v.ToString("; ", "G"); var s4 = v.ToString("; ", "G", CultureInfo.InvariantCulture); var v3 = double4.Parse(s3, "; ", NumberStyles.Number); var v4 = double4.Parse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture); Assert.AreEqual(v, v3); Assert.AreEqual(v, v4); var b4 = double4.TryParse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture, out v4); Assert.That(b4); Assert.AreEqual(v, v4); }
public void ToString_CultureDE() { string s = "(1,5; 1,5; 1,5; 1,5)"; double4 d = double4.One * 1.5d; Assert.Equal(s, d.ToString(new CultureInfo("de-DE"))); }
public void ToString_InvariantCulture() { string s = "(1.5, 1.5, 1.5, 1.5)"; double4 d = double4.One * 1.5f; Assert.Equal(s, d.ToString(CultureInfo.InvariantCulture)); }
public void ConvertFromDouble4(int i, float f, double d, bool isTrue, string text, double2 d2, double3 d3, double4 d4, double4x4 d4x4, float2 f2, float3 f3, float4 f4, float4x4 f4x4) { text = d4.ToString(); d4x4 = new double4x4(d4, new double4(0, 0, 0, 0), new double4(0, 0, 0, 0), new double4(0, 0, 0, 0)); f4x4 = new float4x4(f4, new float4(0, 0, 0, 0), new float4(0, 0, 0, 0), new float4(0, 0, 0, 0)); ConverterClass source = new ConverterClass(); ConverterClass expected = new ConverterClass(); Node root = new Node(source); Node node = new Node(expected); Circuit circuit = new Circuit(); circuit.AddNode(root); circuit.AddNode(node); circuit.AddRoot(root); source.d4 = d4; root.Attach("d4", node, "i"); root.Attach("d4", node, "f"); root.Attach("d4", node, "d"); root.Attach("d4", node, "isTrue"); root.Attach("d4", node, "text"); root.Attach("d4", node, "d2"); root.Attach("d4", node, "d3"); root.Attach("d4", node, "d4"); root.Attach("d4", node, "d4x4"); root.Attach("d4", node, "f2"); root.Attach("d4", node, "f3"); root.Attach("d4", node, "f4"); root.Attach("d4", node, "f4x4"); circuit.Execute(); Assert.True(expected.i == i, "Error when parsing to int: Should be " + i + " but is " + expected.i + "."); Assert.True(expected.f == f, "Error when parsing to float: Should be " + f + " but is " + expected.f + "."); Assert.True(expected.d == d, "Error when parsing to double: Should be " + d + " but is " + expected.d + "."); Assert.True(expected.isTrue == isTrue, "Error when parsing to bool: Should be " + isTrue + " but is " + expected.isTrue + "."); Assert.True(expected.text == text, "Error when parsing to string: Should be " + text + " but is " + expected.text + "."); Assert.True(expected.d2 == d2, "Error when parsing to double2: Should be " + d2 + " but is " + expected.d2 + "."); Assert.True(expected.d3 == d3, "Error when parsing to double3: Should be " + d3 + " but is " + expected.d3 + "."); Assert.True(expected.d4 == d4, "Error when parsing to double4: Should be " + d4 + " but is " + expected.d4 + "."); Assert.True(expected.d4x4 == d4x4, "Error when parsing to double4x4: Should be " + d4x4 + " but is " + expected.d4x4 + "."); Assert.True(expected.f2 == f2, "Error when parsing to float2: Should be " + f2 + " but is " + expected.f2 + "."); Assert.True(expected.f3 == f3, "Error when parsing to float3: Should be " + f3 + " but is " + expected.f3 + "."); Assert.True(expected.f4 == f4, "Error when parsing to float4: Should be " + f4 + " but is " + expected.f4 + "."); Assert.True(expected.f4x4 == f4x4, "Error when parsing to float4x4: Should be " + f4x4 + " but is " + expected.f4x4 + "."); }
/// <summary> /// Returns a string representation of this vector using a provided seperator and a format and format provider for each component. /// </summary> public static string ToString(double4 v, string sep, string format, IFormatProvider provider) => v.ToString(sep, format, provider);
/// <summary> /// Returns a string representation of this vector using a provided seperator and a format for each component. /// </summary> public static string ToString(double4 v, string sep, string format) => v.ToString(sep, format);
/// <summary> /// Returns a string representation of this vector using a provided seperator. /// </summary> public static string ToString(double4 v, string sep) => v.ToString(sep);
/// <summary> /// Returns a string representation of this vector using ', ' as a seperator. /// </summary> public static string ToString(double4 v) => v.ToString();
public void Parse_ToString_CultureDE() { double4 d = double4.One * 1.5d; Assert.Equal(d, double4.Parse(d.ToString(new CultureInfo("de-DE")), new CultureInfo("de-DE"))); }
public void Parse_ToString_InvariantCulture() { double4 d = double4.One * 1.5d; Assert.Equal(d, double4.Parse(d.ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture)); }
public void Parse_ToString_NoCulture() { double4 d = double4.One * 1.5d; Assert.Equal(d, double4.Parse(d.ToString())); }