コード例 #1
0
ファイル: EasyPoolTests.cs プロジェクト: ywscr/Easy.Common
        public void When_getting_and_renting_items_from_the_pool_with_null_reset()
        {
            Func <SomeObject> factory = () => new SomeObject {
                Name = "Foo", Number = 1
            };

            using (IEasyPool <SomeObject> pool = new EasyPool <SomeObject>(factory, null, 5))
            {
                pool.Count.ShouldBe((uint)0);

                var obj1 = pool.Rent();

                obj1.ShouldNotBeNull();
                obj1.Name.ShouldBe("Foo");
                obj1.Number.ShouldBe(1);

                pool.Count.ShouldBe((uint)0);

                pool.Return(obj1).ShouldBeTrue();

                pool.Count.ShouldBe((uint)1);

                var obj2 = pool.Rent();

                obj2.ShouldNotBeNull();
                obj2.ShouldBe(obj1);

                obj2.Name.ShouldBe("Foo");
                obj2.Number.ShouldBe(1);
            }
        }
コード例 #2
0
ファイル: EasyPoolTests.cs プロジェクト: ywscr/Easy.Common
        public void When_returning_more_than_max_pool_size()
        {
            Func <SomeObject> factory  = () => new SomeObject();
            const int         MaxCount = 1;

            using (IEasyPool <SomeObject> pool = new EasyPool <SomeObject>(factory, null, MaxCount))
            {
                pool.Count.ShouldBe((uint)0);

                var obj1 = new SomeObject();

                pool.Return(obj1).ShouldBeTrue();

                pool.Count.ShouldBe((uint)1);

                var obj2 = new SomeObject();

                pool.Return(obj2).ShouldBeFalse();

                pool.Count.ShouldBe((uint)1);

                var pooledObj = pool.Rent();
                pooledObj.ShouldBe(obj1);

                pool.Count.ShouldBe((uint)0);
            }
        }
コード例 #3
0
ファイル: EasyPoolTests.cs プロジェクト: ywscr/Easy.Common
        public void When_disposing_the_pool()
        {
            Func <SomeObject>      factory  = () => new SomeObject();
            const int              MaxCount = 1;
            IEasyPool <SomeObject> pool     = new EasyPool <SomeObject>(factory, null, MaxCount);
            var obj1 = new SomeObject();

            pool.Return(obj1).ShouldBeTrue();
            pool.Count.ShouldBe((uint)1);

            pool.Dispose();
            pool.Count.ShouldBe((uint)0);
        }
コード例 #4
0
ファイル: EasyPool.cs プロジェクト: sukritidawar/Eduthon-AR
    void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
        }

        Instance = this;

        thisTransform = transform;
        pooledObjects = new GameObject[poolSize];
        AddObjectsToPool();
    }