public void ReadMoreLinesThanCapacity()
 {
     arrayStringBuffer = new CircularArray(5);
     AddLines(20);
     Assert.AreEqual(CircularArrayTestResources.ForwardLastFive, arrayStringBuffer.ToString(EnumeratorDirection.Forward), "Wrong lines returned when overfilling array");
     Assert.AreEqual(CircularArrayTestResources.BackwardLastFive, arrayStringBuffer.ToString(EnumeratorDirection.Backward), "Wrong lines returned when overfilling array");
 }
 void CheckIndexer <T>(CircularArray <T> array, T[] compareArray)
 {
     for (int idx = 0; idx < array.Count; idx++)
     {
         Assert.Equal(compareArray[idx], array[idx]);
     }
 }
 public void ReadFewerLinesThanCapacity()
 {
     arrayStringBuffer = new CircularArray(30);
     AddLines(20);
     Assert.AreEqual(CircularArrayTestResources.BackwardThirty, arrayStringBuffer.ToString(EnumeratorDirection.Backward), "Wrong lines returned when underfilling array");
     Assert.AreEqual(CircularArrayTestResources.ForwardThirty, arrayStringBuffer.ToString(EnumeratorDirection.Forward), "Wrong lines returned when underfilling array");
 }
        public void SampleTest()
        {
            //creating a PianoWire
            PianoWire pw = new PianoWire(5, 25);

            //calling strike() method
            pw.Strike();

            //storing the initial values of the array
            CircularArray buffer = pw.getWires();

            double[] beforeSample = buffer.getValues();

            double decay = 3;

            //adding new value to queue
            pw.Sample(decay);

            //Storing the new value of the array
            CircularArray buffer2 = pw.getWires();

            double[] afterSample = buffer2.getValues();

            double value = ((beforeSample[0] + beforeSample[1]) / 2) * decay;

            Assert.AreEqual(value, afterSample[0]);
        }
Exemple #5
0
        /// <summary>
        /// Initializes the instance of the object.
        /// </summary>
        /// <param name="capacity">Maximal number of hashes we can store.</param>
        public InvalidBlockHashStore(IDateTimeProvider dateTimeProvider, int capacity = DefaultCapacity)
        {
            this.dateTimeProvider = dateTimeProvider;

            this.invalidBlockHashesExpirations = new Dictionary <uint256, DateTime?>(capacity);
            this.orderedHashList = new CircularArray <uint256>(capacity);
        }
        public void CircularArrayConstructorTestHelper <K, V>()
        {
            CircularArray <K, V> target = new CircularArray <K, V>();

            Assert.IsFalse(target.HasNext);
            Assert.IsTrue(target.MapInProgress);
        }
Exemple #7
0
 private void Start()
 {
     _charactersCircularArray = new CircularArray <Character>(_characters);
     print("PlayerID: " + _playerID);
     _player = Players.GetPlayer(_playerID);
     print("Fetched PlayerID: " + _player.playerID);
 }
