public string[] Get(string vertex1, string vertex2, string vertex3)
        {
            List <Point> points = new List <Point>();
            Point        point1 = ParsePoint(vertex1);
            Point        point2 = ParsePoint(vertex2);
            Point        point3 = ParsePoint(vertex3);

            points.Add(point1);
            points.Add(point2);
            points.Add(point3);

            TriangleValidator validator = new TriangleValidator(point1, point2, point3);

            if (!validator.IsValid())
            {
                return(new string[] { "INVALID COORDINATES" });
            }

            string row = ROWS[GetMin_Y(points) / 10];

            int col = -1;

            if (IsTheTriangleInEvenNumberPosition(points, GetMax_X(points)))
            {
                col = GetMax_X(points) * 2 / 10;
            }
            else
            {
                col = (GetMin_X(points) * 2 / 10) + 1;
            }
            return(new string[] { row + col });
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int a, b, c = 0;
            ITriangleValidator    validator = new TriangleValidator();
            ITriangleDeterminator service   = new TriangleDeterminatorService(validator);

            Console.WriteLine("Guess the triangle");
            Console.WriteLine("==================");

            Console.Write("Enter length of Side 1 :");
            a = GetInt();

            Console.Write("Enter length of Side 2 :");
            b = GetInt();

            Console.Write("Enter length of Side 3 :");
            c = GetInt();

            Console.WriteLine();

            if (!validator.IsValid(a, b, c))
            {
                Console.WriteLine("Sorry, this is not a valid triangle.");
            }
            else
            {
                Console.WriteLine($"Your triangle is a {service.Determine(a, b, c)} triangle.");
            }

            Console.WriteLine("Press a key to exit.");
            Console.ReadKey();
        }
Esempio n. 3
0
        public void Test_ValidatorInvalidTriangle4_Ok()
        {
            //given
            ITriangleValidator validator = new TriangleValidator();

            //when
            bool isValid = validator.IsValid(-4, -4, -4);

            //then
            Assert.False(isValid);
        }
        [DataRow(50, 50, 50, 60, 60, 60)] //F11
        public void TriangleValidationDoesAllowTrianglesOnTheInsideEdgeOfTheGrid(int point1_X, int point1_y, int point2_X, int point2_y, int point3_X, int point3_y)
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(point1_X, point1_y), new Point(point2_X, point2_y), new Point(point3_X, point3_y));

            Assert.IsTrue(triangleValidator.IsValid(), "Triangle is out of bounds");
        }
        public void TriangleValidationDoesAllowTrianglesOutOfTheAllowedGridBottomRight(int point1_X, int point1_y, int point2_X, int point2_y, int point3_X, int point3_y)
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(point1_X, point1_y), new Point(point2_X, point2_y), new Point(point3_X, point3_y));

            Assert.IsFalse(triangleValidator.IsValid(), "Triangle is out of bounds");
        }
        public void TriangleValidationDoesAllowHypotenusTopRightToBottomLeft(int point1_X, int point1_y, int point2_X, int point2_y, int point3_X, int point3_y)
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(point1_X, point1_y), new Point(point2_X, point2_y), new Point(point3_X, point3_y));

            Assert.IsTrue(triangleValidator.IsValid(), "Invalid Triangle coordinates right angle is only allowed bottom left or top right");
        }
        public void TriangleValidationDoesNotAllowRightSidesAreNotOfLength10(int point1_X, int point1_y, int point2_X, int point2_y, int point3_X, int point3_y)
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(point1_X, point1_y), new Point(point2_X, point2_y), new Point(point3_X, point3_y));

            Assert.IsFalse(triangleValidator.IsValid(), "Triangle vertices do not have sides length 10");
        }
        public void TriangleRightSidesAreOfLength10()
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(20, 20), new Point(20, 30), new Point(30, 30));

            Assert.IsTrue(triangleValidator.IsValid(), "Triangle vertices are not located on 10x10 grid");
        }
        public void TriangleVerticesAreNotValidWhenTheyAreNot10PixelsApartPerAxis()
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(1, 0), new Point(0, 0), new Point(10, 0));

            Assert.IsFalse(triangleValidator.IsValid(), "Triangle vertices are not located on 10x10 grid");
        }
        public void TriangleVerticesAre10PixelsApartPerAxis()
        {
            TriangleValidator triangleValidator = new TriangleValidator(new Point(0, 0), new Point(0, 10), new Point(10, 10));

            Assert.IsTrue(triangleValidator.IsValid(), "Triangle vertices are not located on 10x10 grid");
        }
 public void TriangleValidator_Valid_1()
 {
     Assert.AreEqual(true, TriangleValidator.IsValid(3, 4, 5));
 }
 public void TriangleValidator_Invalid_3()
 {
     Assert.AreEqual(false, TriangleValidator.IsValid(25, 5, 10));
 }
 public void TriangleValidator_Invalid_2()
 {
     Assert.AreEqual(false, TriangleValidator.IsValid(10, 25, 5));
 }
 public void TriangleValidator_Valid_3()
 {
     Assert.AreEqual(true, TriangleValidator.IsValid(4, 5, 3));
 }
 public void TriangleValidator_Valid_2()
 {
     Assert.AreEqual(true, TriangleValidator.IsValid(5, 4, 3));
 }