/// <summary> /// Verify that the result of serializing and then deserializing /// an object is the same as the original. /// </summary> private void VerifyRoundtrip(Context context, LocalMinute value) { // To be used in assert message string nameAsString = value.AsString(); // Verify string serialization roundtrip string stringValue = value.AsString(); LocalMinute parsedStringValue = LocalMinuteUtil.Parse(stringValue); context.Log.Assert(value == parsedStringValue, $"String roundtrip for {nameAsString} assert."); // Verify int serialization roundtrip int intValue = value.ToIsoInt(); LocalMinute parsedIntValue = LocalMinuteUtil.FromIsoInt(intValue); context.Log.Assert(value == parsedIntValue, $"Int roundtrip for {nameAsString} assert."); }
/// <summary> /// Populate with values based on the specified array /// of value types, repeating the types in cycle. /// </summary> private void PopulateValues(VariantType[] valueTypes, VariantMatrix result) { // Initial values to populate the data int stringValueAsInt = 0; bool boolValue = false; int intValue = 0; long longValue = 0; double doubleValue = 0.5; LocalDate localDateValue = new LocalDate(2003, 5, 1); LocalTime localTimeValue = new LocalTime(10, 15, 30); LocalMinute localMinuteValue = new LocalMinute(10, 15); LocalDateTime localDateTimeValue = new LocalDateTime(2003, 5, 1, 10, 15, 0); Instant instantValue = new LocalDateTime(2003, 5, 1, 10, 15, 0).ToInstant(DateTimeZone.Utc); int valueTypeCount = valueTypes.Length; for (int rowIndex = 0; rowIndex < result.RowCount; rowIndex++) { for (int colIndex = 0; colIndex < result.ColCount; colIndex++) { // Repeat value types in cycle var valueType = valueTypes[colIndex % valueTypeCount]; switch (valueType) { case VariantType.String: result[rowIndex, colIndex] = $"Str{stringValueAsInt++}"; break; case VariantType.Double: result[rowIndex, colIndex] = doubleValue++; break; case VariantType.Bool: result[rowIndex, colIndex] = boolValue; boolValue = !boolValue; break; case VariantType.Int: result[rowIndex, colIndex] = intValue++; break; case VariantType.Long: result[rowIndex, colIndex] = longValue++; break; case VariantType.LocalDate: result[rowIndex, colIndex] = localDateValue; localDateValue = localDateValue.PlusDays(1); break; case VariantType.LocalTime: result[rowIndex, colIndex] = localTimeValue; localTimeValue = localTimeValue.PlusHours(1); break; case VariantType.LocalMinute: result[rowIndex, colIndex] = localMinuteValue; localMinuteValue = localMinuteValue.ToLocalTime().PlusHours(1).ToLocalMinute(); break; case VariantType.LocalDateTime: result[rowIndex, colIndex] = localDateTimeValue; localDateTimeValue = localDateTimeValue.PlusDays(2).PlusHours(2); break; case VariantType.Instant: result[rowIndex, colIndex] = instantValue; instantValue = instantValue; // TODO Fix, uses previous value break; default: throw new Exception($"Value type {valueType} cannot be stored in VariantMatrix."); } } } }