Exemple #8
0
        private void Reduce <TNk, TNv, TRnv>(
            Reducer <TNk, TNv, TRnv> reducer,
            CircularArray <TNk, TNv> dictMap,
            IDictionary <TNk, TRnv> dictRed)
        {
            reducer.Parameters = this.Parameters;

            while (dictMap.MapInProgress || dictMap.HasNext)
            {
                while (PartialSaveInProgress) // a short save and we continue
                {
                    Thread.Sleep(100);
                }

                TNk key;
                TNv val;
                if (!dictMap.Pop(out key, out val))
                {
                    Thread.Sleep(1);
                    continue;
                }

                var pos = ((CustomDictionary <TNk, TRnv>)dictRed).InitOrGetPosition(key);

                var reducedValue = ((CustomDictionary <TNk, TRnv>)dictRed).GetAtPosition(pos);

                var newReducedValue = reducer.Reduce(key, val, reducedValue);

                ((CustomDictionary <TNk, TRnv>)dictRed).StoreAtPosition(pos, newReducedValue);
            }

            reducer.BeforeSave(dictRed);
        }
        public void WriteBeforeCurrentWindowHasNoEffectTest()
        {
            var a = new CircularArray <double>(5, double.NaN);

            a[0] = 1;
            Assert.AreEqual(1, a[0]);

            a[6] = 6;
            Assert.AreEqual(double.NaN, a[0]);
            Assert.AreEqual(6, a[6]);

            a[0] = 0;
            a[1] = 1;
            a[2] = 2;
            a[3] = 3;
            a[4] = 4;
            a[5] = 5;

            Assert.AreEqual(double.NaN, a[0]);
            Assert.AreEqual(double.NaN, a[1]);
            Assert.AreEqual(2, a[2]);
            Assert.AreEqual(3, a[3]);
            Assert.AreEqual(4, a[4]);
            Assert.AreEqual(5, a[5]);
        }
        public void ReadBeyondWindowDoesNotTouchContent()
        {
            var a = new CircularArray <double>(5, double.NaN);

            a[6] = 6;

            a[0] = 0;
            a[1] = 1;
            a[2] = 2;
            a[3] = 3;
            a[4] = 4;
            a[5] = 5;

            Assert.AreEqual(double.NaN, a[0]);
            Assert.AreEqual(double.NaN, a[1]);
            Assert.AreEqual(2, a[2]);
            Assert.AreEqual(3, a[3]);
            Assert.AreEqual(4, a[4]);
            Assert.AreEqual(5, a[5]);
            Assert.AreEqual(6, a[6]);

            Assert.AreEqual(double.NaN, a[12]);

            Assert.AreEqual(double.NaN, a[0]);
            Assert.AreEqual(double.NaN, a[1]);
            Assert.AreEqual(2, a[2]);
            Assert.AreEqual(3, a[3]);
            Assert.AreEqual(4, a[4]);
            Assert.AreEqual(5, a[5]);
            Assert.AreEqual(6, a[6]);
        }
        static void Main(string[] args)
        {
            CircularArray <int> circularArray = new CircularArray <int>();

            // Start from here to use circularArray
            // Test test = new Test
            // {
            //     Id = 1,
            //     Name = "Test1"
            // };
            // Test test1 = new Test
            // {
            //     Id = 2,
            //     Name = "Test2"
            // };
            // Test test2 = new Test
            // {
            //     Id = 3,
            //     Name = "Test3"
            // };

            circularArray.AddRange(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

            System.Console.WriteLine(circularArray[200]);
            circularArray.RemoveItem(200);
            circularArray.JugglingRotate(3);

            foreach (int item in circularArray)
            {
                System.Console.Write(item + " ");
            }
        }
Exemple #12
0
        static void Main(string[] args)
        {
            CircularArray testCirc = new CircularArray(5);

            testCirc.add("one");
            Console.WriteLine("cap" + testCirc.getCapacity());
            Console.WriteLine("size" + testCirc.getSize());
            testCirc.add("two");
            Console.WriteLine("cap" + testCirc.getCapacity());
            Console.WriteLine("size" + testCirc.getSize());

            testCirc.add("three");
            Console.WriteLine(testCirc.get(1));
            Console.WriteLine("cap" + testCirc.getCapacity());
            Console.WriteLine("s" + testCirc.getSize());
            Console.WriteLine("2 " + testCirc.get(2));
            Console.WriteLine("3 " + testCirc.get(3));
            Console.WriteLine("s" + testCirc.getSize());
            testCirc.add("four");
            testCirc.add("five");
            testCirc.add("six");
            testCirc.add("seven");
            Console.WriteLine("1 " + testCirc.get(1));
            Console.WriteLine("2 " + testCirc.get(2));
            Console.WriteLine("3 " + testCirc.get(3));
            testCirc.add("eight");
            Console.WriteLine("ioOne " + testCirc.indexOf("one"));
            Console.WriteLine(testCirc.indexOf("eight"));

            Console.WriteLine(testCirc.get(1));
            Console.ReadLine();
        }
        public void MovingForwardWithGapLeavesCleanGap()
        {
            var a = new CircularArray <double>(5, double.NaN);

            a[6] = 6;

            a[0] = 0;
            a[1] = 1;
            a[2] = 2;
            a[3] = 3;
            a[4] = 4;
            a[5] = 5;

            Assert.AreEqual(double.NaN, a[0]);
            Assert.AreEqual(double.NaN, a[1]);
            Assert.AreEqual(2, a[2]);
            Assert.AreEqual(3, a[3]);
            Assert.AreEqual(4, a[4]);
            Assert.AreEqual(5, a[5]);

            a[9] = 9;

            Assert.AreEqual(double.NaN, a[3]);
            Assert.AreEqual(double.NaN, a[4]);
            Assert.AreEqual(5, a[5]);
            Assert.AreEqual(6, a[6]);
            Assert.AreEqual(double.NaN, a[7]);
            Assert.AreEqual(double.NaN, a[8]);
        }
        public void CircularArrayTest()
        {
            CircularArray <int> intCircularArray = new CircularArray <int>(5);

            intCircularArray[0] = 0;
            intCircularArray[1] = 1;
            intCircularArray[2] = 2;
            intCircularArray[3] = 3;
            intCircularArray[4] = 4;

            intCircularArray.shift(2);

            foreach (int i in intCircularArray)
            {
                Trace.Write(string.Format("{0} ", i));
            }

            Assert.AreEqual(0, intCircularArray[2]);
            Trace.WriteLine("");

            intCircularArray.shift(13);

            foreach (int i in intCircularArray)
            {
                Trace.Write(string.Format("{0} ", i));
            }

            Trace.WriteLine("");
        }
Exemple #15
0
        public static void Test()
        {
            CircularArray <string> ca = new CircularArray <string>(10);

            for (int i = 0; i < 10; ++i)
            {
                ca.set(i, i.ToString());
            }

            ca.rotate(3);

            ca.rotate(2);

            Console.Write("Circular array: ");
            for (int i = 0; i < 10; ++i)
            {
                Console.Write(ca.get(i) + ",");
            }
            Console.WriteLine("\n");

            Console.Write("Printing Iterator: ");

            foreach (string s in ca)
            {
                Console.Write(s + ",");
            }
            Console.WriteLine("\n");
        }
        private void Reduce <NK, NV, RNV>(Reducer <NK, NV, RNV> reducer, CircularArray <NK, NV> dictMap, IDictionary <NK, RNV> dictRed)
        {
            reducer.Parameters = this.Parameters;
            NK key;
            NV val;

            //int reduceTooFastCount = 0;

            while (dictMap.MapInProgress || dictMap.HasNext)
            {
                while (PartialSaveInProgress) // a short save and we continue
                {
                    Thread.Sleep(100);
                }

                if (!dictMap.Pop(out key, out val))
                {
                    Thread.Sleep(1);
                    continue;
                }

                int pos = ((CustomDictionary <NK, RNV>)dictRed).InitOrGetPosition(key);

                RNV reducedValue = ((CustomDictionary <NK, RNV>)dictRed).GetAtPosition(pos);

                RNV newReducedValue = reducer.Reduce(key, val, reducedValue);
                ((CustomDictionary <NK, RNV>)dictRed).StoreAtPosition(pos, newReducedValue);
            }

            reducer.BeforeSave(dictRed);
        }
Exemple #17
0
 private Printer(PrinterProfile profile, SpoolerClient client)
 {
     this.client             = client;
     mylockID                = Guid.Empty;
     m_printer_profile.Value = profile;
     thread_sync             = new object();
     spool_lock              = new object();
     spool_up_to_date        = false;
     incoming_data           = null;
     Found = new ThreadSafeVariable <bool>
     {
         Value = false
     };
     _connected = new ThreadSafeVariable <bool>
     {
         Value = false
     };
     log                       = new CircularArray <string>(200);
     LogWaits                  = true;
     LogFeedback               = true;
     waiting_object            = null;
     waiting_object_lock       = new object();
     lockstatus                = new ThreadSafeVariable <PrinterLockStatus>(PrinterLockStatus.Unlocked);
     lockstepmode              = new ThreadSafeVariable <bool>(true);
     lockTimeOutSeconds        = new ThreadSafeVariable <int>(0);
     keeplockalive_clock       = new Stopwatch();
     keeplockalive_limit_clock = new Stopwatch();
     finished_lock             = new object();
     m_ChangedKeyValuePairs    = new ConcurrentDictionary <string, string>();
 }
Exemple #18
0
 internal Info(CircularArray array)
 {
     average   = array.Average;
     highest   = array.Highest;
     lowest    = array.Lowest;
     p_average = p_highest = p_lowest = 1;
 }
        public void IndexerAssignent_OutOfRange()
        {
            var array = new CircularArray <string>(3);

            Assert.Throws <IndexOutOfRangeException>(() => array[-1] = "can't assign this");
            Assert.Throws <IndexOutOfRangeException>(() => array[3]  = "can't assign this");
        }
Exemple #20
0
        public void Should_Check_Clone()
        {
            //arrange
            int capacity = 5;
            var array    = new CircularArray <int>(capacity);

            int[] values = { 5, 3, -3, 4, 1 };
            for (int i = 0; i < values.Length; i++)
            {
                array[i] = values[i];
            }
            array.Rotate(2);

            int[] resultValues = new[] { -3, 4, 1, 5, 3 };

            //act
            var clone  = array.Clone();
            var result = new List <int>();

            foreach (var item in clone)
            {
                result.Add(item);
            }

            //assert
            result.SequenceEqual(resultValues).ShouldBeEquivalentTo(true);
            result.Count.ShouldBeEquivalentTo(resultValues.Length);
            clone.Capacity.ShouldBeEquivalentTo(array.Capacity);
            clone.Count.ShouldBeEquivalentTo(array.Count);

            clone.ShouldBeEquivalentTo(array);
            clone.Equals(array).ShouldBeEquivalentTo(false);
        }
Exemple #21
0
        public void HintLinesSketch()
        {
            var ctx = Context.Current;

            var sketch = TestSketchGenerator.CreateSketch(createBody: true);

            var array = CircularArray.Create(sketch.Body);

            array.Quantity      = 4;
            array.Radius        = 50;
            array.OriginalAngle = 20;
            array.Range         = 220;
            array.Alignment     = CircularArray.AlignmentMode.Center;
            Assume.That(array.Make(Shape.MakeFlags.None));

            ctx.ViewportController.ZoomFitAll();
            ctx.WorkspaceController.Selection.SelectEntity(array.Body);
            var editor = Editor.CreateEditor(array);

            editor.Start();

            Assert.Multiple(() =>
            {
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "HintLinesSketch"));

                // Cleanup
                editor.Stop();
                AssertHelper.IsSameViewport(Path.Combine(_BasePath, "HintLinesSketch_Clean"));
            });
        }
 public void ReadFiveLines()
 {
     arrayStringBuffer = new CircularArray(5);
     AddLines(5);
     Assert.AreEqual(CircularArrayTestResources.ForwardFive, arrayStringBuffer.ToString(EnumeratorDirection.Forward), "Wrong lines returned when filling array");
     Assert.AreEqual(CircularArrayTestResources.BackwardFive, arrayStringBuffer.ToString(EnumeratorDirection.Backward), "Wrong lines returned");
 }
        public void EnumerationOrderWithLessThanCapacityItemsIsCorrect()
        {
            int[] array = new int[] { 7, 5, 6 };
            CircularArray <int> carray = new CircularArray <int>(5, false);

            // Add all items from normal array to circular array.
            for (int i = 0; i < array.Length; i++)
            {
                carray.Add(array[i], out int oldItem);
            }

            // Create a new array from enumeration over circular array.
            int index = 0;

            int[] arrayCopy = new int[array.Length];
            foreach (int item in carray)
            {
                arrayCopy[index++] = item;
            }

            // Check that each item from the enumeration was in correct order.
            for (int i = 0; i < array.Length; i++)
            {
                Assert.Equal(array[i], arrayCopy[i]);
            }
        }
