Ejemplo n.º 1
0
        public void Mass_SettingValue_ShouldStayZero()
        {
            var landscape = Landscape.Create(Size.Create(10, 10));

            landscape.Mass = 42;

            landscape.Mass.Should().Be(0);
        }
Ejemplo n.º 2
0
        public void Acceleration_SettingValue_ShouldStayZero()
        {
            var landscape = Landscape.Create(Size.Create(10, 10));

            landscape.Acceleration = Vector.Create(5, 6);

            landscape.Acceleration.Should().BeEquivalentTo(Vector.Zero);
        }
Ejemplo n.º 3
0
        public void Cords_SettingValue_ShouldStayZero()
        {
            var landscape = Landscape.Create(Size.Create(10, 10));

            landscape.Cords = Vector.Create(5, 6);

            landscape.Cords.Should().BeEquivalentTo(Vector.Zero);
        }
Ejemplo n.º 4
0
        public void IntersectsWith_IntersectingWithLandscape_ShouldThrowArgumentException()
        {
            Action a = () =>
            {
                Landscape.Create(Size.Create(10, 10))
                .IntersectsWith(Landscape.Create(Size.Create(10, 10)));
            };

            a.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 5
0
        public void Create_NormalSize_ShouldReturnEmptyFieldWithRightSize(Size size)
        {
            var sut = Landscape.Create(size);

            sut.Size.Should().BeEquivalentTo(size);
            for (var i = 0; i < size.Height; i++)
            {
                for (var j = 0; j < size.Width; j++)
                {
                    sut.GetCell(i, j).Should().BeEquivalentTo(LandscapeCell.Empty);
                }
            }
        }
Ejemplo n.º 6
0
        public static void IsObjectLanded_ShouldLanded(double x, double y, bool result)
        {
            var landscape = Landscape.CreateFromText(new List <string>
            {
                "......................",
                "................******",
                "...............*******",
                "****.........*********",
                "******....************",
                "**********************"
            }, chr => chr == '*' ? LandscapeCell.Ground : LandscapeCell.Empty);
            var ship = new Ship(Vector.Create(x, y), Size.Create(2, 2), 25, 5);

            Assert.AreEqual(result, landscape.IsObjectLanded(ship));
        }
Ejemplo n.º 7
0
        private static IEnumerable <TestCaseData> CreateSizeTestCases()
        {
            yield return(new TestCaseData(Size.Create(5, 5)));

            yield return(new TestCaseData(Size.Create(0, 0)));

            yield return(new TestCaseData(Size.Create(0, 1)));

            yield return(new TestCaseData(Size.Create(10, 10)));

            yield return(new TestCaseData(Size.Create(4, 100)));

            yield return(new TestCaseData(Size.Create(5000, 5)));

            yield return(new TestCaseData(Size.Create(100, 100)));
        }
        private void DoIntersectObg(Vector firstCord, Size firstSize, Vector secondCord, Size secondSize)
        {
            var physObj = Substitute.For <IPhysObject>();

            physObj.Cords.Returns(firstCord);
            physObj.Size.Returns(firstSize);
            physObj.Direction.Returns(Vector.Zero);

            var otherPhysObject = Substitute.For <IPhysObject>();

            otherPhysObject.Cords.Returns(secondCord);
            otherPhysObject.Size.Returns(secondSize);
            otherPhysObject.Direction.Returns(Vector.Zero);

            Assert.AreEqual(true, physObj.IsRectangleObjectsIntersects(otherPhysObject));
            Assert.AreEqual(true, otherPhysObject.IsRectangleObjectsIntersects(physObj));
        }
        public void EqualityObg_ShouldReturnTrue()
        {
            var cord = GetRandomVector();
            var size = new Size(Random.Next(), Random.Next());

            var physObj = Substitute.For <IPhysObject>();

            physObj.Cords.Returns(cord);
            physObj.Size.Returns(size);
            physObj.Direction.Returns(Vector.Zero);

            var otherPhysObject = Substitute.For <IPhysObject>();

            otherPhysObject.Cords.Returns(cord);
            otherPhysObject.Size.Returns(size);
            otherPhysObject.Direction.Returns(Vector.Zero);

            Assert.AreEqual(true, physObj.IsRectangleObjectsIntersects(otherPhysObject));
            Assert.AreEqual(true, otherPhysObject.IsRectangleObjectsIntersects(physObj));
        }
Ejemplo n.º 10
0
        public void GetCellSetCell_WorkingWithValues_ShouldReturnRightValues()
        {
            var random            = new Random();
            var landscape         = Landscape.Create(Size.Create(random.Next(10, 100), random.Next(10, 100)));
            var exceptedLandscape = new LandscapeCell[landscape.Size.Height, landscape.Size.Width];

            for (var i = 0; i < landscape.Size.Height; i++)
            {
                for (var j = 0; j < landscape.Size.Width; j++)
                {
                    exceptedLandscape[i, j] = random.Next(1, 2) == 1 ? LandscapeCell.Empty : LandscapeCell.Ground;
                    landscape.SetCell(i, j, exceptedLandscape[i, j]);
                }
            }


            for (var i = 0; i < landscape.Size.Height; i++)
            {
                for (var j = 0; j < landscape.Size.Width; j++)
                {
                    landscape.GetCell(i, j).Should().BeEquivalentTo(exceptedLandscape[i, j]);
                }
            }
        }
Ejemplo n.º 11
0
        private static IEnumerable <TestCaseData> IntersectingTestCases()
        {
            IPhysObject GetObjectWithSize(Vector cords, Size size)
            {
                var obj = Substitute.For <IPhysObject>();

                obj.Cords.Returns(cords);
                obj.Size.Returns(size);

                return(obj);
            }

            var landscape = Landscape.CreateFromText(new List <string>
            {
                "........................................",
                "........................................",
                "........................................",
                "........................................",
                "........................................",
                "...........................*************",
                "........................****************",
                "..................................******",
                ".................................*******",
                ".**............................*********",
                "*****.............******....************",
                "******.........******************...****",
                "*********************************...****"
            }, chr => chr == '*' ? LandscapeCell.Ground : LandscapeCell.Empty);

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(0, 0), Size.Create(5, 5)), false)
                         .SetName("int 1"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(2, 2), Size.Create(5, 5)), false)
                         .SetName("int 2"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(5, 5), Size.Create(5, 5)), false)
                         .SetName("int 3"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(30, 1), Size.Create(15, 15)), true)
                         .SetName("int 4"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(26, 7), Size.Create(2, 2)), false)
                         .SetName("int 5"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(35, 9), Size.Create(5, 5)), true)
                         .SetName("int 6"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(26, 5), Size.Create(1, 1)), false)
                         .SetName("int 7"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(-10, 20), Size.Create(100, 100)),
                                          false).SetName("int 8"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(-10, 10), Size.Create(100, 100)),
                                          true).SetName("int 9"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(35, 4), Size.Create(1, 1)), false)
                         .SetName("int 10"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(34, 12), Size.Create(1, 1)), false)
                         .SetName("int 11"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(32, 12), Size.Create(1, 1)), true)
                         .SetName("int 12"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(26.1, 5), Size.Create(1, 1)), true)
                         .SetName("double 1"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(-1, 5), Size.Create(10, 10)), true)
                         .SetName("double 2"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(26.7, 7), Size.Create(1, 1)),
                                          false).SetName("double 3"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(26, 7.1), Size.Create(1, 1)),
                                          false).SetName("double 4"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(34.9, 12), Size.Create(1, 1)),
                                          false).SetName("double 5"));

            yield return(new TestCaseData(landscape, GetObjectWithSize(Vector.Create(32.1, 12), Size.Create(1, 1)),
                                          true).SetName("double 6"));
        }