public void ConvertPositionToPosXYTest()
        {
            LayoutDimensions layoutDimensions = new LayoutDimensions(12, 8);

            // Pos, ExpectedX, ExpectedY
            TestConvertPositionToPosXY(layoutDimensions, 1, 1, 1);
            TestConvertPositionToPosXY(layoutDimensions, 2, 2, 1);
            TestConvertPositionToPosXY(layoutDimensions, 12, 12, 1);
            TestConvertPositionToPosXY(layoutDimensions, 13, 1, 2);
            TestConvertPositionToPosXY(layoutDimensions, 24, 12, 2);
            TestConvertPositionToPosXY(layoutDimensions, 96, 12, 8);
        }
        public void ConvertPosXYToPositionTest()
        {
            LayoutDimensions layoutDimensions = new LayoutDimensions(12, 8);
            int result;
            result = LayoutHelpers.ConvertPosXYToPosition(new PosXY(1, 1), layoutDimensions);
            Assert.AreEqual(result, (int)1);

            result = LayoutHelpers.ConvertPosXYToPosition(new PosXY(1, 2), layoutDimensions);
            Assert.AreEqual(result, (int)13);

            result = LayoutHelpers.ConvertPosXYToPosition(new PosXY(12, 8), layoutDimensions);
            Assert.AreEqual(result, (int)96);
        }
        /// <summary>
        /// Converts PosXY to a a 1 based position value to a 
        /// e.g PosX=1, PosY=1 -> 1
        ///     PosX=2, PosY=1 -> 2
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="layoutDimensions"></param>
        /// <returns></returns>
        public static int ConvertPosXYToPosition(PosXY posXY, LayoutDimensions layoutDimensions)
        {
            Debug.Assert(posXY.X > 0);
            Debug.Assert(posXY.X <= layoutDimensions.Width);
            Debug.Assert(posXY.Y > 0);
            Debug.Assert(posXY.Y <= layoutDimensions.Height);

            int result = ((posXY.Y - 1) * layoutDimensions.Width) + posXY.X;

            Debug.Assert(result > 0);
            Debug.Assert(result <= layoutDimensions.NumPositions);

            return result;
        }
        /// <summary>
        /// Converts a 1 based position value to a PosXY (as PosXY uses top left as 1,1) 
        /// e.g. Position = 1 -> PosX=1, PosY=1
        ///      Position = 2 -> PosX=2, PosY=1
        /// </summary>
        /// <param name="pos"></param>
        /// <param name="layoutDimensions"></param>
        /// <returns></returns>
        public static PosXY ConvertPositionToPosXY(int pos, LayoutDimensions layoutDimensions)
        {
            if ((pos < 1) || (pos > layoutDimensions.NumPositions))
            {
                throw new ArgumentOutOfRangeException(string.Format("The  position: {0} is out of the range of the layout dimensions: {1}", pos, layoutDimensions.NumPositions));
            }

            Debug.Assert(pos >= 1);
            Debug.Assert(pos <= layoutDimensions.NumPositions);

            pos--;

            int y = (int)1 + (pos / layoutDimensions.Width);
            int x = (int)1 + (pos % layoutDimensions.Width);

            Debug.Assert(x >= 1);
            Debug.Assert(x <= layoutDimensions.Width);
            Debug.Assert(y >= 1);
            Debug.Assert(y <= layoutDimensions.Height);

            return new PosXY(x, y);
        }
 public void LayoutDimensionsConstructorTest()
 {
     LayoutDimensions target = new LayoutDimensions(0, 12);
 }
        private static int GetPreviousPosition(int currentPos, FillSettings fillSettings, LayoutDimensions layoutDimensions, out bool endOfLine)
        {
            Debug.Assert(fillSettings.IsGrid == false);
            Debug.Assert(currentPos >= 1);
            Debug.Assert(currentPos <= layoutDimensions.NumPositions);

            PosXY currentPosXY = ConvertPositionToPosXY(currentPos, layoutDimensions);
            PosXY nextPosXY = new PosXY();

            endOfLine = false;

            if (fillSettings.GroupDirection == Direction.Row)
            {
                if (currentPosXY.X > 1)
                {
                    nextPosXY.X = currentPosXY.X - 1;
                    nextPosXY.Y = currentPosXY.Y;
                }
                else
                {
                    nextPosXY.X = layoutDimensions.Width;
                    nextPosXY.Y = currentPosXY.Y - 1;
                    endOfLine = true;
                }
            }
            else
            {
                Debug.Assert(fillSettings.GroupDirection == Direction.Col);
                if (currentPosXY.Y > 1)
                {
                    nextPosXY.X = currentPosXY.X;
                    nextPosXY.Y = currentPosXY.Y - 1;
                }
                else
                {
                    nextPosXY.X = currentPosXY.X - 1;
                    nextPosXY.Y = layoutDimensions.Height;
                    endOfLine = true;
                }
            }

            int nextPos = ConvertPosXYToPosition(nextPosXY, layoutDimensions);
            Debug.Assert(nextPos != currentPos);
            Debug.Assert(nextPos >= 1);
            Debug.Assert(nextPos <= layoutDimensions.NumPositions);

            return nextPos;
        }
 private static void FillGridRow(FillSettings fillSettings, LayoutDimensions layoutDimensions, List<int> list, PosXY topLeft, int gridWidth, int gridHeight)
 {
     for (int y = 0; y < gridHeight; y++)
     {
         for (int x = 0; x < gridWidth; x++)
         {
             AddPositionToList(layoutDimensions, list, topLeft, x, y);
         }
         if (fillSettings.IsSnake && y < (gridHeight - 1))
         {
             // In snake mode do the next line in reverse
             y++;
             for (int x = gridWidth - 1; x >= 0 && x != int.MaxValue; x--)
             {
                 AddPositionToList(layoutDimensions, list, topLeft, x, y);
             }
         }
     }
 }
 private static void AddPositionToList(LayoutDimensions layoutDimensions, List<int> list, PosXY topLeft, int x, int y)
 {
     list.Add(ConvertPosXYToPosition(new PosXY(topLeft.X + x, topLeft.Y + y), layoutDimensions));
 }
        /// <summary>
        /// Returns a list of all position selected between startPos and endPos, in the order with which they should be filled with groups.
        /// </summary>
        /// <param name="startPos">The 1 based starting position</param>
        /// <param name="endPos">The 1 based ending position (this can be anywhere within the range and can be before startPos)</param>
        /// <param name="fillSettings"></param>
        /// <param name="layoutDimensions"></param>
        /// <returns></returns>
        public static int[] GetPositions(int startPos, int endPos, FillSettings fillSettings, LayoutDimensions layoutDimensions)
        {
            if ((startPos < 1) || (startPos > layoutDimensions.NumPositions))
            {
                throw new ArgumentOutOfRangeException(string.Format("The start position: {0} is out of the range of the layout dimensions: {1}", startPos, layoutDimensions.NumPositions), "startPos");
            }
            if ((endPos < 1) || (endPos > layoutDimensions.NumPositions))
            {
                throw new ArgumentOutOfRangeException(string.Format("The end position: {0} is out of the range of the layout dimensions: {1}", startPos, layoutDimensions.NumPositions), "endPos");
            }
            if (layoutDimensions.NumPositions < 1)
            {
                throw new ArgumentException("The LayoutDimensions are invalid.", "layoutDimensions");
            }
            Debug.Assert(startPos >= 1);
            Debug.Assert(startPos <= layoutDimensions.NumPositions);
            Debug.Assert(endPos >= 1);
            Debug.Assert(endPos <= layoutDimensions.NumPositions);

            List<int> list = new List<int>();
            // Deal with simple case of 1 position
            if (startPos == endPos)
            {
                list.Add(fillSettings.StartGroup);
                return list.ToArray();
            }

            // TODO: do we want to do this, will anyone ever want to fill backwards?
            // Swap start and end around so start is < end
            bool isForwards = (startPos < endPos);

            Debug.Assert(startPos != endPos);

            PosXY topLeft, bottomRight;
            if (isForwards)
            {
                topLeft = ConvertPositionToPosXY(startPos, layoutDimensions);
                bottomRight = ConvertPositionToPosXY(endPos, layoutDimensions);
            }
            else
            {
                topLeft = ConvertPositionToPosXY(endPos, layoutDimensions);
                bottomRight = ConvertPositionToPosXY(startPos, layoutDimensions);
            }

            if (fillSettings.IsGrid)
            {
                int gridWidth = 1 + (bottomRight.X - topLeft.X);
                int gridHeight = 1 + (bottomRight.Y - topLeft.Y);

                Debug.Assert(gridWidth > 0);
                Debug.Assert(gridHeight > 0);

                if (fillSettings.GroupDirection == Direction.Col)
                {
                    FillGridCol(fillSettings, layoutDimensions, list, topLeft, gridWidth, gridHeight);
                }
                else if (fillSettings.GroupDirection == Direction.Row)
                {
                    FillGridRow(fillSettings, layoutDimensions, list, topLeft, gridWidth, gridHeight);
                }

                if (!isForwards)
                {
                    list.Reverse();
                }
            }
            else
            {
                // Not grid mode
                int pos = startPos;
                list.Add(pos);
                bool endOfLine = true;
                if (!fillSettings.IsSnake)
                {
                    while (pos != endPos)
                    {
                        if (isForwards)
                        {
                            pos = GetNextPosition(pos, fillSettings, layoutDimensions, out endOfLine);
                        }
                        else
                        {
                            pos = GetPreviousPosition(pos, fillSettings, layoutDimensions, out endOfLine);
                        }
                        list.Add(pos);
                    }
                }
                else
                {
                    bool snakeForwards = isForwards;
                    while (pos != endPos)
                    {
                        if (snakeForwards)
                        {
                            pos = GetNextPosition(pos, fillSettings, layoutDimensions, out endOfLine);
                            if (endOfLine)
                            {
                                if (isForwards)  // Snake (instead of starting line)
                                {
                                    if (fillSettings.GroupDirection == Direction.Row)
                                    {
                                        pos += layoutDimensions.Width - 1;
                                    }
                                    else
                                    {
                                        pos = list[list.Count - 1] + 1;
                                    }
                                }
                                else
                                {
                                    if (fillSettings.GroupDirection == Direction.Row)
                                    {
                                        pos -= layoutDimensions.Width + 1;
                                    }
                                    else
                                    {
                                        pos = list[list.Count - 1] - 1;
                                    }
                                }
                                snakeForwards = false;
                            }
                        }
                        else
                        {
                            pos = GetPreviousPosition(pos, fillSettings, layoutDimensions, out endOfLine);
                            if (endOfLine)
                            {
                                if (isForwards)  // Snake (instead of starting line)
                                {
                                    if (fillSettings.GroupDirection == Direction.Row)
                                    {
                                        pos += layoutDimensions.Width + 1;
                                    }
                                    else
                                    {
                                        pos = list[list.Count - 1] + 1;
                                    }
                                }
                                else
                                {
                                    if (fillSettings.GroupDirection == Direction.Row)
                                    {
                                        pos -= layoutDimensions.Width - 1;
                                    }
                                    else
                                    {
                                        pos = list[list.Count - 1] - 1;
                                    }
                                }

                                snakeForwards = true;
                            }
                        }
                        list.Add(pos);
                    }
                }
            }
            Debug.Assert(list.Count > 0);
            return list.ToArray();
        }
        /// Read in EVERY position in the layout from a CSV list of TypeId, GroupNum
        public void InitFromCSVStringAllPositions(string csv, int width, int height)
        {
            LayoutDimensions = new LayoutDimensions(width, height);
            singleLayoutLight = new SingleLayoutLight(csv);

            if (singleLayoutLight.NumPositions != width * height)
            {
                throw new InvalidProgramException();
            }

            // Infer Sample types if they have not already been setup
            if (sampleTypes.Count == 0)
            {
                var usedTypes = (from LayoutPos pos in singleLayoutLight.LayoutPositions
                                 where pos.TypeId != 1      // Ignore unused type in this list
                                 select pos.TypeId).Distinct();

                // Always add unused
                sampleTypes.Add(new SampleType() { Name = "Unused", Colour = "White", Id = 1 });

                foreach (var type in usedTypes)
                {

                    SampleType sampleType;
                    switch (type)
                    {
                        case 2:
                            sampleType = new SampleType() { Name = "Standard", Colour = "Red" };
                            break;
                        case 3:
                            sampleType = new SampleType() { Name = "Blank", Colour = "Yellow" };
                            break;
                        case 4:
                            sampleType = new SampleType() { Name = "Control", Colour = "Aqua" };
                            break;
                        case 5:
                            sampleType = new SampleType() { Name = "Unknown", Colour = "Lime" };
                            break;
                        case 7:
                            sampleType = new SampleType() { Name = "Pos Control", Colour = "#7dffff" };
                            break;
                        case 8:
                            sampleType = new SampleType() { Name = "Neg Control", Colour = "#fefccf" };
                            break;
                        case 24:
                            sampleType = new SampleType() { Name = "B0", Colour = "#FFD080" };
                            break;
                        case 25:
                            sampleType = new SampleType() { Name = "NSB", Colour = "#FF80FF" };
                            break;
                        case 26:
                            sampleType = new SampleType() { Name = "TA", Colour = "#9E8010" };
                            break;
                        case 109:
                            sampleType = new SampleType() { Name = "Unknown 1:1", Colour = "#408040" };
                            break;
                        case 110:
                            sampleType = new SampleType() { Name = "Unknown 1:10", Colour = "#00c000" };
                            break;
                        case 111:
                            sampleType = new SampleType() { Name = "Unknown 1:200", Colour = "#c0ffc0" };
                            break;

                        default:
                            sampleType = new SampleType() { Name = typeNotSupported, Colour = "Black" };
                            break;
                    }
                    sampleType.Id = type;
                    sampleTypes.Add(sampleType);
                }
            }
        }
        public void FillPositionsTest()
        {
            LayoutDimensions layoutDimensions = new LayoutDimensions(12, 8);

            FillSettings fillSettings = new FillSettings()
            {
                IsGrid = true,
                IsSnake = false,
                GroupDirection = Direction.Row,
                StartGroup = 1,
                Replicates = 1
            };

            int[] positions;

            // IsGrid, By row
            positions = TestGetPositions(1, 2, layoutDimensions, fillSettings, new int[] { 1, 2 });

            // Expected group nums, expected next group, expected all replicates used
            TestFillPositions(positions, layoutDimensions, fillSettings, new int[] { 1, 2 }, 3, true);
            fillSettings.Replicates = 2;
            TestFillPositions(positions, layoutDimensions, fillSettings, new int[] { 1, 1 }, 2, true);
            fillSettings.Replicates = 3;
            TestFillPositions(positions, layoutDimensions, fillSettings, new int[] { 1, 1 }, 1, false);
            fillSettings.Replicates = 100;
            TestFillPositions(positions, layoutDimensions, fillSettings, new int[] { 1, 1 }, 1, false);

            fillSettings.Replicates = 1;
            TestGetPositions(2, 1, layoutDimensions, fillSettings, new int[] { 2, 1 });
            TestFillPositions(positions, layoutDimensions, fillSettings, new int[] { 1, 2 }, 3, true);
        }
        private static int[] TestGetPositions(int startPos, int endPos, LayoutDimensions layoutDimensions, FillSettings fillSettings, int[] expected)
        {
            int[] result = LayoutHelpers.GetPositions(startPos, endPos, fillSettings, layoutDimensions);
            Assert.AreEqual(result.Length, expected.Length, "The number of expected positions is wrong.");

            for (int i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(result[i], expected[i], string.Format("Unexpected result at position {0}, expected: {1} result {2}.  Full result: {3}", i, expected[i], result[i], UintArrayToString(result)));
            }
            return result;
        }
 public void LayoutDimensionsConstructorTest2()
 {
     LayoutDimensions target = new LayoutDimensions(12, -8);
 }
        private static void TestFillPositions(int[] positions, LayoutDimensions layoutDimensions, FillSettings fillSettings,
                                            int[] expectedGroupNumbers,
                                            int expectedNextGroup, bool expectedIsAllRepsUsed)
        {
            int[] groupNumbers;
            int nextGroup;
            bool isAllRepsUsed;
            groupNumbers = LayoutHelpers.FillPositions(positions, fillSettings, out nextGroup, out isAllRepsUsed);

            Assert.AreEqual(groupNumbers.Length, positions.Length, "groupNumbers length differs from positions length");

            for (int i = 0; i < groupNumbers.Length; i++)
            {
                Assert.AreEqual(groupNumbers[i], expectedGroupNumbers[i],
                    string.Format("Unexpected result at position {0}, expected: {1} result {2}.  Full result: {3}",
                            i, expectedGroupNumbers[i], groupNumbers[i], UintArrayToString(groupNumbers)));
            }

            Assert.AreEqual(nextGroup, expectedNextGroup, "The next group is not as expected");
            Assert.AreEqual(isAllRepsUsed, expectedIsAllRepsUsed, "isAllRepsUsed is not as expected");
        }
 private static void TestConvertPositionToPosXY(LayoutDimensions layoutDimensions, int pos, int posXExpected, int posYExpected)
 {
     PosXY result;
     result = LayoutHelpers.ConvertPositionToPosXY(pos, layoutDimensions);
     Assert.AreEqual(result.X, (int)posXExpected, string.Format("posX value is not as expected, expecting {0}, result is {1}", posXExpected, result.X));
     Assert.AreEqual(result.Y, (int)posYExpected, string.Format("posY value is not as expected, expecting {0}, result is {1}", posXExpected, result.Y));
 }
        public void GetPositionsTest2()
        {
            LayoutDimensions layoutDimensions = new LayoutDimensions(12, 8);

            FillSettings fillSettings = new FillSettings()
            {
                IsGrid = true,
                IsSnake = false,
                GroupDirection = Direction.Row,
                StartGroup = 1,
                Replicates = 1
            };

            // IsGrid, By row
            TestGetPositions(1, 2, layoutDimensions, fillSettings, new int[] { 1, 2 });
            TestGetPositions(2, 1, layoutDimensions, fillSettings, new int[] { 2, 1 });
            TestGetPositions(1, 13, layoutDimensions, fillSettings, new int[] { 1, 13 });
            TestGetPositions(1, 14, layoutDimensions, fillSettings, new int[] { 1, 2, 13, 14 });
            TestGetPositions(14, 1, layoutDimensions, fillSettings, new int[] { 14, 13, 2, 1 });
            TestGetPositions(1, 96, layoutDimensions, fillSettings, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 });
            TestGetPositions(96, 1, layoutDimensions, fillSettings, new int[] { 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });

            // IsGrid, By row with snake mode
            fillSettings.IsSnake = true;
            TestGetPositions(1, 14, layoutDimensions, fillSettings, new int[] { 1, 2, 14, 13 });
            TestGetPositions(14, 1, layoutDimensions, fillSettings, new int[] { 13, 14, 2, 1 });       // TODO: Not sure about this one - test with UI
            TestGetPositions(1, 27, layoutDimensions, fillSettings, new int[] { 1, 2, 3, 15, 14, 13, 25, 26, 27 });

            // IsGrid, By col without snake mode
            fillSettings.IsSnake = false;
            fillSettings.GroupDirection = Direction.Col;
            TestGetPositions(1, 14, layoutDimensions, fillSettings, new int[] { 1, 13, 2, 14 });
            TestGetPositions(14, 1, layoutDimensions, fillSettings, new int[] { 14, 2, 13, 1 });   // TODO: Not sure about this one - test with UI

            // IsGrid, By col with snake mode
            fillSettings.IsSnake = true;
            TestGetPositions(1, 14, layoutDimensions, fillSettings, new int[] { 1, 13, 14, 2 });
            TestGetPositions(1, 27, layoutDimensions, fillSettings, new int[] { 1, 13, 25, 26, 14, 2, 3, 15, 27 });
            TestGetPositions(27, 1, layoutDimensions, fillSettings, new int[] { 27, 15, 3, 2, 14, 26, 25, 13, 1 });  // TODO: Not sure about this one - test with UI

            // Not grid, By row
            fillSettings.IsGrid = false;
            fillSettings.GroupDirection = Direction.Row;
            fillSettings.IsSnake = false;
            TestGetPositions(1, 2, layoutDimensions, fillSettings, new int[] { 1, 2 });
            TestGetPositions(2, 1, layoutDimensions, fillSettings, new int[] { 2, 1 });
            TestGetPositions(1, 13, layoutDimensions, fillSettings, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 });
            TestGetPositions(13, 1, layoutDimensions, fillSettings, new int[] { 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });
            TestGetPositions(1, 96, layoutDimensions, fillSettings, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 });
            TestGetPositions(96, 1, layoutDimensions, fillSettings, new int[] { 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 });

            // Not grid, By col
            fillSettings.GroupDirection = Direction.Col;
            TestGetPositions(1, 2, layoutDimensions, fillSettings, new int[] { 1, 13, 25, 37, 49, 61, 73, 85, 2 });
            TestGetPositions(2, 1, layoutDimensions, fillSettings, new int[] { 2, 85, 73, 61, 49, 37, 25, 13, 1 });
            TestGetPositions(1, 13, layoutDimensions, fillSettings, new int[] { 1, 13 });
            TestGetPositions(13, 1, layoutDimensions, fillSettings, new int[] { 13, 1 });
            TestGetPositions(1, 86, layoutDimensions, fillSettings, new int[] { 1, 13, 25, 37, 49, 61, 73, 85, 2, 14, 26, 38, 50, 62, 74, 86 });

            // Not grid, By row, snake
            fillSettings.IsSnake = true;
            fillSettings.GroupDirection = Direction.Row;
            TestGetPositions(1, 2, layoutDimensions, fillSettings, new int[] { 1, 2 });

            // Not grid, By row, snake
            layoutDimensions.Width = 3;
            layoutDimensions.Height = 2;
            TestGetPositions(1, 6, layoutDimensions, fillSettings, new int[] { 1, 2, 3, 6 });
            TestGetPositions(6, 1, layoutDimensions, fillSettings, new int[] { 6, 5, 4, 1 });
            TestGetPositions(6, 3, layoutDimensions, fillSettings, new int[] { 6, 5, 4, 1, 2, 3 });  // This is row - by if it were by col it would be 2 pos

            // Not grid, By row, snake
            layoutDimensions.Width = 4;
            layoutDimensions.Height = 3;
            TestGetPositions(1, 12, layoutDimensions, fillSettings, new int[] { 1, 2, 3, 4, 8, 7, 6, 5, 9, 10, 11, 12 });
            TestGetPositions(12, 1, layoutDimensions, fillSettings, new int[] { 12, 11, 10, 9, 5, 6, 7, 8, 4, 3, 2, 1 });

            // Not grid, By col, snake
            layoutDimensions.Width = 3;
            layoutDimensions.Height = 2;
            fillSettings.GroupDirection = Direction.Col;
            TestGetPositions(1, 6, layoutDimensions, fillSettings, new int[] { 1, 4, 5, 2, 3, 6 });
            TestGetPositions(6, 1, layoutDimensions, fillSettings, new int[] { 6, 3, 2, 5, 4, 1 });

            // Not grid, By col, snake
            layoutDimensions.Width = 4;
            layoutDimensions.Height = 3;
            TestGetPositions(1, 12, layoutDimensions, fillSettings, new int[] { 1, 5, 9, 10, 6, 2, 3, 7, 11, 12 });
            TestGetPositions(12, 1, layoutDimensions, fillSettings, new int[] { 12, 8, 4, 3, 7, 11, 10, 6, 2, 1 });
            TestGetPositions(1, 10, layoutDimensions, fillSettings, new int[] { 1, 5, 9, 10 });
            TestGetPositions(12, 8, layoutDimensions, fillSettings, new int[] { 12, 8 });
        }
        public void GetPositionsTest1()
        {
            int startPos = 97;
            int endPos = 98;

            LayoutDimensions layoutDimensions = new LayoutDimensions(12, 8);
            FillSettings fillSettings = new FillSettings() { GroupDirection = Direction.Col };
            int[] result = LayoutHelpers.GetPositions(startPos, endPos, fillSettings, layoutDimensions);
        }
        public void GetPositionsTest()
        {
            int startPos = 1;
            int endPos = 1;

            LayoutDimensions layoutDimensions = new LayoutDimensions(12, 8);

            FillSettings fillSettings = new FillSettings() { GroupDirection = Direction.Col };
            int[] result;
            result = LayoutHelpers.GetPositions(startPos, endPos, fillSettings, layoutDimensions);
            Assert.AreEqual(result.Length, 1, "The number of expected positions is wrong.");
            Assert.AreEqual(result[0], fillSettings.StartGroup, "The first group is wrong.");
        }