public void CellLineIsCompleteIsTrueWhenAllBlank()
        {
            Nonogram n = new Nonogram(5, 5);
            CellLine l = n.Row(0);

            foreach (var cell in l)
            {
                cell.State = Cell.CellState.Blank;
            }

            Assert.IsTrue(n.Row(0).isComplete);
        }
        public void CellLineIsCompleteIsTrueWhenAllNotUnknown()
        {
            Nonogram n           = new Nonogram(5, 5);
            CellLine l           = n.Row(0);
            bool     setToFilled = false;

            foreach (var cell in l)
            {
                cell.State  = setToFilled ? Cell.CellState.Filled : Cell.CellState.Blank;
                setToFilled = !setToFilled;
            }

            Assert.IsTrue(n.Row(0).isComplete);
        }
        public void CellLineIsCompleteIsFalseWithOneUnknown()
        {
            Nonogram n            = new Nonogram(5, 5);
            CellLine l            = n.Row(0);
            bool     setToUnknown = false;

            foreach (var cell in l)
            {
                cell.State   = setToUnknown ? Cell.CellState.Unknown : Cell.CellState.Filled;
                setToUnknown = true;
            }

            Assert.IsFalse(n.Row(0).isComplete);
        }
        public void DistinctGroupsReturnsZeroWithAllUnknowns()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            Assert.AreEqual(0, l.DistinctGroups());
        }
        public void OverlapTechniqueFindsSolutionWhenGivenPartialInformation_5_3_last()
        {
            // Testing: Finds information when a partial solution is in place
            // Expected Results:
            // Width: 5
            // Hint: 3
            // Pre-given information: ????X
            // Solution: __XXX

            const int width = 5;
            var       n     = new Nonogram(width, 1);
            var       line  = n.Row(0);

            line.Hints.AddRange(new int[] { 3 });

            line[4].State = Cell.CellState.Filled;

            Cell.CellState[] expected = new Cell.CellState[width] {
                Cell.CellState.Blank,
                Cell.CellState.Blank,
                Cell.CellState.Filled,
                Cell.CellState.Filled,
                Cell.CellState.Filled
            };

            var t = new OverlapTechnique();

            t.Apply(line);

            for (int i = 0; i < width; ++i)
            {
                Assert.AreEqual(expected[i], line[i].State);
            }
        }
        public void OverlapTechniqueGivesSolutionWhenHintGivenCompleteInformation_5_2_2()
        {
            // Testing: Finds solution for odd-numbered width
            // Expected Results:
            // Width: 5
            // Hint: 2, 2
            //
            // Solution:
            // XX XX

            const int width = 5;
            var       n     = new Nonogram(width, 1);
            var       line  = n.Row(0);

            line.Hints.AddRange(new int[] { 2, 2 });

            Cell.CellState[] expected = new Cell.CellState[width] {
                Cell.CellState.Filled,
                Cell.CellState.Filled,
                Cell.CellState.Blank,
                Cell.CellState.Filled,
                Cell.CellState.Filled
            };

            var t = new OverlapTechnique();

            t.Apply(line);

            for (int i = 0; i < width; ++i)
            {
                Assert.AreEqual(expected[i], line[i].State);
            }
        }
        public void OverlapTechniqueDoesNothingWhenGivenConflictingInformation()
        {
            // Testing: Finds information when a partial solution is in place
            // Expected Results:
            // Width: 5
            // Hint: 3
            // Pre-given information: X???X

            const int width = 5;
            var       n     = new Nonogram(width, 1);
            var       line  = n.Row(0);

            line.Hints.AddRange(new int[] { 3 });

            line[0].State = Cell.CellState.Filled;
            line[4].State = Cell.CellState.Filled;

            Cell.CellState[] expected = new Cell.CellState[width] {
                Cell.CellState.Filled,
                Cell.CellState.Unknown,
                Cell.CellState.Unknown,
                Cell.CellState.Unknown,
                Cell.CellState.Filled
            };

            var t = new OverlapTechnique();

            t.Apply(line);

            for (int i = 0; i < width; ++i)
            {
                Assert.AreEqual(expected[i], line[i].State);
            }
        }
        public void CellLineMaxFunctionsWithSomeKnownCells_5_3_last()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Hints.AddRange(new int[] { 3 });
            l[4].State = Cell.CellState.Filled;

            var expectedStates = new Cell.CellState[5] {
                Cell.CellState.Blank,
                Cell.CellState.Blank,
                Cell.CellState.Filled,
                Cell.CellState.Filled,
                Cell.CellState.Filled
            };

            var expectedFlags = new int[5] {
                0,
                1,
                0,
                0,
                0
            };

            var max = l.Max();

            Assert.IsNotNull(max);

            for (int i = 0; i < 5; ++i)
            {
                Assert.AreEqual(expectedStates[i], max[i].State);
                Assert.AreEqual(expectedFlags[i], max[i].Flag);
            }
        }
        public void OverlapTechniqueGivesSolutionWhenHintGivenCompleteInformation_1_1()
        {
            // Testing: Finds solution for simple problem
            // Expected Results:
            // Width: 1
            // Hint: 1
            //
            // Solution:
            // X

            const int width = 1;
            var       n     = new Nonogram(width, 1);
            var       line  = n.Row(0);

            line.Hints.AddRange(new int[] { 1 });

            Cell.CellState[] expected = new Cell.CellState[width] {
                Cell.CellState.Filled
            };

            var t = new OverlapTechnique();

            t.Apply(line);

            for (int i = 0; i < width; ++i)
            {
                Assert.AreEqual(expected[i], line[i].State);
            }
        }
        public void FillingPartOfALineThatHasStateOutsideThatPartWithStateAndFlagFillsTheSectionWithThatStateAndFlagAndReturnsFalse()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l[0].State = Cell.CellState.Blank;

            Assert.IsTrue(l.Fill(1, 2, Cell.CellState.Filled, 42));

            var expectedStates = new Cell.CellState[5] {
                Cell.CellState.Blank,
                Cell.CellState.Filled,
                Cell.CellState.Filled,
                Cell.CellState.Unknown,
                Cell.CellState.Unknown
            };

            var expectedFlags = new int[5] {
                0,
                42,
                42,
                0,
                0
            };

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(expectedStates[i], l[i].State);
                Assert.AreEqual(expectedFlags[i], l[i].Flag);
            }
        }
        public void IsValidReturnsTrueWhenAllUnknown()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            Assert.AreEqual(true, l.IsValid());
        }
        public void CellLineMinFunctionsWithAllUnknownCells_5_2_1()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Hints.AddRange(new int[] { 2, 1 });

            var expectedStates = new Cell.CellState[5] {
                Cell.CellState.Filled,
                Cell.CellState.Filled,
                Cell.CellState.Blank,
                Cell.CellState.Filled,
                Cell.CellState.Blank
            };

            var expectedFlags = new int[5] {
                0,
                0,
                0,
                1,
                1
            };

            var min = l.Min();

            Assert.IsNotNull(min);

            for (int i = 0; i < 5; ++i)
            {
                Assert.AreEqual(expectedStates[i], min[i].State);
                Assert.AreEqual(expectedFlags[i], min[i].Flag);
            }
        }
        public void OverlapTechniqueGivesNoInformationWhenHintGivenIncompleteInformation_5_1_1()
        {
            // Testing: Returns no information when given hints that don't overlap
            // Expected Results:
            // Width: 5
            // Hint: 1, 1
            //
            // Min/Max:
            // X X??
            // ??X X
            //
            // Overlap:
            // ?????

            const int width = 5;
            var       n     = new Nonogram(width, 1);
            var       line  = n.Row(0);

            line.Hints.AddRange(new int[] { 1, 1 });

            var t = new OverlapTechnique();

            t.Apply(line);

            // All are unknown
            Assert.IsTrue(line.All(x => x.State == Cell.CellState.Unknown));
        }
        public void CellLineMaxFunctionsWithSomeBlockedCells()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Hints.AddRange(new int[] { 2, 1 });
            l[2].State = Cell.CellState.Blank;

            var expectedStates = new Cell.CellState[5] {
                Cell.CellState.Filled,
                Cell.CellState.Filled,
                Cell.CellState.Blank, // forced blank
                Cell.CellState.Blank,
                Cell.CellState.Filled
            };

            var expectedFlags = new int[5] {
                0,
                0,
                0,
                1,
                1
            };

            var max = l.Max();

            Assert.IsNotNull(max);

            for (int i = 0; i < 5; ++i)
            {
                Assert.AreEqual(expectedStates[i], max[i].State);
                Assert.AreEqual(expectedFlags[i], max[i].Flag);
            }
        }
        public void DistinctGroupsReturnsZeroWithAllBlank()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(Cell.CellState.Blank);

            Assert.AreEqual(0, l.DistinctGroups());
        }
        public void IsValidReturnsFalseWhenHintIsNotPossible_Hint32()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Hints.AddRange(new int[] { 3, 2 });

            Assert.AreEqual(false, l.IsValid());
        }
        public void IsValidReturnsTrueWhenHintMatchesContents_Hint0_Contents0()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(Cell.CellState.Blank);

            Assert.AreEqual(true, l.IsValid());
        }
        public void DistinctGroupsReturnsOneWithAllFilled()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(Cell.CellState.Filled);

            Assert.AreEqual(1, l.DistinctGroups());
        }
        public void DistinctGroupsReturnsActualNumberOfGroupsWithTwoGroupsOfTwo()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(Cell.CellState.Filled);
            l[2].State = Cell.CellState.Blank;

            Assert.AreEqual(2, l.DistinctGroups());
        }
        public void IsValidReturnsFalseWhenHintsExistButAllBlank()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(Cell.CellState.Blank);
            l.Hints.AddRange(new int[] { 1 });

            Assert.AreEqual(false, l.IsValid());
        }
        public void ReversingACellLineReversesItsContents()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l[0].State = Cell.CellState.Blank;
            l.Reverse();

            Assert.AreEqual(Cell.CellState.Blank, l[4].State);
        }
        public void DistinctGroupsReturnsActualNumberOfGroupsWithThreeGroupsOfOne()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l[0].State = l[2].State = l[4].State = Cell.CellState.Filled;
            l[1].State = l[3].State = Cell.CellState.Blank;

            Assert.AreEqual(3, l.DistinctGroups());
        }
        public void IsValidReturnsFalseWhenNoPossibleSolutionsExist()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(0, 3, Cell.CellState.Filled);
            l[4].State = Cell.CellState.Filled;
            l.Hints.AddRange(new int[] { 3 });

            Assert.AreEqual(false, l.IsValid());
        }
        public void IsValidReturnsTrueWhenNotEnoughGroups_Hint111_Contents11()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l[0].State = l[2].State = Cell.CellState.Filled;
            l[1].State = l[3].State = Cell.CellState.Blank;
            l.Hints.AddRange(new int[] { 1, 1, 1 });

            Assert.AreEqual(true, l.IsValid());
        }
        public void IsValidReturnsFalseWhenGroupIsTooLarge_Hint3_Contents4_right()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l[0].State = Cell.CellState.Blank;
            l.Fill(1, 4, Cell.CellState.Filled);
            l.Hints.AddRange(new int[] { 3 });

            Assert.AreEqual(false, l.IsValid());
        }
        public void IsValidReturnsTrueWhenPossibleSolutionsExist()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Fill(0, 3, Cell.CellState.Blank);
            l[4].State = Cell.CellState.Blank;
            l.Hints.AddRange(new int[] { 1 });

            Assert.AreEqual(true, l.IsValid());
        }
        public void CellLineMaxReturnsNullWhenNotPossibleToFill()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            l.Hints.AddRange(new int[] { 2, 2 });
            l[1].State = Cell.CellState.Blank;

            var max = l.Max();

            Assert.IsNull(max);
        }
        public void CellLineDeepClonesReferToDifferentCells()
        {
            const int width  = 7;
            const int height = 3;

            Nonogram n = new Nonogram(width, height);

            var first  = n.Row(0);
            var second = first.DeepClone();

            Assert.AreNotSame(first[0], second[0]);
        }
        public void CellLineClonesReferToTheSameCells()
        {
            const int width  = 7;
            const int height = 3;

            Nonogram n = new Nonogram(width, height);

            var first  = n.Row(0);
            var second = first.Clone();

            Assert.AreSame(first[0], second[0]);
        }
        public void FillingALineWithStateFillsTheEntireLineWithThatStateAndReturnsTrue()
        {
            Nonogram n = new Nonogram(5, 1);
            CellLine l = n.Row(0);

            Assert.IsTrue(l.Fill(Cell.CellState.Filled));

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(Cell.CellState.Filled, l[i].State);
            }
        }