public Triangle(decimal _sideA, decimal _sideB, decimal _sideC) { sideA = _sideA; sideB = _sideB; sideC = _sideC; triangleFactory = new ProduceTrangle(); }
static void Main(string[] args) { try { Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); IViewer figuresViwer = new Viewer(DefaultSettings.START_MESSAGE); TriangleValidatorFactory validatorCreator = new TriangleValidatorFactory(); IFigureValidator triangleChecker = validatorCreator.Create(); TriangleFactory triangleBuilder = new TriangleFactory(); FigureComparerBySquareFactory creator = new FigureComparerBySquareFactory(); IComparer <IFigure> triangleComparer = creator.Create(); IContinueChecker continueChecker = new ContinueChecker(new string[] { DefaultSettings.FIRST_ANSWER, DefaultSettings.SECOND_ANSWER }); INumbericsValidator numbersChecker = new NumbericsValidator(); FiguresSorterByDescendingFactory sorterFactory = new FiguresSorterByDescendingFactory(); ConsoleController application = new ConsoleController(DefaultSettings.INSTRUCTION, continueChecker, numbersChecker, triangleChecker, triangleBuilder, triangleComparer, sorterFactory, figuresViwer); application.Run(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(DefaultSettings.INSTRUCTION); } Console.ReadKey(); }
static void Main(string[] args) { iIOmethod ioMethod = new ConsoleIO(); Console.WriteLine("1. Circle"); iFigureFactory factory = new CircleFactory(ioMethod); iFigure fig = factory.create(); Console.WriteLine("Circle square = " + fig.getSquare()); Console.WriteLine("2. Triangle"); factory = new TriangleFactory(ioMethod); fig = factory.create(); Console.WriteLine("Triangle square = " + fig.getSquare()); Triangle triangle = fig as Triangle; if (triangle != null) { Console.WriteLine("Is this a right triangle? " + (triangle.isRightAngle() ? "Yes!!" : "No!")); } Console.WriteLine(); Console.WriteLine("Happy end! Press a key.."); Console.ReadKey(); }
public void TriangleFactory_isTriangleOK() { TriangleFactory factory = new TriangleFactory(null); Assert.AreEqual(true, factory.isTriangleOK(3, 10, 7)); Assert.AreEqual(false, factory.isTriangleOK(1, 2, 15)); }
public void Create_ShouldReturnIFigure(string name, double[] sides) { var factory = new TriangleFactory(name, sides[0], sides[1], sides[2]); //assert Assert.IsAssignableFrom <IFigure>(factory.Create()); }
public void TestTriangle() { IFigureFactorory figureFactory = new TriangleFactory(3, 4, 5); IFigure figure = figureFactory.Create(); Assert.AreEqual(Math.Round(figure.Square), 6); }
private void toolStripButtonTriangle_Click(object sender, EventArgs e) { CurrentFactory = new TriangleShapeFactory(); Factory current = new TriangleFactory(pnlMain); CurrentDrawman = current.FactoryMethod(); }
public void ThrowsIfThereAreNotThreeCoordinates() { TriangleFactory factory = new TriangleFactory(); Assert.Throws <ArgumentException>(() => factory.ToTriangle(new Collection <Coordinate>())); }
public Triangle() { sideA = default(decimal); sideB = default(decimal); sideC = default(decimal); triangleFactory = new ProduceTrangle(); }
public void TriangleFactory_DefineGenericTriangle_Failure() { var figure = new TriangleFactory(); Assert.Null(figure.GetTriangle(1, 2, 3)); Assert.Null(figure.GetTriangle(0, 2, 3)); Assert.Null(figure.GetTriangle(1, -2, 3)); }
public void TriangleFactory_DefineRightTriangle_Success() { var figure = new TriangleFactory(); Assert.True(figure.GetTriangle(1, 2, 2) is RightTriangle); Assert.True(figure.GetTriangle(2, 1, 2) is RightTriangle); Assert.True(figure.GetTriangle(2, 2, 1) is RightTriangle); Assert.True(figure.GetTriangle(2, 2, 2) is RightTriangle); }
public static IShapeService GetShapeService() { IShapeValidator typeValidator = new TriangleValidator(); IShapeFactory shapeFactory = new TriangleFactory(typeValidator); // Compose shape factory IShapeFactory UnknownShapeFacotry = new UnknownShapeFactory(); var genericShapeValidator = new GenericShapeValidator(); return(new ShapeService(shapeFactory, UnknownShapeFacotry, genericShapeValidator)); // Compose shape service }
public void CalculateName_Should_Return_Correct_Name_Tests(Vertex v1, Vertex v2, Vertex v3, string expected) { //Arrange var triangle = new TriangleFactory().Create(v1, v2, v3); //Act var actual = triangle.CalculateName(); //Assert Assert.That(actual, Does.Contain(expected)); }
public void Create_Should_Return_Triangle_Tests(Vertex v1, Vertex v2, Vertex v3) { //Arrange //Act var actual = new TriangleFactory().Create(v1, v2, v3); //Assert Assert.IsInstanceOf <Triangle>(actual); Assert.IsNotInstanceOf <InvalidTriangle>(actual); }
private void btnCreate_Click(object sender, EventArgs e) { if (cmboShapeType.SelectedItem is null) { errorMessage("Please select a type of shape"); } else if (ValidateInfo()) { ShapeFactory factory = null; switch (cmboShapeType.SelectedItem.ToString()) { case "Circle": Shapes.Point CirclePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new CircleFactory(CirclePoint, Int32.Parse(txtRadius1.Text)); break; case "Ellipse": Shapes.Point EllipsePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new EllipseFactory(EllipsePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text)); break; case "Rectangle": Shapes.Point RectanglePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new RectangleFactory(RectanglePoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text)); break; case "Square": Shapes.Point SquarePoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new SquareFactory(SquarePoint, Int32.Parse(txtRadius1.Text)); break; case "Triangle": Shapes.Point TriPoint1 = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); Shapes.Point TriPoint2 = new Shapes.Point(Int32.Parse(txtPoint2X.Text), Int32.Parse(txtPoint2Y.Text)); Shapes.Point TriPoint3 = new Shapes.Point(Int32.Parse(txtPoint3X.Text), Int32.Parse(txtPoint3Y.Text)); factory = new TriangleFactory(TriPoint1, TriPoint2, TriPoint3); break; case "Composite Image": factory = new CompositeImageFactory(filepath); break; case "Embedded Pic": Shapes.Point EmbeddedPoint = new Shapes.Point(Int32.Parse(txtPoint1X.Text), Int32.Parse(txtPoint1Y.Text)); factory = new EmbeddedPicFactory(EmbeddedPoint, Int32.Parse(txtRadius1.Text), Int32.Parse(txtRadius2.Text), filepath); break; } Shape shape = factory.GetShape(); Console.WriteLine(shape.ShapeType); shapeToDraw = shape; this.Close(); } }
public void TriangleFactory_ShouldValidateTriangleExistence(double sideOne, double sideTwo, double sideThree) { // Arrange var parameters = new double[] { sideOne, sideTwo, sideThree }; var factory = new TriangleFactory(); // Act var result = factory.TryParseFigureParameters(parameters, out _); // Assert Assert.False(result); }
public void ReturnsTriangleIfInputAreValid( string designation, Triangle expected) { TriangleFactory factory = new TriangleFactory(); Triangle result = factory.ToTriangle(designation); Assert.True(expected.Designation.Column == result.Designation.Column); Assert.True(expected.Designation.Row == result.Designation.Row); Assert.True(result.Coordinates.Count == 3); }
public void ThrowsIfAnyCoordinateIsInvalid() { TriangleFactory factory = new TriangleFactory(); Assert.Throws <ArgumentException>(() => factory.ToTriangle(new Collection <Coordinate>() { new Coordinate(10, 10), new Coordinate(10, 10), new Coordinate(10, 7) } )); }
public void TriangleFactory_ShouldValidateParametersLength(int parametersLength) { // Arrange var parameters = new double[parametersLength]; var factory = new TriangleFactory(); // Act var result = factory.TryParseFigureParameters(parameters, out var message); // Assert Assert.False(result); Assert.Equal("Triangle parameters array must contain 3 values for triangle sides", message); }
public void TriangleFactory_ShouldValidateTriangleSideValues(double sideOne, double sideTwo, double sideThree) { // Arrange var parameters = new double[] { sideOne, sideTwo, sideThree }; var factory = new TriangleFactory(); // Act var result = factory.TryParseFigureParameters(parameters, out var message); // Assert Assert.False(result); Assert.Equal("Triangle sides cannot be less or equal zero", message); }
static void Main(string[] args) { #region Initialize Components Validator validator = new Validator(); DisplayTriangles displayTriangles = new DisplayTriangles(); TriangleFactory triangleFactory = new TriangleFactory(); TriangleSquareCompare squareCompare = new TriangleSquareCompare(); #endregion TriangleController triangleController = new TriangleController(validator, displayTriangles, triangleFactory, squareCompare); triangleController.StartTriangleAnalizing(); Console.ReadKey(); }
public void Create_Should_Return_InvalidTriangle_Tests(Vertex v1, Vertex v2, Vertex v3, string messageIncludes) { //Arrange //Act var actual = new TriangleFactory().Create(v1, v2, v3); //Assert Assert.IsInstanceOf <InvalidTriangle>(actual); var invalidTraiangle = actual as InvalidTriangle; Assert.That(invalidTraiangle.Message, Does.Contain(messageIncludes)); }
public void TestComputeArea() { ShapeFactory sf = new TriangleFactory(); Triangle triangle = (Triangle)sf.Create2dShape(); triangle.Point1.X = 1; triangle.Point1.Y = 1; triangle.Point2.X = 2; triangle.Point2.Y = 2; triangle.Point3.X = 3; triangle.Point3.Y = 3; Assert.AreEqual(2, triangle.ComputeArea(), .0001); }
public void Should_Build_Triangle(int vertex1x, int vertex1y, int vertex2x, int vertex2y, int vertex3x, int vertex3y) { var sut = TriangleFactory.BuildTriangle( new Vertex(vertex1x, vertex1y), new Vertex(vertex2x, vertex2y), new Vertex(vertex3x, vertex3y) ); Assert.That(sut.Vertex1.X, Is.EqualTo(vertex1x)); Assert.That(sut.Vertex1.Y, Is.EqualTo(vertex1y)); Assert.That(sut.Vertex2.X, Is.EqualTo(vertex2x)); Assert.That(sut.Vertex2.Y, Is.EqualTo(vertex2y)); Assert.That(sut.Vertex3.X, Is.EqualTo(vertex3x)); Assert.That(sut.Vertex3.Y, Is.EqualTo(vertex3y)); }
public ConsoleController(string instruction, IContinueChecker checkerProcess, INumbericsValidator numbericsCheker, IFigureValidator figuresChecker, TriangleFactory figureBuilder, IComparer <IFigure> figuresComparer, FiguresSorterByDescendingFactory sorterFactory, IViewer figuresViwer) { _insrtuction = instruction; _checker = checkerProcess; _numbericsCheker = numbericsCheker; _figuresChecker = figuresChecker; _figureBuilder = figureBuilder; _figuresComparer = figuresComparer; _sorterFactory = sorterFactory; _figuresViwer = figuresViwer; _figuresContainer = new Queue <IFigure>(); }
public void TriangleFactory_ShouldCreateTriangle_WithCorrectSides() { // Arrange double sideOne = 3; double sideTwo = 5; double sideThree = 7; var parameters = new double[] { sideOne, sideTwo, sideThree }; var factory = new TriangleFactory(); // Act var triangle = factory.CreateFigure(parameters) as Triangle; // Assert Assert.Equal(sideOne, triangle.SideOne); Assert.Equal(sideTwo, triangle.SideTwo); Assert.Equal(sideThree, triangle.SideThree); }
public void CalculateName_Should_Return_Correct_Name_RegardlessOfOrder_Tests(Vertex v1, Vertex v2, Vertex v3, string expected) { //Arrange var triangle = new TriangleFactory().Create(v1, v2, v3); //Act var actual = triangle.CalculateName(); //Assert Assert.That(actual.Contains(expected), "v1, v2, v3"); //Arrange triangle = new TriangleFactory().Create(v1, v3, v2); //Act actual = triangle.CalculateName(); //Assert Assert.That(actual.Contains(expected), "v1, v3, v2"); //Arrange triangle = new TriangleFactory().Create(v2, v3, v1); //Act actual = triangle.CalculateName(); //Assert Assert.That(actual.Contains(expected), "v2, v3, v1"); //Arrange triangle = new TriangleFactory().Create(v2, v1, v3); //Act actual = triangle.CalculateName(); //Assert Assert.That(actual.Contains(expected), "v2, v1, v3"); //Arrange triangle = new TriangleFactory().Create(v3, v2, v1); //Act actual = triangle.CalculateName(); //Assert Assert.That(actual.Contains(expected), "v3, v2, v1"); //Arrange triangle = new TriangleFactory().Create(v3, v1, v2); //Act actual = triangle.CalculateName(); //Assert Assert.That(actual.Contains(expected), "v3, v1, v2"); }
public void TestValidConstruction() { ShapeFactory sf = new TriangleFactory(); Triangle triangle = (Triangle)sf.Create2dShape(); triangle.Point1.X = 1; triangle.Point1.Y = 1; triangle.Point2.X = 2; triangle.Point2.Y = 2; triangle.Point3.X = 3; triangle.Point3.Y = 3; Assert.AreEqual(1, triangle.Point1.X); Assert.AreEqual(1, triangle.Point1.Y); Assert.AreEqual(2, triangle.Point2.X); Assert.AreEqual(2, triangle.Point2.Y); Assert.AreEqual(3, triangle.Point3.X); Assert.AreEqual(3, triangle.Point3.Y); }
/// <summary> /// Builds a triangle image based on the specified height and width /// </summary> private void BuildImage() { for (var row = 0; row < _height; row++) { for (var col = 0; col < _width; col++) { var cellChar = Convert.ToChar(row + 65).ToString(); var lowerVertices = VerticesFromCell(row, col, false); var upperVertices = VerticesFromCell(row, col, true); _sectors.Add(new TriangleImageSector { Lower = new NamedTriangle(TriangleFactory.BuildTriangle(lowerVertices), $"{cellChar}{(col * 2 + 1)}"), Upper = new NamedTriangle(TriangleFactory.BuildTriangle(upperVertices), $"{cellChar}{(col + 1) * 2}"), Row = row, Column = col }); } } }
public void TestMove() { ShapeFactory sf = new TriangleFactory(); Triangle triangle = (Triangle)sf.Create2dShape(); triangle.Point1.X = 1; triangle.Point1.Y = 1; triangle.Point2.X = 2; triangle.Point2.Y = 2; triangle.Point3.X = 3; triangle.Point3.Y = 3; triangle.Move(2, 4); Assert.AreEqual(3, triangle.Point1.X); Assert.AreEqual(5, triangle.Point1.Y); Assert.AreEqual(4, triangle.Point2.X); Assert.AreEqual(6, triangle.Point2.Y); Assert.AreEqual(5, triangle.Point3.X); Assert.AreEqual(7, triangle.Point3.Y); }