public void AccessorTests() { DataPointObservation target = new DataPointObservation(); target.UtcTimestamp = new DateTime(2016, 6, 23, 19, 40, 59, DateTimeKind.Utc); Assert.AreEqual(new DateTime(2016, 6, 23, 19, 40, 59, DateTimeKind.Utc), target.UtcTimestamp); target.Value = 0.6; Assert.AreEqual(0.6, target.Value); }
public void EqualityTests() { DateTime dateTimeA = new DateTime(2016, 6, 23, 19, 45, 23); DateTime dateTimeB = new DateTime(2016, 6, 23, 19, 45, 24); double valueX = 0.3; double valueY = 0.4; DataPointObservation point1 = new DataPointObservation(); point1.UtcTimestamp = dateTimeA; point1.Value = valueX; DataPointObservation point2 = new DataPointObservation(); point2.UtcTimestamp = dateTimeA; point2.Value = valueX; DataPointObservation point3 = new DataPointObservation(); point3.UtcTimestamp = dateTimeA; point3.Value = valueY; DataPointObservation point4 = new DataPointObservation(); point4.UtcTimestamp = dateTimeB; point4.Value = valueX; Assert.IsTrue(point1 == point2); Assert.IsFalse(point1 == point3); Assert.IsFalse(point1 == point4); Assert.IsTrue(point1.GetHashCode() == point2.GetHashCode()); Assert.IsFalse(point1.GetHashCode() == point3.GetHashCode()); Assert.IsFalse(point1.GetHashCode() == point4.GetHashCode()); Assert.IsFalse(point1 != point2); Assert.IsTrue(point1 != point3); Assert.IsTrue(point1 != point4); Assert.IsTrue(point1.Equals(point2)); Assert.IsFalse(point1.Equals(point3)); Assert.IsFalse(point1.Equals(point4)); Assert.IsFalse(point1.Equals("A String object")); }
/// <summary> /// Generate predictable (based on test build) but seemingly random sample data for use in tests. /// </summary> /// <param name="seed"> /// Seed. A constant seed will produce consistent results. A small change in the seed used should produce massively /// different results.</param> /// <param name="sampleRawDataMaximumLength">Amount of data point observations. Can be zero.</param> /// <param name="sampleAggregatedDataMaximumLength">Amount of aggregated data points. Can be zero.</param> /// <param name="sampleRawData">Will be populated with sample raw data point observations.</param> /// <param name="sampleAggregatedData">Will be populated with aggregated data points.</param> /// <returns>Whether or not to consider the sample raw data a partial page.</returns> private static bool GenerateSampleData( int seed, int sampleRawDataMaximumLength, int sampleAggregatedDataMaximumLength, out DataPointObservation[] sampleRawData, out AggregatedDataPoint[] sampleAggregatedData) { Random psuedoRandomNumberGenerator = new Random(seed); int sampleRawDataLength = sampleRawDataMaximumLength == 0 ? 0 : psuedoRandomNumberGenerator.Next(1, sampleRawDataMaximumLength + 1); sampleRawData = new DataPointObservation[sampleRawDataLength]; for (int i = 0; i < sampleRawData.Length; i++) { sampleRawData[i] = new DataPointObservation(NewRandomDateTimeUtc(psuedoRandomNumberGenerator), value: psuedoRandomNumberGenerator.NextDouble()); } int sampleAggregatedDataLength = sampleAggregatedDataMaximumLength == 0 ? 0 : psuedoRandomNumberGenerator.Next(1, sampleAggregatedDataMaximumLength + 1); sampleAggregatedData = new AggregatedDataPoint[sampleAggregatedDataLength]; for (int i = 0; i < sampleAggregatedData.Length; i++) { sampleAggregatedData[i] = new AggregatedDataPoint(); sampleAggregatedData[i].UtcTimestamp = NewRandomDateTimeUtc(psuedoRandomNumberGenerator); sampleAggregatedData[i].AggregatedValue = psuedoRandomNumberGenerator.NextDouble(); } return psuedoRandomNumberGenerator.NextDouble() < 0.5; }