Esempio n. 1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            CircularBuffer<int> items = new CircularBuffer<int>();

            for(int i = 0; i < 1000; i++)
            {
                items.Add(i);
            }

            Console.WriteLine("CircularBuffer<int> default capacity, current count: " + items.Count);

            ObservableCollection<int> obserableItems = new CircularObservableBuffer<int>(items);
            Console.WriteLine("ObservableCollection<int> default capacity, current count: " + items.Count);

            obserableItems.CollectionChanged += (sender, eventArgs) =>
            {
                Console.WriteLine(eventArgs.Action);
            };

            for(int i = 0; i < 1000; i++)
            {
                obserableItems.Add(i);
            }

            Console.WriteLine("ObservableCollection<int> default capacity, current count: " + obserableItems.Count);

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
 public void CircularBuffer_Back_EmptyBufferThrowsException()
 {
     var buffer = new CircularBuffer<int>(5);
     Assert.That(() => buffer.Back(),
                  Throws.Exception.TypeOf<InvalidOperationException>().
                  With.Property("Message").ContainsSubstring("empty buffer"));
 }
 public void CircularBuffer_BackOfBufferOverflowByOne_CorrectItem()
 {
     var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
     buffer.PushBack(42);
     Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 4, 42 }));
     Assert.That(buffer.Back(), Is.EqualTo(42));
 }
    protected override void Awake()
    {
        base.Awake();
        _environmentFadeVisuals    = base.trackedSpace.Find("EnvironmentFadeCube").GetComponent <MeshRenderer>();
        _trackingSpaceFloorVisuals = base.trackedSpace.Find("Plane").GetComponent <MeshRenderer>();
        _chaperoneVisuals          = base.trackedSpace.Find("Chaperone").GetComponent <MeshRenderer>();

        _baseMaximumRotationGain = MAX_ROT_GAIN;
        _baseMinimumRotationGain = MIN_ROT_GAIN;
        _baseCurvatureRadius     = CURVATURE_RADIUS;

        _AC2FRedirector = GetComponent <AC2FRedirector>();
        _AC2FRedirector.redirectionManager = this;

        _S2CRedirector = GetComponent <S2CRedirectorER>();

        // By setting _ZWrite to 1 we avoid some sorting issues.
        // Setting the render queue a bit higher than normal should help with some transparency issues between the chaperone and fade cube too.
        _trackingSpaceFloorVisuals.material.SetInt("_ZWrite", 1);
        _chaperoneVisuals.material.SetInt("_ZWrite", 1);
        _chaperoneVisuals.material.renderQueue = 4000;

        _distractorTrigger = trackedSpace.GetComponentInChildren <DistractorTrigger>();
        _distractorTrigger._bodyCollider         = body.GetComponentInChildren <CapsuleCollider>();
        _distractorTrigger._redirectionManagerER = this;
        _distractorTrigger.Initialise();

        _distractorPrefabPool.AddRange(Resources.LoadAll <GameObject>("Distractors"));
        _pausables.AddRange(FindObjectsOfType <Pausable>());

        _virtualWorld = GameObject.Find("Virtual Environment");
        _uiManager    = GameObject.Find("UIManager").GetComponent <UIManager>();

        _uiManager._redirectorManager = this;

        _positionSamples = new CircularBuffer.CircularBuffer <Vector3>(_positionSamplesPerSecond);

        _gameManager = GameObject.Find("GameManager").GetComponent <GameManager>();

        var floorColour = _trackingSpaceFloorVisuals.material.color;

        floorColour.a = _alwaysDisplayTrackingFloor ? 1f : 0f;
        _trackingSpaceFloorVisuals.material.color = floorColour;

        _playerManager = GetComponentInChildren <PlayerManager>();
        _distractorCooldownMagnitudeAccumulation = _distractorMagnitudeCooldownAfterDeath;

        RepopulateRandomDistractorList();

        if (_debugGainApplicationType)
        {
            _objectivePointerRenderer     = GetComponentInChildren <ObjectivePointer>().GetComponentInChildren <MeshRenderer>();
            _baseObjectivePointerMaterial = _objectivePointerRenderer.material;
        }
    }
        public void CircularBuffer_ConstructurSizeIndexAccess_CorrectContent()
        {
            var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3 });

            Assert.That(buffer.Capacity, Is.EqualTo(5));
            Assert.That(buffer.Size, Is.EqualTo(4));
            for (int i = 0; i < 4; i++)
            {
                Assert.That(buffer[i], Is.EqualTo(i));
            }
        }
        public void CircularBuffer_GetEnumeratorConstructorDefinedArray_Correctcontent()
        {
            var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3 });

            int x = 0;
            foreach (var item in buffer)
            {
                Assert.That(item, Is.EqualTo(x));
                x++;
            }
        }
        public static void Main(string[] args)
        {
            var buffer = new CircularBuffer<int>(5);

            for (int i = 0; i < 5; i++)
            {
                buffer.PushBack(i);
            }

            Console.WriteLine(buffer.Front()); // 0
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(buffer[i]);
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var q = new CircularBuffer<int>(100);

            for (int i = 1; i <= 150; i++)
            {
                q.Enqueue(i);
            }

            foreach ( int i in q ) {
                Console.WriteLine(i.ToString());
            }

            Console.ReadKey();
        }
 public void AddLast()
 {
     try
     {
         CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(10);
         for (Int32 i = 0; i < 10; i++)
         {
             buffer.AddLast(i);
         }
     }
     catch
     {
         Assert.Fail();
     }
 }
 public void Dynamic()
 {
     try
     {
         CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(12);
         buffer.IsDynamic = true;
         for (Int32 i = 0; buffer.Size != buffer.Capacity; i++)
         {
             buffer.AddLast(i);
         }
         buffer.AddLast(12);
     }
     catch
     {
         Assert.Fail();
     }
 }
 public void Clear()
 {
     try
     {
         CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(10);
         for (Int32 i = 0; i < 10; i++)
         {
             buffer.AddFirst(i);
         }
         buffer.Reset();
         if (buffer.Size != 0)
         {
             Assert.Fail();
         }
     }
     catch
     {
         Assert.Fail();
     }
 }
