public void Serialize(BallisticCoefficientValueType valueType)
        {
            var bc1 = new BallisticCoefficient(1.2345678, DragTableId.G7, valueType);
            var s   = JsonSerializer.Serialize(bc1);
            var bc2 = JsonSerializer.Deserialize <BallisticCoefficient>(s);

            bc2.ValueType.Should().Be(valueType);
            bc2.Value.Should().Be(1.2345678);
            bc2.Table.Should().Be(DragTableId.G7);
        }
        public void ToStringAndParse(double value, DragTableId tableId, BallisticCoefficientValueType valueType, string format, string expected, double expectedAccuracy)
        {
            var bc1 = new BallisticCoefficient(value, tableId, valueType);

            if (format != null)
            {
                bc1.ToString(format, CultureInfo.InvariantCulture).Should().Be(expected);
            }
            else
            {
                bc1.ToString(CultureInfo.InvariantCulture).Should().Be(expected);
            }

            BallisticCoefficient.TryParse(expected, out BallisticCoefficient bc2).Should().BeTrue();
            bc2.ValueType.Should().Be(valueType);
            bc2.Value.Should().BeApproximately(value, expectedAccuracy);
            bc2.Table.Should().Be(tableId);
        }
示例#3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="coefficient"></param>
 /// <param name="table"></param>
 /// <param name="valueType"></param>
 public BallisticCoefficient(double coefficient, DragTableId table, BallisticCoefficientValueType valueType)
 {
     ValueType = valueType;
     Value     = coefficient;
     Table     = table;
 }
示例#4
0
        private static bool TryParse(string text, CultureInfo cultureInfo, out double value, out DragTableId table, out BallisticCoefficientValueType valueType)
        {
            value     = 0;
            table     = DragTableId.G1;
            valueType = BallisticCoefficientValueType.Coefficient;

            if (text.Length < 3)
            {
                return(false);
            }

            if (text[0] == 'F')
            {
                text = text.Substring(1);
                if (text.Length < 3)
                {
                    return(false);
                }

                valueType = BallisticCoefficientValueType.FormFactor;
            }

            string tableName = text.Substring(text.Length - 2);

            if (!Enum.TryParse <DragTableId>(tableName, out table))
            {
                return(false);
            }
            string v = text.Substring(0, text.Length - 2);

            return(double.TryParse(v, NumberStyles.Float, cultureInfo, out value));
        }