Пример #1
0
        public void PadColumn_PaddingHeightGreaterThanInputReturnsPaddedInput()
        {
            List <int?> input = new List <int?> {
                1, 2, 3, 4, 5
            };

            List <int?> expected = new List <int?> {
                1, 2, 3, 4, 5, null, null
            };

            List <int?> output = PinningModelBase.PadColumn(input, 7);

            if (output.Count != expected.Count)
            {
                Assert.Fail($"Output had length {output.Count} instead of {expected.Count}.");
            }

            for (int index = 0; index < output.Count; index++)
            {
                int?currentOutput   = output[index];
                int?currentExpected = expected[index];

                if (currentOutput != currentExpected)
                {
                    Assert.Fail($"Output value {currentOutput} at index {index} did not match expected value of {currentExpected}.");
                }
            }
        }
Пример #2
0
        public void GetMaxKeyLength_ValidListReturnsLongestKeyLength()
        {
            List <KeyModel> input = new List <KeyModel>
            {
                new KeyModel()
                {
                    Cuts = "123"
                },
                new KeyModel()
                {
                    Cuts = "1234"
                },
                new KeyModel()
                {
                    Cuts = "123456"
                },
                new KeyModel()
                {
                    Cuts = "12345"
                }
            };

            int output = PinningModelBase.GetMaxKeyLength(input);

            Assert.AreEqual(output, 6);
        }
Пример #3
0
        public void GetPaddedKeys_ReturnedKeysAllHaveSameLength()
        {
            List <KeyModel> input = new List <KeyModel>
            {
                new KeyModel()
                {
                    Cuts = "123456"
                },
                new KeyModel()
                {
                    Cuts = "1234"
                },
                new KeyModel()
                {
                    Cuts = "12345678"
                }
            };

            List <List <int?> > output = PinningModelBase.GetPaddedKeys(input, 6);

            for (int index = 0; index < output.Count; index++)
            {
                int currentLength = output[index].Count;

                if (currentLength != 6)
                {
                    Assert.Fail($"Result at index {index} had length {currentLength} instead of 6.");
                }
            }
        }
Пример #4
0
        public void PadKey_PaddingLengthEqualsKeyLengthReturnsUnmodifiedCuts()
        {
            KeyModel input = new KeyModel()
            {
                Cuts = "123456"
            };

            List <int?> expected = new List <int?> {
                1, 2, 3, 4, 5, 6
            };

            List <int?> output = PinningModelBase.PadKey(input, 6);

            if (output.Count != expected.Count)
            {
                Assert.Fail("Output has wrong length.");
            }

            for (int index = 0; index < output.Count; index++)
            {
                if (output[index] != expected[index])
                {
                    Assert.Fail($"Output has wrong value at index {index}");
                }
            }
        }
Пример #5
0
        public void PadColumns_ValidInputReturnsColumnsOfSameHeight()
        {
            List <List <int?> > input = new List <List <int?> >
            {
                new List <int?> {
                    1, 2, 3
                },
                new List <int?> {
                    1, 2, 3, 4, 5
                },
                new List <int?> {
                    1, 2
                }
            };

            List <List <int?> > output = PinningModelBase.PadColumns(input);

            for (int index = 0; index < output.Count; index++)
            {
                List <int?> currentColumn = output[index];

                if (currentColumn.Count != 5)
                {
                    Assert.Fail($"Column at index {index} was height {currentColumn.Count} instead of expected 5.");
                }
            }
        }
Пример #6
0
        public void GetSortedCutsAtIndex_IndexOutOfRangeThrowsException()
        {
            List <List <int?> > input = new List <List <int?> >
            {
                new List <int?> {
                    null, null, 4, null
                },
                new List <int?> {
                    null, null, 3, null
                },
                new List <int?> {
                    null, null, 5, null
                },
                new List <int?> {
                    null, null, 1, null
                },
                new List <int?> {
                    null, null, 7, null
                },
            };

            List <int?> output = PinningModelBase.GetSortedCutsAtIndex(input, 2);

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => { PinningModelBase.GetSortedCutsAtIndex(input, -1); });
            Assert.ThrowsException <ArgumentOutOfRangeException>(() => { PinningModelBase.GetSortedCutsAtIndex(input, 7); });
        }
Пример #7
0
        public void GetDeepestCuts_ValidInputReturnsCorrectResults()
        {
            List <List <int?> > input = new List <List <int?> >
            {
                new List <int?> {
                    1, 2, 3, 4
                },
                new List <int?> {
                    3, 4, 5
                },
                new List <int?> {
                    1, 2, 3, 4, 5, 6
                },
                new List <int?> {
                    4, 5, 6, 7
                }
            };

            List <int?> expected = new List <int?> {
                4, 5, 6, 7
            };

            List <int?> output = PinningModelBase.GetDeepestCuts(input);

            Assert.AreEqual(expected.Count, output.Count);

            for (int index = 0; index < output.Count; index++)
            {
                int?currentExpected = expected[index];
                int?currentOutput   = output[index];

                Assert.AreEqual(currentExpected, currentOutput);
            }
        }
