I'm making unit-tests for this class, a triangle class that takes the sides and determines if the triangle is scalene, isosceles or equilateral.
public struct Point
{
public int x, y;
public Point(int a, int b)
{
x = a;
y = b;
}
}
public class Triangle
{
double[] sides;
public Triangle(double a, double b, double c)
{
if ((a <= 0) || (b <= 0) || (c <= 0))
{
throw new ArgumentException(" ");
}
sides = new double[] { a, b, c };
}
public Triangle(double[] s)
{
sides = new double[s.Length];
for (int i = 0; i < s.Length; i++)
sides[i] = s[i];
}
public Triangle(Point a, Point b, Point c)
{
sides = new double[3];
sides[0] = Math.Sqrt(Math.Pow((double)(b.x - a.x), 2.0) + Math.Pow((double)(b.y - a.y), 2.0));
sides[1] = Math.Sqrt(Math.Pow((double)(b.x - c.x), 2.0) + Math.Pow((double)(b.x - a.x), 2.0));
sides[2] = Math.Sqrt(Math.Pow((double)(c.x - a.x), 2.0) + Math.Pow((double)(c.x - a.x), 2.0));
}
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));
}
private int uniqueSides()
{
return sides.Distinct<double>().Count();
}
public bool isScalene()
{
if (uniqueSides() == 1)
return true;
return false;
}
public bool isEquilateral()
{
if (uniqueSides() == 3)
return true;
return false;
}
public bool isIsosceles()
{
if (uniqueSides() == 2)
return true;
return false;
}
}
}
The isScaleneTest is failing, and I can't figure out why?
[TestMethod()]
public void isScaleneTest()
{
Triangle target = new Triangle(1.2, 2.1, 7.1);
Assert.IsTrue(target.isScalene());
}
I also have problem figuring out how to test the other methods. isEquilateral and isIsosceles is tested and passes, but I can't get any other test to pass. Any ideas? Is there any point to testing the constructor? Thanks for help.