public void Problem1_PointClass_SideAffecting() { // Instantiate the problem var target = new Problem1(); // Set up the test int x = 5; int y = 10; var pointClass = new PointClass(x, y); target.DoubleTheTargetPointClass(pointClass); // Assert truths. Assert.IsNotNull(pointClass); Assert.AreEqual(x * 2, pointClass.X); Assert.AreEqual(y * 2, pointClass.Y); }
public void Problem1_PointClass_WithReturnValue() { // Instantiate the problem var target = new Problem1(); // Set up the test int x = 590; int y = 37; var pointClass = new PointClass(x, y); var result = target.ReturnADoubledPointClass(pointClass); // Assert truths. Assert.IsNotNull(result); Assert.AreNotSame(result, pointClass); Assert.AreEqual(x * 2, result.X); Assert.AreEqual(y * 2, result.Y); }
/// <summary> /// Return a *new* point class whose X and Y values are twice those of the input /// instance. /// </summary> /// <param name="pointClass"> /// The input class whose X and Y to double. /// </param> /// <returns> /// A new instance of the point class whose X and Y values are double those of the /// input. /// </returns> public PointClass ReturnADoubledPointClass(PointClass pointClass) { var myNewPoint = new PointClass(pointClass.X * 2, pointClass.Y * 2); return myNewPoint; }
/// <summary> /// Modify the passed in point class such that the X and Y values are twice their /// original values. Note that this is called a Side Affecting method, and it's /// generally bad practice to write code like this. Nevertheless, it is instructional /// to see the difference between structs and reference types. We should be able to /// modify the class and have the changes stick--something that's impossible to do with /// structs unless we pass the new value out of the method. /// </summary> /// <param name="pointClass"> /// The target point class to double. /// </param> public void DoubleTheTargetPointClass(PointClass pointClass) { throw new NotImplementedException(); }