Exemple #24
0
        public void Should_Check_Rotate_Full_Length_Negative()
        {
            //arrange
            int capacity = 5;
            var array    = new CircularArray <int>(capacity);

            int[] values = { 5, 3, -3, 4, 1 };
            for (int i = 0; i < values.Length; i++)
            {
                array[i] = values[i];
            }

            //act
            array.Rotate(-values.Length);
            var result = new List <int>();

            foreach (var item in array)
            {
                result.Add(item);
            }

            //assert
            result.SequenceEqual(values).ShouldBeEquivalentTo(true);
            result.Count.ShouldBeEquivalentTo(values.Length);
        }
        public void DelayedWriteCountTest()
        {
            CircularArray <string, string> target = new CircularArray <string, string>();

            new Thread(new ParameterizedThreadStart(DelayedWriteCountTestHelper)).Start(target);
            Thread.Sleep(300);
            Assert.AreNotEqual(0, target.DelayedWriteCount);
        }
            public void Sets_MaximumSize_To_Provided_Value_And_Start_With_Length_Zero()
            {
                // act
                var circularArray = new CircularArray <string>(10);

                Assert.Equal(10, circularArray.MaximumSize);
                Assert.Equal(0, circularArray.Length);
            }
        public void EmptyArrayAlwaysReturnsNoElementTest()
        {
            var a = new CircularArray <double>(5, double.NaN);

            Assert.AreEqual(double.NaN, a[0]);
            Assert.AreEqual(double.NaN, a[4]);
            Assert.AreEqual(double.NaN, a[500]);
        }
        public void RemoveAt()
        {
            var compareArray = new [] { "one", "three", "four", null };
            var array        = new CircularArray <string>(new [] { "one", "two", "three", "four" });

            array.RemoveAt(1);
            TestRead(array, compareArray);
        }
