Пример #1
0
        public void TestRingArray()
        {
            RingArray <int> array = new RingArray <int>(10);

            Assert.IsTrue(array.Count == 0);

            array.Add(0);
            Assert.IsTrue(array.Count == 1);
            Assert.IsTrue(array[0] == 0);

            array.Add(1);
            Assert.IsTrue(array.Count == 2);
            Assert.IsTrue(array[0] == 0);
            Assert.IsTrue(array[1] == 1);

            for (int i = 2; i < 10; i++)
            {
                array.Add(i);
            }

            Assert.IsTrue(array.Count == 10);
            Assert.IsTrue(array[9] == 9);

            array.Add(10);
            Assert.IsTrue(array.Count == 10);
            Assert.IsTrue(array.IndexOf(9) == 8);
            Assert.IsTrue(array.IndexOf(10) == 9);
            Assert.IsTrue(array[9] == 10);
            Assert.IsTrue(array[0] == 1);

            array.Clear();
            (array.Count == 0).AssertIsTrue();
            for (int i = 0; i < 100; i++)
            {
                array.Add(i);
            }

            (array.Count == array.Capacity).AssertIsTrue();
            for (int i = 0; i < array.Capacity; i++)
            {
                (array[i] == i + 90).AssertIsTrue();
            }

            var enumerator = array.GetEnumerator();
            int count      = 0;

            while (enumerator.MoveNext())
            {
                (enumerator.Current == (count + 90)).AssertIsTrue();
                count++;
            }

            (count == 10).AssertIsTrue();
        }
Пример #2
0
		public void TestRingArray()
		{
			RingArray<int> array = new RingArray<int>(10);
			Assert.IsTrue(array.Count == 0);

			array.Add(0);
			Assert.IsTrue(array.Count == 1);
			Assert.IsTrue(array[0] == 0);

			array.Add(1);
			Assert.IsTrue(array.Count == 2);
			Assert.IsTrue(array[0] == 0);
			Assert.IsTrue(array[1] == 1);

			for (int i = 2; i < 10; i++)
			{
				array.Add(i);
			}

			Assert.IsTrue(array.Count == 10);
			Assert.IsTrue(array[9] == 9);

			array.Add(10);
			Assert.IsTrue(array.Count == 10);
			Assert.IsTrue(array.IndexOf(9) == 8);
			Assert.IsTrue(array.IndexOf(10) == 9);
			Assert.IsTrue(array[9] == 10);
			Assert.IsTrue(array[0] == 1);

			array.Clear();
			(array.Count == 0).AssertIsTrue();
			for (int i = 0; i < 100; i++)
			{
				array.Add(i);
			}

			(array.Count == array.Capacity).AssertIsTrue();
			for (int i = 0; i < array.Capacity; i++)
			{
				(array[i] == i + 90).AssertIsTrue();
			}

			var enumerator = array.GetEnumerator();
			int count = 0;
			while (enumerator.MoveNext())
			{
				(enumerator.Current == (count + 90)).AssertIsTrue();
				count++;
			}

			(count == 10).AssertIsTrue();
		}
Пример #3
0
        void OptionPricePlotView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            for (int i = 0; i < plotter.Children.Count; i++)
            {
                if (plotter.Children[i].GetType() == typeof(LineGraph))
                {
                    plotter.Children.RemoveAt(i);
                    i--;
                }
            }
            foreach (List <double> linePlot in PlotsItemsControl.Items)
            {
                RingArray <OptionPricePoint> pricePoints = new RingArray <OptionPricePoint>(linePlot.Count);
                for (int t = 0; t < linePlot.Count; t++)
                {
                    pricePoints.Add(new OptionPricePoint(t, linePlot[t]));
                }
                EnumerableDataSource <OptionPricePoint> linePlotData = new EnumerableDataSource <OptionPricePoint>(pricePoints);
                linePlotData.SetXMapping(x => x.Time);
                linePlotData.SetYMapping(y => y.Price);

                plotter.AddLineGraph(linePlotData);
            }
            plotter.LegendVisible = false;
        }
Пример #4
0
        public void TickEveryInGameHourServer(double nowTotalHours)
        {
            SnowAccumSnapshot latestSnap = new SnowAccumSnapshot()
            {
                TotalHours = nowTotalHours,
                // SumTemperatureByRegionCorner = new API.FloatDataMap3D(snowAccumResolution, snowAccumResolution, snowAccumResolution),
                SnowAccumulationByRegionCorner = new API.FloatDataMap3D(snowAccumResolution, snowAccumResolution, snowAccumResolution)
            };

            // Idea: We don't want to simulate 512x512 blocks at all times, thats a lot of iterations
            // lets try with just the 8 corner points of the region cuboid and lerp
            BlockPos tmpPos  = new BlockPos();
            int      regsize = ws.api.World.BlockAccessor.RegionSize;


            for (int ix = 0; ix < snowAccumResolution; ix++)
            {
                for (int iy = 0; iy < snowAccumResolution; iy++)
                {
                    for (int iz = 0; iz < snowAccumResolution; iz++)
                    {
                        int y = iy == 0 ? ws.api.World.SeaLevel : ws.api.World.BlockAccessor.MapSizeY - 1;

                        tmpPos.Set(
                            regionX * regsize + ix * (regsize - 1),
                            y,
                            regionZ * regsize + iz * (regsize - 1)
                            );

                        ClimateCondition nowcond = ws.api.World.BlockAccessor.GetClimateAt(tmpPos, EnumGetClimateMode.ForSuppliedDateValues, nowTotalHours + 0.5); // Sample from the middle of the hour
                        if (nowcond == null)
                        {
                            return;
                        }

                        //latestSnap.SumTemperatureByRegionCorner.AddValue(ix, iy, iz, nowcond.Temperature);

                        if (nowcond.Temperature > 0)
                        {
                            latestSnap.SnowAccumulationByRegionCorner.AddValue(ix, iy, iz, -nowcond.Temperature / 5f);
                        }
                        else
                        {
                            latestSnap.SnowAccumulationByRegionCorner.AddValue(ix, iy, iz, nowcond.Rainfall / 3f);
                        }
                    }
                }
            }

            lock (lockTest)
            {
                SnowAccumSnapshots.Add(latestSnap);
            }
            latestSnap.Checks++;
        }
Пример #5
0
 public void AddPoint(Point pnt)
 {
     _points.Add(pnt);
 }