public void Add() { var p1 = new XY(1, 2); var p2 = p1; p2.Add(p1); Assert.AreEqual(new XY(2, 4), p2); Assert.AreEqual(new XY(2, 4), p1.Added(new XY(1, 2))); p2 += new XY(1, 2); Assert.AreEqual(new XY(3, 6), p2); }
public void ValueType_XY() { var p1 = new XY(1, 2); var p2 = new XY(4, 5); Assert.AreEqual(5, p1.SquareModulus()); Assert.AreEqual(Math.Sqrt(5), p1.Modulus()); Assert.IsTrue(p1.IsEqual(p2, 3)); Assert.IsFalse(p1.IsEqual(p2, 2.99)); p2 = p1; p2.Add(new XY(1, 2)); Assert.AreEqual(new XY(2, 4), p2); Assert.AreEqual(new XY(2, 4), p1.Added(new XY(1, 2))); p2 += new XY(1, 2); Assert.AreEqual(new XY(3, 6), p2); Assert.AreEqual(-4, p1.Crossed(new XY(3, 2))); Assert.AreEqual(Math.Sqrt(16), p1.CrossMagnitude(new XY(3, 2))); Assert.AreEqual(16, p1.CrossSquareMagnitude(new XY(3, 2))); p2 = new XY(1, 2); p2.Divide(2); Assert.AreEqual(new XY(0.5, 1), p2); Assert.AreEqual(new XY(0.5, 1), p1.Divided(2)); Assert.AreEqual(5, p1.Dot(new XY(1, 2))); p2 = new XY(1, 2); p2.Multiply(2); Assert.AreEqual(new XY(2, 4), p2); Assert.AreEqual(new XY(2, 4), p1.Multiplied(2)); Assert.AreEqual(new XY(2, 4), p1 * 2); p2 = new XY(1, 2); p2.Multiply(new XY(1, 2)); Assert.AreEqual(new XY(1, 4), p2); Assert.AreEqual(new XY(1, 4), p1.Multiplied(new XY(1, 2))); Assert.AreEqual(new XY(1, 4), p1 * new XY(1, 2)); Mat2d m1 = new Mat2d(); m1.SetRotation(Math.PI / 2); p2 = new XY(4, 5); Assert.AreEqual("-5,4", p2.Multiplied(m1).ToString()); Assert.AreEqual("-5,4", (p2 * m1).ToString()); p2.Multiply(m1); Assert.AreEqual("-5,4", p2.ToString()); p2 = new XY(1, 23); Assert.AreEqual("0.0434372242763069,0.99905615835506", p2.Normalized().ToString()); p2.Normalize(); Assert.AreEqual("0.0434372242763069,0.99905615835506", p2.ToString()); p2 = new XY(1, 2); p2.Reverse(); Assert.AreEqual(new XY(-1, -2), p2); Assert.AreEqual(new XY(-1, -2), p1.Reversed()); p2 = new XY(1, 2); p2.Subtract(new XY(3, 2)); Assert.AreEqual(new XY(-2, 0), p2); Assert.AreEqual(new XY(-2, 0), p1.Subtracted(new XY(3, 2))); Assert.AreEqual(new XY(-2, 0), p1 - new XY(3, 2)); p2.SetLinearForm(new XY(1, 2), new XY(4, 5)); Assert.AreEqual(new XY(5, 7), p2); p2.SetLinearForm(2, new XY(1, 2), new XY(4, 5)); Assert.AreEqual(new XY(6, 9), p2); p2.SetLinearForm(2, new XY(1, 2), 3, new XY(4, 5)); Assert.AreEqual(new XY(14, 19), p2); p2.SetLinearForm(2, new XY(1, 2), 3, new XY(4, 5), new XY(7, 8)); Assert.AreEqual(new XY(21, 27), p2); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1}", gp2.x, gp2.y)); //TestContext.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0},{1}", new gp_XY(1, 23).Normalized().X(), new gp_XY(1, 23).Normalized().Y())); }