Esempio n. 12
0
        static void Main( string[] args )
        {
            CircularBuffer circularBuffer = new CircularBuffer( 8 );

            Console.WriteLine( "Storing 1" );
            circularBuffer.Store( 1 );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Storing 2" );
            circularBuffer.Store( 2 );
            Console.WriteLine( "Storing 3" );
            circularBuffer.Store( 3 );
            Console.WriteLine( "Storing 4" );
            circularBuffer.Store( 4 );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Storing 5" );
            circularBuffer.Store( 5 );
            Console.WriteLine( "Storing 6" );
            circularBuffer.Store( 6 );
            Console.WriteLine( "Storing 7" );
            circularBuffer.Store( 7 );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Storing 8" );
            circularBuffer.Store( 8 );
            Console.WriteLine( "Storing 9" );
            circularBuffer.Store( 9 );
            Console.WriteLine( "Storing 10" );
            circularBuffer.Store( 10 );
            Console.WriteLine( "Storing 11" );
            circularBuffer.Store( 11 );
            Console.WriteLine( "Storing 12" );
            circularBuffer.Store( 12 );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.WriteLine( "Reading: {0}", circularBuffer.Read() );
            Console.ReadLine();
        }
Esempio n. 13
0
    private void Start()
    {
        _gameManager        = GameObject.Find("GameManager").GetComponent <GameManager>();
        _playerManager      = _gameManager.GetCurrentPlayerManager();
        _redirectionManager = _gameManager._redirectionManager;
        AcquireNewID();

        _appliedGainsTimeSample = new CircularBuffer.CircularBuffer <RecordedGainTypes>((int)(_samplesPerSecond * _gainRatioSampleWindowInSeconds));

        _gainIncrementer = GetComponent <GainIncrementer>();

        if (_experimentType == ExperimentType.effectiveness)
        {
            _experiment2Group = Randoms.Next(0, 2);
            Debug.Log("Experiment Group: " + (_experiment2Group == 0 ? "Control" : "Experimental"));
            _redirectionManager._switchToAC2FOnDistractor = _experiment2Group == 0 ? false : true;
            _redirectionManager.SubscribeToDistractorTriggerCallback(OnDistractorTrigger);
            _redirectionManager.SubscribeToResetTriggerCallback(OnResetTrigger);
            _redirectionManager.SubscribeToAlignmentCallback(OnAlignmentCallback);
            _redirectionManager.SubscribeToDistractorEndCallback(OnDistractorEnd);
        }
    }
