Esempio n. 1
0
        public void Properties_Of_Different_Types_Can_Have_The_Same_Name()
        {
            var allocator   = new ParticleAllocator(10);
            var reservation = allocator.Reserve(5);

            allocator.RegisterProperty(typeof(bool), "Something");
            allocator.RegisterProperty(typeof(float), "Something");

            var boolValues  = reservation.GetPropertyValues <bool>("Something");
            var floatValues = reservation.GetPropertyValues <float>("Something");
        }
Esempio n. 2
0
        public void Property_Values_Remain_After_Expansion()
        {
            var allocator = new ParticleAllocator(5);

            allocator.RegisterProperty(typeof(float), "Something");

            var first = allocator.Reserve(3);

            {
                var values = first.GetPropertyValues <float>("Something");
                values[0] = 1.1f;
                values[1] = 2.2f;
                values[2] = 3.3f;
            }

            allocator.Reserve(3);

            allocator.Capacity.ShouldBeGreaterThan(5, "Expected capacity to grow");

            var newValues = first.GetPropertyValues <float>("Something");

            newValues[0].ShouldBe(1.1f);
            newValues[1].ShouldBe(2.2f);
            newValues[2].ShouldBe(3.3f);
        }
Esempio n. 3
0
        public void Cannot_Get_Property_Not_In_Valid_Readable_Hash_Set()
        {
            var property1 = new ParticleProperty(typeof(bool), "Something");
            var property2 = new ParticleProperty(typeof(bool), "Something2");
            var allocator = new ParticleAllocator(10);

            allocator.RegisterProperty(property1.Type, property1.Name);
            allocator.RegisterProperty(property2.Type, property2.Name);

            var reservation = allocator.Reserve(5);
            var collection  = new ParticleCollection(reservation)
            {
                ValidPropertiesToSet = new HashSet <ParticleProperty>(new[] { property1 })
            };

            Assert.ThrowsAny <Exception>(() => collection.GetReadOnlyPropertyValues <bool>(property2.Name));
        }
Esempio n. 4
0
        public void KeyNotFoundException_When_Property_Registered_For_Different_Type()
        {
            var allocator   = new ParticleAllocator(10);
            var reservation = allocator.Reserve(5);

            allocator.RegisterProperty(typeof(float), "Something");

            Assert.Throws <KeyNotFoundException>(() => reservation.GetPropertyValues <bool>("Something"));
        }
Esempio n. 5
0
        public void Properties_Marked_As_Valid_For_Reading_Can_Be_Retrieved_As_Read_Only()
        {
            var property  = new ParticleProperty(typeof(bool), "Something");
            var allocator = new ParticleAllocator(10);

            allocator.RegisterProperty(property.Type, property.Name);

            var reservation = allocator.Reserve(5);
            var collection  = new ParticleCollection(reservation)
            {
                ValidPropertiesToRead = new HashSet <ParticleProperty>(new[] { property })
            };

            var result = collection.GetReadOnlyPropertyValues <bool>(property.Name);

            result.Length.ShouldBe(reservation.Length);
        }
Esempio n. 6
0
        public void Multiple_Reservations_Have_Distinct_Property_Values()
        {
            var allocator = new ParticleAllocator(8);

            allocator.RegisterProperty(typeof(float), "Something");

            var first  = allocator.Reserve(3);
            var second = allocator.Reserve(2);
            var third  = allocator.Reserve(3);

            allocator.Capacity.ShouldBe(8, "Allocator capacity shouldn't have changed yet");

            {
                var values = first.GetPropertyValues <float>("Something");
                values[0] = 1.1f;
                values[1] = 2.2f;
                values[2] = 3.3f;
            }

            {
                var values = third.GetPropertyValues <float>("Something");
                values[0] = 4.4f;
                values[1] = 5.5f;
                values[2] = 6.6f;
            }

            second.Dispose();
            allocator.Reserve(3); // cause defrag or expansion, don't care which for this test

            {
                var values = first.GetPropertyValues <float>("Something");
                values[0].ShouldBe(1.1f);
                values[1].ShouldBe(2.2f);
                values[2].ShouldBe(3.3f);
            }

            {
                var values = third.GetPropertyValues <float>("Something");
                values[0].ShouldBe(4.4f);
                values[1].ShouldBe(5.5f);
                values[2].ShouldBe(6.6f);
            }
        }
Esempio n. 7
0
        public void Property_Values_Remain_After_A_Defrag()
        {
            var allocator = new ParticleAllocator(15);

            allocator.RegisterProperty(typeof(float), "Something");

            var first  = allocator.Reserve(3);
            var second = allocator.Reserve(2);
            var third  = allocator.Reserve(3);
            var fourth = allocator.Reserve(2);
            var fifth  = allocator.Reserve(3);

            var thirdStartIndex = third.StartIndex;

            {
                var values = third.GetPropertyValues <float>("Something");
                values[0] = 1.1f;
                values[1] = 2.2f;
                values[2] = 3.3f;
            }

            second.Dispose();
            fourth.Dispose();

            var sixth = allocator.Reserve(3);

            allocator.Capacity.ShouldBe(15);                     // No increase in capacity in a defrag
            VerifyAllAreConsecutive(first, third, fifth, sixth); // defrag actually occured

            third.StartIndex.ShouldNotBe(thirdStartIndex, "Expected 'third' to have moved start indexes");
            var newValues = third.GetPropertyValues <float>("Something");

            newValues[0].ShouldBe(1.1f);
            newValues[1].ShouldBe(2.2f);
            newValues[2].ShouldBe(3.3f);
        }
Esempio n. 8
0
        public void Can_Set_Value_For_Registered_Property()
        {
            var allocator   = new ParticleAllocator(10);
            var reservation = allocator.Reserve(5);

            allocator.RegisterProperty(typeof(float), "Something");

            var values = reservation.GetPropertyValues <float>("Something");

            values.Length.ShouldBe(5);
            values[0] = 1.1f;
            values[1] = 2.2f;
            values[2] = 3.3f;
            values[3] = 4.4f;
            values[4] = 5.5f;

            var values2 = reservation.GetPropertyValues <float>("Something");

            values2[0].ShouldBe(values[0]);
            values2[1].ShouldBe(values[1]);
            values2[2].ShouldBe(values[2]);
            values2[3].ShouldBe(values[3]);
            values2[4].ShouldBe(values[4]);
        }