Esempio n. 1
0
 public void TestGetHashCode()
 {
     {
         var emptyRope = Rope.Create <char>();
         Assert.Equal(371857150, emptyRope.GetHashCode());
     }
     {
         var singletonRope = Rope.Create('a');
         Assert.Equal(378386365, singletonRope.GetHashCode());
     }
     {
         var shortRope = Rope.CreateRange("abcd");
         Assert.Equal(1200620054, shortRope.GetHashCode());
     }
     {
         var shortConcatRope = Rope.CreateRange("ab").Concat(Rope.CreateRange("cd"));
         Assert.Equal(1200620054, shortConcatRope.GetHashCode());
     }
     {
         var longConcatRope = Rope.CreateRange(Enumerable.Repeat('a', 500)).Concat(Rope.CreateRange(Enumerable.Repeat('a', 500)));
         Assert.Equal(1129875070, longConcatRope.GetHashCode());
     }
     {
         var manyConcatRope = Enumerable.Repeat(Rope.Create('a'), 3).Aggregate((x, y) => x.Concat(y));
         Assert.Equal(119771257, manyConcatRope.GetHashCode());
     }
     {
         var longManyConcatRope = Enumerable.Repeat(Rope.Create('a'), 1000).Aggregate((x, y) => x.Concat(y));
         Assert.Equal(1129875070, longManyConcatRope.GetHashCode());
     }
 }
Esempio n. 2
0
        public void ShouldHavePositiveIndexAndLength()
        {
            var rope = Rope.Create("1");

            Assert.Throws <ArgumentOutOfRangeException>(() => rope.Delete(-1, 2));
            Assert.Throws <ArgumentOutOfRangeException>(() => rope.Delete(1, 0));
        }
Esempio n. 3
0
        public void ShouldSplitAfterConcat()
        {
            var split = (Rope.Create("Hello") + "World").Split(6);

            Assert.Equal("HelloWo", split.Item1.ToString());
            Assert.Equal("rld", split.Item2.ToString());
        }
Esempio n. 4
0
 public void TestLength()
 {
     {
         var emptyRope = Rope.Create <char>();
         Assert.Equal(0, emptyRope.Length);
     }
     {
         var singletonRope = Rope.Create('a');
         Assert.Equal(1, singletonRope.Length);
     }
     {
         var shortRope = Rope.CreateRange("abcd");
         Assert.Equal(4, shortRope.Length);
     }
     {
         var shortConcatRope = Rope.CreateRange("ab").Concat(Rope.CreateRange("cd"));
         Assert.Equal(4, shortConcatRope.Length);
     }
     {
         var longConcatRope = Rope.CreateRange(Enumerable.Repeat('a', 500)).Concat(Rope.CreateRange(Enumerable.Repeat('a', 500)));
         Assert.Equal(1000, longConcatRope.Length);
     }
     {
         var manyConcatRope = Enumerable.Repeat(Rope.Create('a'), 3).Aggregate((x, y) => x.Concat(y));
         Assert.Equal(3, manyConcatRope.Length);
     }
     {
         var longManyConcatRope = Enumerable.Repeat(Rope.Create('a'), 1000).Aggregate((x, y) => x.Concat(y));
         Assert.Equal(1000, longManyConcatRope.Length);
     }
 }
Esempio n. 5
0
        public void TestRopeAsEnumerableEqualsSelfToImmutableArray()
        {
            void ShouldEqualSelf <T>(Rope <T> item) => Assert.Equal(item.ToImmutableArray(), item.AsEnumerable());

            {
                var emptyRope = Rope.Create <char>();
                ShouldEqualSelf(emptyRope);
            }
            {
                var singletonRope = Rope.Create('a');
                ShouldEqualSelf(singletonRope);
            }
            {
                var shortRope = Rope.CreateRange("abcd");
                ShouldEqualSelf(shortRope);
            }
            {
                var shortConcatRope = Rope.CreateRange("ab").Concat(Rope.CreateRange("cd"));
                ShouldEqualSelf(shortConcatRope);
            }
            {
                var longConcatRope = Rope.CreateRange(Enumerable.Repeat('a', 500)).Concat(Rope.CreateRange(Enumerable.Repeat('a', 500)));
                ShouldEqualSelf(longConcatRope);
            }
            {
                var manyConcatRope = Enumerable.Repeat(Rope.Create('a'), 3).Aggregate((x, y) => x.Concat(y));
                ShouldEqualSelf(manyConcatRope);
            }
            {
                var longManyConcatRope = Enumerable.Repeat(Rope.Create('a'), 1000).Aggregate((x, y) => x.Concat(y));
                ShouldEqualSelf(longManyConcatRope);
            }
        }
Esempio n. 6
0
 public void TestToImmutableArray()
 {
     {
         var emptyRope = Rope.Create <char>();
         Assert.Equal(ImmutableArray.Create <char>(), emptyRope.ToImmutableArray());
     }
     {
         var singletonRope = Rope.Create('a');
         Assert.Equal(new[] { 'a' }, singletonRope.ToImmutableArray());
     }
     {
         var shortRope = Rope.CreateRange("abcd");
         Assert.Equal("abcd", shortRope.ToImmutableArray());
     }
     {
         var shortConcatRope = Rope.CreateRange("ab").Concat(Rope.CreateRange("cd"));
         Assert.Equal("abcd", shortConcatRope.ToImmutableArray());
     }
     {
         var longConcatRope = Rope.CreateRange(Enumerable.Repeat('a', 500)).Concat(Rope.CreateRange(Enumerable.Repeat('a', 500)));
         Assert.Equal(Enumerable.Repeat('a', 1000), longConcatRope.ToImmutableArray());
     }
     {
         var manyConcatRope = Enumerable.Repeat(Rope.Create('a'), 3).Aggregate((x, y) => x.Concat(y));
         Assert.Equal("aaa", manyConcatRope.ToImmutableArray());
     }
     {
         var longManyConcatRope = Enumerable.Repeat(Rope.Create('a'), 1000).Aggregate((x, y) => x.Concat(y));
         Assert.Equal(Enumerable.Repeat('a', 1000), longManyConcatRope.ToImmutableArray());
     }
 }