Esempio n. 14
0
 public CircularStream(int bufferCapacity)
     : base()
 {
     buffer = new CircularBuffer <byte>(bufferCapacity);
 }
        public void CircularBuffer_GetEnumeratorOverflowedArray_Correctcontent()
        {
            var buffer = new CircularBuffer<int>(5);

            for (int i = 0; i < 10; i++)
            {
                buffer.PushBack(i);
            }

            // buffer should have [5,6,7,8,9]
            int x = 5;
            foreach (var item in buffer)
            {
                Assert.That(item, Is.EqualTo(x));
                x++;
            }
        }
        public void CircularBuffer_Front_CorrectItem()
        {
            var buffer = new CircularBuffer <int>(5, new[] { 0, 1, 2, 3, 4 });

            Assert.That(buffer.Front(), Is.EqualTo(0));
        }
        public void CircularBuffer_PushBack_CorrectContent()
        {
            var buffer = new CircularBuffer<int>(5);

            for (int i = 0; i < 5; i++)
            {
                buffer.PushBack(i);
            }

            Assert.That(buffer.Front(), Is.EqualTo(0));
            for (int i = 0; i < 5; i++)
            {
                Assert.That(buffer[i], Is.EqualTo(i));
            }
        }
 public void ToList()
 {
     try
     {
         CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(10);
         for (Int32 i = 0; i < 10; i++)
         {
             buffer.AddFirst(i);
         }
         List<Int32> bufferToList = buffer.ToList();
         if (bufferToList.Count == 0)
         {
             Assert.Fail();
         }
     }
     catch
     {
         Assert.Fail();
     }
 }
        public void CircularBuffer_ToArrayConstructorDefinedArray_Correctcontent()
        {
            var buffer = new CircularBuffer <int>(5, new[] { 0, 1, 2, 3 });

            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 1, 2, 3 }));
        }
Esempio n. 20
0
 public CircularStream(int length)
 {
     _circularBuffer = new CircularBuffer <byte>(length);
 }
        public void Enumerator()
        {
            try
            {
                CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(10);
                for (Int32 i = 0; i < 10; i++)
                {
                    buffer.AddFirst(i);
                }
                foreach (var item in buffer)
                {

                }
            }
            catch
            {
                Assert.Fail();
            }
        }
 public void CircularBuffer_Back_CorrectItem()
 {
     var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });
     Assert.That(buffer.Back(), Is.EqualTo(4));
 }
        public void CircularBuffer_PushFront_CorrectContent()
        {
            var buffer = new CircularBuffer<int>(5);

            for (int i = 0; i < 5; i++)
            {
                buffer.PushFront(i);
            }

            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 4, 3, 2, 1, 0 }));
        }
        public void CircularBuffer_PushFrontAndOverflow_CorrectContent()
        {
            var buffer = new CircularBuffer<int>(5);

            for (int i = 0; i < 10; i++)
            {
                buffer.PushFront(i);
            }

            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 9, 8, 7, 6, 5 }));
        }
 public void Index()
 {
     try
     {
         CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(10);
         for (Int32 i = 0; i < 10; i++)
         {
             buffer.AddFirst(i);
         }
         Int32 item = buffer[2];
         if (item != buffer[2])
         {
             Assert.Fail();
         }
     }
     catch
     {
         Assert.Fail();
     }
 }
        public void CircularBuffer_Back_CorrectItem()
        {
            var buffer = new CircularBuffer <int>(5, new[] { 0, 1, 2, 3, 4 });

            Assert.That(buffer.Back(), Is.EqualTo(4));
        }
 public void ToArray()
 {
     try
     {
         CircularBuffer<Int32> buffer = new CircularBuffer<Int32>(10);
         for (Int32 i = 0; i < 10; i++)
         {
             buffer.AddFirst(i);
         }
         Int32[] bufferToArray = buffer.ToArray();
         if (bufferToArray.Length == 0)
         {
             Assert.Fail();
         }
     }
     catch
     {
         Assert.Fail();
     }
 }
        public void CircularBuffer_Front_CorrectItem()
        {
            var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });

            Assert.That(buffer.Front(), Is.EqualTo(0));
        }
        public void CircularBuffer_SetIndex_ReplacesElement()
        {
            var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });

            buffer[1] = 10;
            buffer[3] = 30;

            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 10, 2, 30, 4 }));
        }
        public void CircularBuffer_PopFront_RemovesBackElement()
        {
            var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3, 4 });

            Assert.That(buffer.Size, Is.EqualTo(5));

            buffer.PopFront();

            Assert.That(buffer.Size, Is.EqualTo(4));
            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 4 }));
        }
        public void CircularBuffer_ToArrayConstructorDefinedArray_Correctcontent()
        {
            var buffer = new CircularBuffer<int>(5, new[] { 0, 1, 2, 3 });

            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 0, 1, 2, 3 }));
        }
        public void CircularBuffer_ToArrayOverflowedBuffer_Correctcontent()
        {
            var buffer = new CircularBuffer<int>(5);

            for (int i = 0; i < 10; i++)
            {
                buffer.PushBack(i);
            }

            Assert.That(buffer.ToArray(), Is.EqualTo(new[] { 5, 6, 7, 8, 9 }));
        }
