public void DeserializedTree_ShouldNotBeTheSameAsSerialized()
        {
            var builder = new LineByLineTreeBuilder();

            builder.AddData(Enumerable.Range(1, 1024).Select(x => x.ToString()).ToArray());
            string input = Api.Serialize(builder.Root);


            var actualTree   = Api.BuildTreeByStringInput(input);
            var expectedTree = builder.Root;

            var traverseAlgorythm = DepthTraverse.Instance;

            using (var actualEnumerator = traverseAlgorythm.GetAll(actualTree).GetEnumerator())
            {
                using (var expectedEnumerator = traverseAlgorythm.GetAll(expectedTree).GetEnumerator())
                {
                    bool actualMove, expectedMove;
                    do
                    {
                        actualMove   = actualEnumerator.MoveNext();
                        expectedMove = expectedEnumerator.MoveNext();

                        Assert.AreEqual(actualMove, expectedMove);

                        var actualNode   = actualEnumerator.Current;
                        var expectedNode = expectedEnumerator.Current;

                        Assert.AreNotSame(actualNode, expectedNode);
                    } while (actualMove && expectedMove);
                }
            }
        }
        public void SerializedTree_ShouldBeWellUnderstoodByParser()
        {
            var builder = new LineByLineTreeBuilder();

            builder.AddData(Enumerable.Range(1, 1024).Select(x => x.ToString()).ToArray());
            string input = Api.Serialize(builder.Root);


            var actualTree   = Api.BuildTreeByStringInput(input);
            var expectedTree = builder.Root;

            Assert.IsTrue(TreeComparer.Instance.Equals(expectedTree, actualTree));
        }
        public void Serializer_ShouldProduceDataFromTheTask_WhenReadableTextIsComing()
        {
            var readableText = "Quick Brown Fox Jumps # Over The Lazy Dog";

            var builder = new LineByLineTreeBuilder(Tree.Create("A").Result);

            builder.AddData(readableText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

            string actualResult   = Api.Serialize(builder.Root, InlineTreeFormatter.WellKnownFormats.CommaAndSpaceSeparated);
            string expectedResult = TaskData.ExampleTreeInput;

            CollectionAssert.AreEquivalent(
                expectedResult.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries),
                actualResult.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
        }
        public void Parser_ShouldPerformFast_WhenReadingFromMemory()
        {
            var data = Enumerable.Range(0, int.MaxValue / 1000).Select(x => UpperLettersAndNumericCharacters.Instance.GetRandom(16)).Distinct().ToArray();

            var builder = new LineByLineTreeBuilder();

            builder.AddData(data);
            string input = Api.Serialize(builder.Root, InlineTreeFormatter.WellKnownFormats.CommaAndSpaceSeparated);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            Api.BuildTreeByStringInput(input);

            sw.Stop();

            var acceptanceTimeInSeconds = 6;

            Trace.WriteLine(string.Format("Elapsed={0}", sw.Elapsed.Seconds));
            Assert.IsTrue(sw.Elapsed.Seconds <= acceptanceTimeInSeconds);
        }