Example #1
0
		/// <summary>
		/// Create a new SmartBuffer with values and times copied from another SmartBuffer
		/// </summary>
		/// <param name="smartBuffer">The SmartBuffer to copy</param>
        public SmartBuffer(SmartBuffer smartBuffer)
		{
			Create();

			if (smartBuffer.TimesCount > 0)
			{
				if (smartBuffer.GetTimeAt(0) is ITimeStamp && smartBuffer.GetValuesAt(0) is IScalarSet)
				{
					for (int i = 0; i < smartBuffer.TimesCount; i++)
					{
						AddValues(new TimeStamp((ITimeStamp) smartBuffer.GetTimeAt(i)),new ScalarSet((IScalarSet) smartBuffer.GetValuesAt(i)));
					}
				}

				if (smartBuffer.GetTimeAt(0) is ITimeStamp && smartBuffer.GetValuesAt(0) is IVectorSet)
				{
					for (int i = 0; i < smartBuffer.TimesCount; i++)
					{
						AddValues(new TimeStamp((ITimeStamp)smartBuffer.GetTimeAt(i)),new VectorSet((IVectorSet)smartBuffer.GetValuesAt(i)));
					}
				}

				if (smartBuffer.GetTimeAt(0) is ITimeSpan && smartBuffer.GetValuesAt(0) is IScalarSet)
				{
					for (int i = 0; i < smartBuffer.TimesCount; i++)
					{
						AddValues(new Backbone.TimeSpan((ITimeSpan)smartBuffer.GetTimeAt(i)),new ScalarSet((IScalarSet)smartBuffer.GetValuesAt(i)));
					}
				}

				if (smartBuffer.GetTimeAt(0) is ITimeSpan && smartBuffer.GetValuesAt(0) is IVectorSet)
				{
					for (int i = 0; i < smartBuffer.TimesCount; i++)
					{
						AddValues(new Backbone.TimeSpan((ITimeSpan)smartBuffer.GetTimeAt(i)),new VectorSet((IVectorSet)smartBuffer.GetValuesAt(i)));
					}
				}

				
			}

		}
		public void SmartBuffer()
		{
			// Testing the overloaded constructor SmartBuffer.SmartBuffer(SmartBuffer buffer)
			// Note: this test does not include testing for buffers containing VectorSets

			SmartBuffer smartBufferA = new SmartBuffer();
			smartBufferA.AddValues(new TimeStamp(1), new ScalarSet(new double[3] { 1, 2, 3 }));
			smartBufferA.AddValues(new TimeStamp(3), new ScalarSet(new double[3] { 3, 4, 5 }));
			smartBufferA.AddValues(new TimeStamp(6), new ScalarSet(new double[3] { 6, 7, 8 }));

			SmartBuffer buffer1 = new SmartBuffer(smartBufferA);
			Assert.AreEqual(smartBufferA.TimesCount, buffer1.TimesCount);
			for (int i = 0; i < smartBufferA.TimesCount; i++)
			{
				Assert.AreEqual(((ITimeStamp)smartBufferA.GetTimeAt(i)).ModifiedJulianDay, ((ITimeStamp)buffer1.GetTimeAt(i)).ModifiedJulianDay);
				for (int n = 0; n < smartBufferA.ValuesCount; n++)
				{
					Assert.AreEqual(((IScalarSet) smartBufferA.GetValuesAt(i)).GetScalar(n),((IScalarSet) buffer1.GetValuesAt(i)).GetScalar(n));
				}
			}

			SmartBuffer smartBufferB = new SmartBuffer();
			smartBufferB.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(1),new TimeStamp(2)), new ScalarSet(new double[3] { 11, 12, 13 }));
			smartBufferB.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(2),new TimeStamp(3)), new ScalarSet(new double[3] { 13, 14, 15 }));
			smartBufferB.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(3),new TimeStamp(5)), new ScalarSet(new double[3] { 16, 17, 18 }));

			SmartBuffer buffer2 = new SmartBuffer(smartBufferB);
			Assert.AreEqual(smartBufferB.TimesCount, buffer2.TimesCount);
			for (int i = 0; i < smartBufferB.TimesCount; i++)
			{
				Assert.AreEqual(((ITimeSpan)smartBufferB.GetTimeAt(i)).Start.ModifiedJulianDay, ((ITimeSpan)buffer2.GetTimeAt(i)).Start.ModifiedJulianDay);
				Assert.AreEqual(((ITimeSpan)smartBufferB.GetTimeAt(i)).End.ModifiedJulianDay, ((ITimeSpan)buffer2.GetTimeAt(i)).End.ModifiedJulianDay);

				for (int n = 0; n < smartBufferB.ValuesCount; n++)
				{
					Assert.AreEqual(((IScalarSet) smartBufferB.GetValuesAt(i)).GetScalar(n),((IScalarSet) buffer2.GetValuesAt(i)).GetScalar(n));
				}
			}
      	}
		public void ClearBefore()
		{
			SmartBuffer smartBuffer = new SmartBuffer();
			smartBuffer.AddValues(new TimeStamp(1), new ScalarSet(new double[3] {  1.1,  2.1,  3.1 }));
			smartBuffer.AddValues(new TimeStamp(3), new ScalarSet(new double[3] {  4.1,  5.1,  6.1 }));
			smartBuffer.AddValues(new TimeStamp(4), new ScalarSet(new double[3] {  7.1,  8.1,  9.1 }));
			smartBuffer.AddValues(new TimeStamp(5), new ScalarSet(new double[3] { 10.1, 11.1, 12.1 }));

			smartBuffer.ClearBefore(new TimeStamp(0.5));
			Assert.AreEqual(4,smartBuffer.TimesCount);
			smartBuffer.CheckBuffer();

			smartBuffer.ClearBefore(new TimeStamp(1));
			Assert.AreEqual(4,smartBuffer.TimesCount);
			smartBuffer.CheckBuffer();

			smartBuffer.ClearBefore(new TimeStamp(1.1));
			Assert.AreEqual(4,smartBuffer.TimesCount);
			Assert.AreEqual(1.1,((ScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(1, ((ITimeStamp) smartBuffer.GetTimeAt(0)).ModifiedJulianDay);
			smartBuffer.CheckBuffer();

			smartBuffer.ClearBefore(new TimeStamp(4.1));
			Assert.AreEqual(2, smartBuffer.TimesCount);
			Assert.AreEqual(7.1,((ScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(4, ((ITimeStamp) smartBuffer.GetTimeAt(0)).ModifiedJulianDay);
			smartBuffer.CheckBuffer();

			smartBuffer.ClearBefore(new TimeStamp(5.1));
			Assert.AreEqual(1, smartBuffer.TimesCount);
			Assert.AreEqual(10.1,((ScalarSet) smartBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(5, ((ITimeStamp) smartBuffer.GetTimeAt(0)).ModifiedJulianDay);
			smartBuffer.CheckBuffer();

			SmartBuffer timeSpanBuffer = new SmartBuffer();
			timeSpanBuffer.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(1),new TimeStamp(3)), new ScalarSet(new double[3] { 1.1,  2.1,   3.1 }));
			timeSpanBuffer.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(3),new TimeStamp(5)), new ScalarSet(new double[3] { 4.1,  5.1,   6.1 })); 
			timeSpanBuffer.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(5),new TimeStamp(7)), new ScalarSet(new double[3] { 7.1,  8.1,   9.1 })); 
			timeSpanBuffer.AddValues(new Oatc.OpenMI.Sdk.Backbone.TimeSpan(new TimeStamp(7),new TimeStamp(9)), new ScalarSet(new double[3] { 10.1, 11.1, 12.1 })); 
			
			timeSpanBuffer.ClearBefore(new TimeStamp(0.5));
			Assert.AreEqual(4,timeSpanBuffer.TimesCount);
			timeSpanBuffer.CheckBuffer();

			timeSpanBuffer.ClearBefore(new TimeStamp(1.0));
			Assert.AreEqual(4,timeSpanBuffer.TimesCount);
			timeSpanBuffer.CheckBuffer();

			timeSpanBuffer.ClearBefore(new TimeStamp(2.0));
			Assert.AreEqual(4,timeSpanBuffer.TimesCount);
			timeSpanBuffer.CheckBuffer();

			timeSpanBuffer.ClearBefore(new TimeStamp(3.0));
			Assert.AreEqual(4,timeSpanBuffer.TimesCount);
			timeSpanBuffer.CheckBuffer();

			timeSpanBuffer.ClearBefore(new TimeStamp(4.0));
			Assert.AreEqual(4,timeSpanBuffer.TimesCount);
			Assert.AreEqual(1.1,((ScalarSet) timeSpanBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(1, ((ITimeSpan) timeSpanBuffer.GetTimeAt(0)).Start.ModifiedJulianDay);
			Assert.AreEqual(3, ((ITimeSpan) timeSpanBuffer.GetTimeAt(0)).End.ModifiedJulianDay);
			timeSpanBuffer.CheckBuffer();

			timeSpanBuffer.ClearBefore(new TimeStamp(7.0));
			Assert.AreEqual(3,timeSpanBuffer.TimesCount);
			Assert.AreEqual(4.1,((ScalarSet) timeSpanBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(3, ((ITimeSpan) timeSpanBuffer.GetTimeAt(0)).Start.ModifiedJulianDay);
			Assert.AreEqual(5, ((ITimeSpan) timeSpanBuffer.GetTimeAt(0)).End.ModifiedJulianDay);
			timeSpanBuffer.CheckBuffer();

			timeSpanBuffer.ClearBefore(new TimeStamp(10.0));
			Assert.AreEqual(1,timeSpanBuffer.TimesCount);
			Assert.AreEqual(10.1,((ScalarSet) timeSpanBuffer.GetValuesAt(0)).GetScalar(0));
			Assert.AreEqual(7, ((ITimeSpan) timeSpanBuffer.GetTimeAt(0)).Start.ModifiedJulianDay);
			Assert.AreEqual(9, ((ITimeSpan) timeSpanBuffer.GetTimeAt(0)).End.ModifiedJulianDay);
			timeSpanBuffer.CheckBuffer();
		}