Exemple #29
0
        public void Constructor()
        {
            var a = new CircularArray <int>(13);

            Assert.AreEqual(13, a.Array.Length);
            Assert.AreEqual(0, a.Size);
            Assert.AreEqual(0, a.Head);
        }
Exemple #30
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="maxSampleCount">Maximal number of samples we calculate statistics from.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the puller.</param>
        public QualityScore(int maxSampleCount, ILoggerFactory loggerFactory)
        {
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.samples = new CircularArray <PeerSample>(maxSampleCount);

            this.AverageBlockTimePerKb = 0.0;
            this.peerReferenceCounter  = new Dictionary <IBlockPullerBehavior, int>();
        }
Exemple #31
0
 /// <summary>
 /// Constructs a new screen manager component.
 /// </summary>
 public ScreenManager(Game game)
     : base(game)
 {
     GameLevelsArray = new CircularArray <GameLevels>((GameLevels[])Enum.GetValues(typeof(GameLevels)));
     GameLevelsArray.MoveNext();
     ComputerColorArray =
         new CircularArray <FigureColors?>(new FigureColors?[] { FigureColors.Black, null, FigureColors.White });
     ComputerColorArray.MoveNext();
 }
Exemple #32
0
 public static void testCircularArray()
 {
   CircularArray<String> cArray = new CircularArray<String>(0);
   cArray.Add("A");
   cArray.Add("B");
   cArray.Add("C");
   cArray.Add("D");
   cArray.Add("E");
   cArray.Add("F");
   cArray.Add("G");
   cArray.Add("H");
   cArray.Add("I");
   Console.WriteLine(cArray.ToString());
 }
		void Awake ()
		{
			if (!_instance) {
				_instance = this;
			}

			if (maxParticleCount <= 0) {
				Debug.LogError ("maxParticleCount must be greater than zero");
			}

			_particleArray = new CircularArray<CustomParticle> (maxParticleCount);
			
			for (int i = 0; i < _particleArray.Capacity; i++) {
				var particle = Instantiate (particlePrefab);
				particle.transform.SetParent (transform);
				particle.SetActive (false);
				_particleArray [i] = particle.GetComponent<CustomParticle> ();
			}

			CustomParticle.UpdateEffectorList ();
		}
Exemple #34
0
 /// <summary>
 /// Resets the statistics.
 /// </summary>
 public void Reset()
 {
     _swapped = new CircularArray<int>(2);
     Writes = Compares = 0;
     Milliseconds = 0L;
     SortedTo = 0;
 }
 protected LetterTranslatorBase(string[] letters)
 {
     _array = new CircularArray<string>(letters);
 }
 public CaesarCipher()
 {
     _letterArray = new CircularArray<string>(Alphabet.LettersLowerCase);
 }