Example #1
0
        public void PutNextRectangle_WhenPutEnoughRectangles_RectanglesShouldBeLikeCircle()
        {
            pointGenerator = new SpiralGenerator(new Point(500, 500));
            layouter       = new CircularCloudLayouter(pointGenerator);
            var    random         = new Random(0);
            var    areaRectangles = 0;
            double radius         = 0;

            for (var i = 0; i < 100; i++)
            {
                var size = new Size(random.Next(10, 50), random.Next(10, 50));
                var rect = layouter.PutNextRectangle(size);
                areaRectangles += rect.Height * rect.Width;

                var currentRadius = GetDistance(layouter.Center, rect.GetCenter());
                if (currentRadius > radius)
                {
                    radius = currentRadius;
                }
            }

            var expectedRadius = Math.Sqrt(areaRectangles / Math.PI) * 1.2;

            radius.Should().BeLessThan(expectedRadius);
        }
        public FunctionPlotSegment(IEnumerable<double> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException();
            }

            points = CreatePoints(points);

            /*int n = 0;
            double x0 = double.NegativeInfinity;
            foreach (double x in points)
            {
                if (x < x0)
                {
                    throw new ArgumentException("Points must be in ascending order.");
                }
                x0 = x;
                n++;
            }*/

            if (points.Count() < 2)
            {
                throw new ArgumentException("Need at least two points.");
            }

            generator = new PointGenerator(points);
        }
        public GameSettings(int rows, int columns, int mineCount, IPointGenerator generator)
        {
            if (rows <= 0)
            {
                throw new ArgumentOutOfRangeException("rows", rows,
                    "row count must be greater than zero");
            }
            if (columns <= 0)
            {
                throw new ArgumentOutOfRangeException("columns", columns,
                    "column count must be greater than zero");
            }
            if (mineCount <= 0)
            {
                throw new ArgumentOutOfRangeException("mineCount", mineCount,
                    "mine count must be greater than zero");
            }
            if (mineCount > rows * columns)
            {
                throw new ArgumentOutOfRangeException("mineCount", mineCount,
                    "mine count cannot be greater than the number of cells");
            }

            Rows = rows;
            Columns = columns;
            MineCount = mineCount;
            PointGenerator = generator;
            UseQuestionableState = false;
        }