Пример #8
0
        public void GetOperatingPins_ValidInputReturnsColumnsOfAllEqualHeight()
        {
            List <List <int?> > input = new List <List <int?> >
            {
                new List <int?> {
                    1, 2, 3, 4, 5, 6
                },
                new List <int?> {
                    3, 4, 5
                },
                new List <int?> {
                    6, 7, 8, 9
                },
                new List <int?> {
                    2, 3
                }
            };

            List <List <int?> > output = PinningModelBase.GetOperatingPins(input);

            int firstColumnHeight = output[0].Count;

            for (int index = 1; index < output.Count; index++)
            {
                List <int?> currentColumn = output[index];

                if (currentColumn.Count != firstColumnHeight)
                {
                    Assert.Fail($"Column at index {index} had height {currentColumn.Count} instead of expected {firstColumnHeight}");
                }
            }
        }
Пример #9
0
        public void PadKey_EndStoppedRightPadsLeft()
        {
            KeyModel input = new KeyModel()
            {
                Cuts = "123456"
            };

            List <int?> expected = new List <int?> {
                null, null, null, 1, 2, 3, 4, 5, 6
            };

            List <int?> output = PinningModelBase.PadKey(input, 9, false);

            if (output.Count != expected.Count)
            {
                Assert.Fail("Output has wrong length.");
            }

            for (int index = 0; index < output.Count; index++)
            {
                if (output[index] != expected[index])
                {
                    Assert.Fail($"Output has wrong value at index {index}");
                }
            }
        }
Пример #10
0
        public void PadColumn_EmptyInputReturnsColumnOfNulls()
        {
            List <int?> input = new List <int?>();

            List <int?> expected = new List <int?> {
                null, null, null, null, null
            };

            List <int?> output = PinningModelBase.PadColumn(input, 5);

            if (output.Count != expected.Count)
            {
                Assert.Fail($"Output had length {output.Count} instead of {expected.Count}.");
            }

            for (int index = 0; index < output.Count; index++)
            {
                int?currentOutput   = output[index];
                int?currentExpected = expected[index];

                if (currentOutput != currentExpected)
                {
                    Assert.Fail($"Output value {currentOutput} at index {index} did not match expected value of {currentExpected}.");
                }
            }
        }
Пример #11
0
        public void GetSortedCuts_EmptyInputReturnsEmptyOutput()
        {
            List <List <int?> > input = new List <List <int?> >();

            List <List <int?> > output = PinningModelBase.GetSortedCuts(input);

            Assert.AreEqual(output.Count, 0);
        }
Пример #12
0
        public void GetDeepestCut_UnsortedInputThrowsException()
        {
            List <int?> input = new List <int?> {
                2, 3, 1, 4, 6, 5
            };

            Assert.ThrowsException <ArgumentException>(() => { PinningModelBase.GetDeepestCut(input); });
        }
Пример #13
0
        public void GetDeepestCut_EmptyInputReturnsNull()
        {
            List <int?> input = new List <int?>();

            int?output = PinningModelBase.GetDeepestCut(input);

            Assert.AreEqual(null, output);
        }
Пример #14
0
        public void ValidateCuts_UnsortedInputThrowsException()
        {
            List <int?> input = new List <int?> {
                2, 3, 1, 4, 6, 5
            };

            Assert.ThrowsException <ArgumentException>(() => { PinningModelBase.ValidateCuts(input); });
        }
Пример #15
0
        public void ValidateCuts_InputContainsNullThrowsException()
        {
            List <int?> input = new List <int?> {
                1, 2, 3, null, 5, 6
            };

            Assert.ThrowsException <ArgumentNullException>(() => { PinningModelBase.ValidateCuts(input); });
        }
Пример #16
0
        public void ValidateCuts_EmptyInputReturnsFalse()
        {
            List <int?> input = new List <int?>();

            bool output = PinningModelBase.ValidateCuts(input);

            Assert.AreEqual(false, output);
        }
Пример #17
0
        public void GetDeepestCuts_EmptyInputReturnsEmptyOutput()
        {
            List <List <int?> > input = new List <List <int?> >();

            List <int?> output = PinningModelBase.GetDeepestCuts(input);

            Assert.AreEqual(0, output.Count);
        }
Пример #18
0
        public void GetMaxColumnHeight_EmptyInputReturnsZeroHeight()
        {
            List <List <int?> > input = new List <List <int?> >();

            int output = PinningModelBase.GetMaxColumnHeight(input);

            Assert.AreEqual(output, 0);
        }
