コード例 #1
0
        public void ContainsComponentsOf_MatchIsDouble_True()
        {
            int        total   = 10;
            List <int> numbers = new List <int> {
                1, 2, 3, 4, 5, 5
            };
            List <int> randomNumbers = new List <int>();

            int numberOfElementsInList = numbers.Count;

            for (int i = numberOfElementsInList; i != 0; i--)
            {
                Random random = new Random();
                int    index  = random.Next(i);

                randomNumbers.Add(numbers[index]);
                numbers.RemoveAt(index);
            }

            bool result = FirstTenProblems.ContainsComponentsOf(randomNumbers, total);

            Assert.AreEqual(0, numbers.Count);
            Assert.AreEqual(numberOfElementsInList, randomNumbers.Count);
            Assert.AreEqual(true, result);
        }
コード例 #2
0
        public void ProductsExcludingElement_GivenExample_AllRight(int[] input, int[] expected)
        {
            int[] output = FirstTenProblems.ProductsExcludingElement(input);

            for (var i = 0; i < input.Length; i++)
            {
                Assert.AreEqual(expected[i], output[i]);
            }
        }
コード例 #3
0
        public void SerializeBinaryTree_ExampleTree()
        {
            BinaryTreeNode node     = new BinaryTreeNode("root", new BinaryTreeNode("left", new BinaryTreeNode("left.left", null, null), null), new BinaryTreeNode("right", null, null));
            string         expected = "root>(left>(left.left>-,-),-),(right>-,-)";

            string serialized = FirstTenProblems.SerializeBinaryTree(node);

            Assert.AreEqual(expected, serialized);
        }
コード例 #4
0
        public void ContainsComponentsOf_EmptyList_False()
        {
            int        total   = 2;
            List <int> numbers = new List <int> {
            };

            bool result = FirstTenProblems.ContainsComponentsOf(numbers, total);

            Assert.AreEqual(false, result);
        }
コード例 #5
0
        public void DeserializeBinaryTree_ExampleTree()
        {
            string         example = "root>(left>(left.left>-,left.left.right>-,-),-),(right>-,-)";
            BinaryTreeNode node    = FirstTenProblems.DeserializeBinaryTree(example);

            Assert.AreEqual(node.Value, "root");
            Assert.AreEqual(node.Left.Value, "left");
            Assert.AreEqual(node.Left.Left.Value, "left.left");
            Assert.AreEqual(node.Left.Left.Right.Value, "left.left.right");
            Assert.AreEqual(node.Right.Value, "right");
        }
コード例 #6
0
        public void ContainsComponentsOf_OneToTen_True()
        {
            int        total   = 10;
            List <int> numbers = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            bool result = FirstTenProblems.ContainsComponentsOf(numbers, total);

            Assert.AreEqual(true, result);
        }
コード例 #7
0
        public void ProductsExcludingElement_ContainsZero_AllRight()
        {
            int[] input = new int[] { 1, 2, 0, 4 };

            int[] output = FirstTenProblems.ProductsExcludingElement(input);

            Assert.AreEqual(0, output[0]);
            Assert.AreEqual(0, output[1]);
            Assert.AreEqual(1 * 2 * 4, output[2]);
            Assert.AreEqual(0, output[3]);
        }
コード例 #8
0
        public void GetLowestMissingInt_ExampleTests(int[] input, int expected)
        {
            int value = FirstTenProblems.GetLowestMissingInt(input);

            Assert.AreEqual(expected, value);
        }