Esempio n. 33
0
 public CircularStream(int bufferCapacity)
     : base()
 {
     buffer = new CircularBuffer<byte>(bufferCapacity);
 }
Esempio n. 34
0
        /// <summary>
        /// Test the ProduceAll and ConsumeAll methods of the circular buffer implementation.
        /// </summary>
        static void TestCircularBufferCollection()
        {
            ICircularBuffer <MyClass> buffer = new CircularBuffer <MyClass>(1000);

            TestProperties(buffer, 0);

            // fill collection with dummy values
            IList <MyInheritedClass> collection = new List <MyInheritedClass>();

            for (int i = 0; i < 800; ++i)
            {
                collection.Add(new MyInheritedClass(String.Format("{0}", i), i));
            }

            // test ProduceAll
            var produced = buffer.ProduceAll(collection);

            if (produced != 800)
            {
                throw new Exception(String.Format("produced {0} != {1}", produced, 800));
            }
            TestProperties(buffer, 800);

            produced = buffer.ProduceAll(collection);
            if (produced != 200)
            {
                throw new Exception(String.Format("produced {0} != {1}", produced, 200));
            }
            TestProperties(buffer, 1000);

            // test ConsumeAll
            uint consumed = 0;

            buffer.ConsumeAll(item => {
                if (!(item is MyInheritedClass))
                {
                    throw new Exception(String.Format("type {0} instead of {1} expected", typeof(MyInheritedClass).Name, item.GetType().Name));
                }
                if ((item as MyInheritedClass).newValue != (consumed % 800))
                {
                    throw new Exception(String.Format("newValue {0} != {1}", (item as MyInheritedClass).newValue, consumed % 800));
                }
                consumed += 1;
            });
            if (consumed != 1000)
            {
                throw new Exception(String.Format("consumed {0} != {1}", consumed, 1000));
            }
            TestProperties(buffer, 0);

            // test if Produce inside of ConsumeAll works
            produced = buffer.ProduceAll(collection);
            if (produced != 800)
            {
                throw new Exception(String.Format("produced {0} != {1}", produced, 800));
            }
            TestProperties(buffer, 800);

            consumed = 0;
            buffer.ConsumeAll(item => {
                if (!(item is MyInheritedClass))
                {
                    throw new Exception(String.Format("type {0} instead of {1} expected", typeof(MyInheritedClass).Name, item.GetType().Name));
                }
                if ((item as MyInheritedClass).newValue != (consumed % 800))
                {
                    throw new Exception(String.Format("newValue {0} != {1}", (item as MyInheritedClass).newValue, consumed % 800));
                }
                consumed += 1;
                if (consumed <= 2000)
                {
                    buffer.Produce(item);
                }
            });
            if (consumed != 2800)
            {
                throw new Exception(String.Format("consumed {0} != {1}", consumed, 2800));
            }
            TestProperties(buffer, 0);
        }