示例#1
0
        private static ConcateRope CreateRope(int depth, int length)
        {
            Debug.Assert(depth >= 1);

            var numOfParts = depth + 1;
            var lengthOfParts = length / numOfParts;

            var primitiveRope = new FlatRope(new String(' ', lengthOfParts));

            Rope rope = primitiveRope;
            for (var i = 1; i < numOfParts; i++) {
                if (i < numOfParts - 1) {
                    rope = new ConcateRope(rope, primitiveRope);
                }
                else {
                    var lastRope = new FlatRope(new String(' ', length - rope.Length));
                    rope = new ConcateRope(rope, lastRope);
                }
            }

            var concateRope = rope.As<ConcateRope>();
            Debug.Assert(concateRope.Depth == depth);
            Debug.Assert(concateRope.Length == length);

            return concateRope;
        }
示例#2
0
        public void SimplePropertiesShouldBeRight()
        {
            var hwRope = new ConcateRope(new FlatRope("Hello "), new FlatRope("World"));
            hwRope.Depth.Should().Be(1);

            var rope = new ConcateRope(new FlatRope("Say "), hwRope);
            rope.Depth.Should().Be(2);
            rope.Length.Should().Be("Say Hello World".Length);
            rope.ToString().Should().Be("Say Hello World");
        }