I'm working on a laboratory practical with unit-testing, and below is a piece of code from the application that i'm testing. Most of the unit-testings are finished, but regarding the constructor below I just can't figure out how to test it. For example, what exactly is the constructor doing with the array elements? What would be a good way of testing the construtor?
Is there maybe a kind soul out there who could give me a kick in the right direction?
public struct Point {
public int x, y;
public Point(int a, int b) {
x = a;
y = b;
}
}
...
public Triangle(Point[] s) {
sides = new double[s.Length];
sides[0] = Math.Sqrt(Math.Pow((double)(s[1].x - s[0].x), 2.0) + Math.Pow((double)(s[1].y - s[0].y), 2.0));
sides[1] = Math.Sqrt(Math.Pow((double)(s[1].x - s[2].x), 2.0) + Math.Pow((double)(s[1].x - s[2].x), 2.0));
sides[2] = Math.Sqrt(Math.Pow((double)(s[2].x - s[0].x), 2.0) + Math.Pow((double)(s[2].x - s[0].x), 2.0));
}
...
[TestMethod()]
public void TriangleConstructorTest1()
{
Point[] s = null; // TODO: Initialize to an appropriate value
Triangle target = new Triangle(s);
Assert.Inconclusive("TODO: Implement code to verify target");
}
Perhaps I'm missing something but won't this do it?
[TestMethod()]
public void PointConstructorTest1()
{
Point target = new Point(1.5, 2.0);
Assert.AreEqual(1.5, target.x);
Assert.AreEqual(2.0, target.y);
}
Not much point in testing variable assigning though really....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With