Example #4
0
    public void Reset()
    {
        m_Generators = new IPointGenerator[]
        {
            new MeshPointGenerator(Meshes),
            new RandomConvexGenerator(),
            new RandomEllipsoidGenerator(),
            new ConeGenerator()
        };

        Results     = new List <TestResult>();
        ResultIndex = 0;

        IPointGenerator[] generators = GetPointGenerators();
        for (int i = 0; i < generators.Length; i++)
        {
            IPointGenerator gen     = generators[i];
            int             numSets = gen.NumSets;
            for (int j = 0; j < numSets; j++)
            {
                Results.Add(new TestResult
                {
                    GeneratorIndex = i,
                    PointSetIndex  = j,
                    Name           = gen.GetName(j)
                });
            }
        }
    }
        public static void getEmptyList(IPointGenerator pointGenerator)
        {
            pointGenerator.CreateList(0, 0, 0);
            List <Point> output   = pointGenerator.GetList();
            List <Point> expected = new List <Point>();

            CollectionAssert.AreEqual(output, expected);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MainWindowViewModel"/> class.
 /// </summary>
 /// <param name="pointGenerator">Point generator to use when creating mine cells.</param>
 public MainWindowViewModel(IPointGenerator pointGenerator)
 {
     var defaultSettings = new DefaultGameSettings(pointGenerator);
     GameViewModel = new MineSearchGameViewModel(defaultSettings);
     SettingsRequest = new InteractionRequest<SettingsViewModel>();
     SettingsCommand = new DelegateCommand(RaiseSettingsRequest);
     ExitCommand = new DelegateCommand<IBaseWindow>(CloseWindow);
 }
        public FunctionPlotSegment(double a, double b, int n, double tolerance)
        {
            if (a >= b || n < 2 || tolerance < 0.0)
            {
                throw new ArgumentOutOfRangeException();
            }

            generator = new DynamicPointGenerator(a, b, n, tolerance);
        }
Example #8
0
 public CircularCloudLayouter(IPointGenerator pointGenerator)
 {
     if (pointGenerator.Center.X < 0 || pointGenerator.Center.Y < 0)
     {
         throw new ArgumentException();
     }
     Rectangles = new List <Rectangle>();
     generator  = pointGenerator;
     Center     = pointGenerator.Center;
 }
        public static void ThreePointsNotTheSame(IPointGenerator pointGenerator)
        {
            int count  = 200;
            int width  = 200;
            int height = 200;

            pointGenerator.CreateList(width, height, count);
            List <Point> output = pointGenerator.GetList();

            Assert.IsFalse((output[0] == output[1]) && (output[0] == output[2]));
        }
        public static void AmountOfPointsEqualsCount(IPointGenerator pointGenerator)
        {
            int count  = 2342;
            int width  = 200;
            int height = 200;

            pointGenerator.CreateList(width, height, count);
            List <Point> output       = pointGenerator.GetList();
            int          amountpoints = output.Count();

            Assert.IsTrue(amountpoints == count);
        }
Example #11
0
        public void Constructor_WhenInitializedPointWithNegativeCoords_ThrowArgumentException(int x, int y)
        {
            var center = new Point(x, y);

            pointGenerator = new SpiralGenerator(center);
            Action action = () =>
            {
                // ReSharper disable once ObjectCreationAsStatement
                new CircularCloudLayouter(pointGenerator);
            };

            action.Should().Throw <ArgumentException>();
        }
        public static void getMultipleZeroPointsTest(IPointGenerator pointGenerator)
        {
            int count = 20;

            pointGenerator.CreateList(0, 0, count);
            List <Point> output   = pointGenerator.GetList();
            List <Point> expected = new List <Point>();

            for (int i = 1; i <= count; i++)
            {
                expected.Add(new Point(0, 0));
            }

            CollectionAssert.AreEqual(expected, output);
        }
        public static void PointsAreInRange(IPointGenerator pointGenerator)
        {
            int count  = 10000;
            int width  = 20;
            int height = 20;

            pointGenerator.CreateList(width, height, count);
            List <Point> output     = pointGenerator.GetList();
            int          xMin       = output.Min(p => p.X);
            int          yMin       = output.Min(p => p.Y);
            int          xMax       = output.Max(p => p.X);
            int          yMax       = output.Max(p => p.Y);
            bool         MinInRange = xMin == 0 && yMin == 0;
            bool         MaxInRange = xMax == width && yMax == height;

            Assert.IsTrue(MinInRange && MaxInRange);
        }
Example #14
0
 public CircularCloudLayouter(IPointGenerator pointGenerator)
 {
     this.pointGenerator = pointGenerator;
     cloudRectangles     = new List <Rectangle>();
 }
Example #15
0
 public void SetUp()
 {
     center         = new Point(10, 10);
     pointGenerator = new SpiralGenerator(center);
     layouter       = new CircularCloudLayouter(pointGenerator);
 }
 public DefaultGameSettings(IPointGenerator generator)
     : base(DefaultRows, DefaultColumns, DefaultMineCount, generator)
 {
     UseQuestionableState = true;
 }
Example #17
0
 public Benchmark(string KindOfAlgorithm, IPointGenerator generator)
 {
     this.KindOfAlgorithm = KindOfAlgorithm;
     this.generator       = generator;
 }
Example #18
0
 public CircularCloudLayouter(Point center, IPointGenerator sequence)
 {
     this.center   = center;
     this.sequence = sequence;
     rectangles    = new List <Rectangle>();
 }
Example #19
0
 public CircularCloudLayouter(IPointGenerator pointGenerator)
 {
     this.pointGenerator = pointGenerator ?? throw new ArgumentException("Point generator cannot be null");
     cloudRectangles     = new List <Rectangle>();
 }