public void TestToString() { double x = 3; double y = 5; VectorPath path = new VectorPath(); Vector vector = new Vector(x, y); path.Add(vector); string expected = $"[{x};{y}] with magnitude {vector.Magnitude()}\n"; vector = new Vector(x, -y); path.Add(vector); expected += $"[{x};{-y}] with magnitude {vector.Magnitude()}\n"; vector = new Vector(-x, -y); path.Add(vector); expected += $"[{-x};{-y}] with magnitude {vector.Magnitude()}\n"; vector = new Vector(-x, y); path.Add(vector); expected += $"[{-x};{y}] with magnitude {vector.Magnitude()}"; Assert.Equal(expected, path.ToString()); }
public void TestResultingTwoVectors() { VectorPath path = new VectorPath(); path.Add(new Vector(3, 4)); path.Add(new Vector(5, -1)); Vector result = path.ResultingVector(); Assert.Equal(8, result.X(), 2); Assert.Equal(3, result.Y(), 2); }
public void TestResultingFourVectors() { VectorPath path = new VectorPath(); path.Add(new Vector(11.98, 0.63)); path.Add(new Vector(22.63, 22.63)); path.Add(new Vector(1.92, -0.55)); path.Add(new Vector(-3.36, 12.56)); Vector result = path.ResultingVector(); Assert.Equal(33.17, result.X(), 2); Assert.Equal(35.27, result.Y(), 2); }
static void Main(string[] args) { Console.WriteLine("Welcome to Vectors - From Start to End"); Console.WriteLine("This app allows you to insert mathematical vectors"); Console.WriteLine("and calculate the resulting total vector.\n"); VectorPath path = new VectorPath(); bool keepAddingVectors = true; do { Console.Write("Please enter the x and y coordinates (separated with space - both zero stops): "); string[] coordinates = Console.ReadLine().Split(" "); if (coordinates[0] != "0" && coordinates[0] != "0") { double x = Convert.ToDouble(coordinates[0]); double y = Convert.ToDouble(coordinates[1]); path.Add(new Vector(x, y)); } else { keepAddingVectors = false; } } while (keepAddingVectors); Console.WriteLine("\n-------------------------------------------------------"); Console.WriteLine("Summing all vector:"); Console.WriteLine(path); Console.WriteLine("\nThe resulting vector is: " + path.ResultingVector()); Console.WriteLine("-------------------------------------------------------"); Console.WriteLine("\nThank you for using our app"); }
public void TestResultingSingleVector() { VectorPath path = new VectorPath(); path.Add(new Vector(8, -22)); Vector result = path.ResultingVector(); Assert.Equal(8, result.X(), 2); Assert.Equal(-22, result.Y(), 2); }