Пример #19
0
        public void GetDeepestCut_InputContainsNullThrowsException()
        {
            List <int?> input = new List <int?> {
                1, 2, 3, null, 5, 6
            };

            Assert.ThrowsException <ArgumentNullException>(() => { PinningModelBase.GetDeepestCut(input); });
        }
Пример #20
0
        public void PadColumn_PaddingHeightLessThanInputThrowsException()
        {
            List <int?> input = new List <int?> {
                1, 2, 3, 4, 5
            };

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => { PinningModelBase.PadColumn(input, 2); });
        }
Пример #21
0
        public void GetMaxKeyLength_EmptyListReturnsZero()
        {
            List <KeyModel> input = new List <KeyModel>();

            int output = PinningModelBase.GetMaxKeyLength(input);

            Assert.AreEqual(output, 0);
        }
Пример #22
0
        public void PadColumns_EmptyInputReturnsEmptyOutput()
        {
            List <List <int?> > input = new List <List <int?> >();

            List <List <int?> > output = PinningModelBase.PadColumns(input);

            Assert.AreEqual(output.Count, 0);
        }
Пример #23
0
        public void CalculatePinColumn_UnsortedInputThrowsException()
        {
            List <int?> input = new List <int?> {
                3, 1, 2, 4
            };

            Assert.ThrowsException <ArgumentException>(() => { PinningModelBase.CalculatePinColumn(input); });
        }
Пример #24
0
        public void CalculatePinColumn_InputContainsNullThrowsException()
        {
            List <int?> input = new List <int?> {
                1, 2, null, 3
            };

            Assert.ThrowsException <ArgumentNullException>(() => { PinningModelBase.CalculatePinColumn(input); });
        }
Пример #25
0
        public void CalculatePinColumn_EmptyInputReturnsEmptyOutput()
        {
            List <int?> input = new List <int?>();

            List <int?> output = PinningModelBase.CalculatePinColumn(input);

            Assert.AreEqual(input.Count, output.Count);
        }
Пример #26
0
        public void GetMaxKeyLength_ListOfBlankKeysReturnsZero()
        {
            List <KeyModel> input = new List <KeyModel> {
                new KeyModel(), new KeyModel(), new KeyModel()
            };

            int output = PinningModelBase.GetMaxKeyLength(input);

            Assert.AreEqual(output, 0);
        }
Пример #27
0
        public void ValidateCuts_ValidInputReturnsTrue()
        {
            List <int?> input = new List <int?> {
                1, 2, 3
            };

            bool output = PinningModelBase.ValidateCuts(input);

            Assert.AreEqual(true, output);
        }
Пример #28
0
        public void GetDeepestCut_ValidInputReturnsDeepestCut()
        {
            List <int?> input = new List <int?> {
                1, 2, 3, 4, 5, 6
            };

            int?output = PinningModelBase.GetDeepestCut(input);

            Assert.AreEqual(6, output);
        }
Пример #29
0
        public void GetPaddedKeys_EmptyInputListReturnsEmptyOutputList()
        {
            List <KeyModel> input = new List <KeyModel>();

            List <List <int?> > output = PinningModelBase.GetPaddedKeys(input, 5);

            if (output.Count != 0)
            {
                Assert.Fail($"Output count was {output.Count} instead of zero.");
            }
        }
Пример #30
0
        public void GetSortedCutsAtIndex_ValidIndexReturnsProperlySortedCutsWithNullsAndDuplicatesOmitted()
        {
            List <List <int?> > input = new List <List <int?> >
            {
                new List <int?> {
                    null, null, 4, null
                },
                new List <int?> {
                    null, null, 3, null
                },
                new List <int?> {
                    null, null, 7, null
                },
                new List <int?> {
                    null, null, 5, null
                },
                new List <int?> {
                    null, null, null, null
                },
                new List <int?> {
                    null, null, 1, null
                },
                new List <int?> {
                    null, null, 3, null
                },
                new List <int?> {
                    null, null, 7, null
                }
            };

            List <int?> expected = new List <int?> {
                1, 3, 4, 5, 7
            };

            List <int?> output = PinningModelBase.GetSortedCutsAtIndex(input, 2);

            if (output.Count != expected.Count)
            {
                Assert.Fail($"Output had length {output.Count} instead of {expected.Count}.");
            }

            for (int index = 0; index < output.Count; index++)
            {
                int?currentOutput   = output[index];
                int?currentExpected = expected[index];

                if (currentOutput != currentExpected)
                {
                    Assert.Fail($"Output value {currentOutput} at index {index} did not match expected value {currentExpected}.");
                }
            }
        }