Esempio n. 7
0
        public void ShouldGetIndex()
        {
            const string text = "0123456789";
            var          rope = Rope.Create(text, 2);

            Assert.Equal(text[5], rope[5]);
        }
Esempio n. 8
0
    public void ToggleRope(bool newRope)
    {
        if (newRope == roped)
        {
            return;
        }

        if (newRope)
        {
            Debug.Log("StartRope");
        }
        else
        {
            Debug.Log("EndRope");
        }

        roped = newRope;
        rope.gameObject.SetActive(roped);
        if (roped)
        {
            rope.Create(world);
        }
        else
        {
            rope.End();
        }
    }
Esempio n. 9
0
        public void ShouldDelete()
        {
            var rope = Rope.Create("0123456789");

            var newRope = rope.Delete(3, 3);

            Assert.Equal("0126789", newRope.ToString());
        }
Esempio n. 10
0
        public void ShouldConcat()
        {
            var left  = Rope.Create("Hello");
            var right = Rope.Create("World");

            var concat = (left + right).ToString();

            Assert.Equal("HelloWorld", concat);
        }
        public void ConcatenateRope()
        {
            var rope = Rope.Create("Test");

            for (var i = 0; i < 10000; i++)
            {
                rope += $"some string{i}";
            }
        }
Esempio n. 12
0
        public void ShouldInsertRope()
        {
            var rope1 = Rope.Create("Hello World");
            var rope2 = Rope.Create(" dear");

            var newRope = rope1.Insert(rope2, 4);

            Assert.Equal("Hello dear World", newRope.ToString());
        }
Esempio n. 13
0
        public void ShouldCreateAndDisplayRope()
        {
            const string sentence = "Hello_my_name_is_Simon";
            var          rope     = Rope.Create(sentence, 4);

            var output = rope.ToString();

            Assert.Equal(sentence, output);
        }
Esempio n. 14
0
        public void ShouldReturnLeftPartWhenCompleteLength()
        {
            var rope = Rope.Create("01234567");

            var pair = rope.Split(7);

            Assert.Equal("01234567", pair.Item1.ToString());
            Assert.Null(pair.Item2);
        }
Esempio n. 15
0
        public void ShouldSplitRope(string word, int indexToSplit, string expectedLeftSide, string expectedRightSide)
        {
            var rope = Rope.Create(word);

            var splitPair = rope.Split(indexToSplit);

            Assert.Equal(expectedLeftSide, splitPair.Item1.ToString());
            Assert.Equal(expectedRightSide, splitPair.Item2.ToString());
        }
Esempio n. 16
0
        public void ShouldGetIndexAfterRebalance()
        {
            var rope1 = Rope.Create("012");
            var rope2 = Rope.Create("345");
            var rope  = rope1 + rope2;

            var index = rope[3];

            Assert.Equal('3', index);
        }
Esempio n. 17
0
        public void ShouldConcatWithStrings()
        {
            var left  = Rope.Create("Hello");
            var right = Rope.Create("World");

            var first  = left + "World";
            var second = "Hello" + right;

            Assert.Equal("HelloWorld", first.ToString());
            Assert.Equal("HelloWorld", second.ToString());
        }
Esempio n. 18
0
        public RopeTest()
        {
            const int   N        = 20;
            const float L        = 0.5f;
            var         vertices = new Vector2[N];
            var         masses   = new float[N];

            for (var i = 0; i < N; ++i)
            {
                vertices[i].Set(0.0f, L * (N - i));
                masses[i] = 1.0f;
            }

            masses[0] = 0.0f;
            masses[1] = 0.0f;
            Tuning1   = new RopeTuning
            {
                BendHertz        = 30.0f,
                BendDamping      = 4.0f,
                BendStiffness    = 1.0f,
                BendingModel     = BendingModel.PbdTriangleBendingModel,
                Isometric        = true,
                StretchHertz     = 30.0f,
                StretchDamping   = 4.0f,
                StretchStiffness = 1.0f,
                StretchingModel  = StretchingModel.PbdStretchingModel
            };

            Tuning2 = new RopeTuning
            {
                BendHertz        = 30.0f,
                BendDamping      = 0.7f,
                BendStiffness    = 1.0f,
                BendingModel     = BendingModel.PbdHeightBendingModel,
                Isometric        = true,
                StretchHertz     = 30.0f,
                StretchDamping   = 1.0f,
                StretchStiffness = 1.0f,
                StretchingModel  = StretchingModel.PbdStretchingModel
            };

            Position1.Set(-5.0f, 15.0f);
            Position2.Set(5.0f, 15.0f);

            var def = new RopeDef
            {
                Vertices = vertices,
                Count    = N,
                Gravity  = new Vector2(0.0f, -10.0f),
                Masses   = masses,
                Position = Position1,
                Tuning   = Tuning1
            };

            Rope1 = new Rope();
            Rope1.Create(def);

            def.Position = Position2;
            def.Tuning   = Tuning2;
            Rope2        = new Rope();
            Rope2.Create(def);

            Iterations1 = 8;
            Iterations2 = 8;

            Speed = 10.0f;
        }
Esempio n. 19
0
 public void ShouldThrowExceptionWhenNegativeIndex()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Rope.Create("a").Split(-1));
 }