public void ToFractonialInchRepresentation()
        {
            var units = new UnitsManager();

            var length = new Dynamo.Units.Length(0.03175, units); //1.25"

            Assert.AreEqual("1 1/4\"", length.ToString(DynamoLengthUnit.FractionalInch));

            length.Value = -0.03175;
            Assert.AreEqual("-1 1/4\"", length.ToString(DynamoLengthUnit.FractionalInch));

            //test just the fractional case
            length.Value = 0.00635; //1/4"
            Assert.AreEqual("1/4\"", length.ToString(DynamoLengthUnit.FractionalInch));

            length.Value = -0.00635; //-1/4"
            Assert.AreEqual("-1/4\"", length.ToString(DynamoLengthUnit.FractionalInch));

            //test just the whole case
            length.Value = 0.0254; //1"
            Assert.AreEqual("1\"", length.ToString(DynamoLengthUnit.FractionalInch));

            length.Value = -0.0254;
            Assert.AreEqual("-1\"", length.ToString(DynamoLengthUnit.FractionalInch));

            //test some edge cases
            length.Value = 0.0;
            Assert.AreEqual("0\"", length.ToString(DynamoLengthUnit.FractionalInch));

            length.Value = 0.000396875; //1/64"
            Assert.AreEqual("1/64\"", length.ToString(DynamoLengthUnit.FractionalInch));

            length.Value = 0.025146; //.99"
            Assert.AreEqual("1\"", length.ToString(DynamoLengthUnit.FractionalInch));
        }
Exemple #2
0
        public static SIUnit Pow(Length input, double power)
        {
            if (power == 2)
            {
                return new Area(Math.Pow(input.Value, power));
            }
            else if (power == 3)
            {
                return new Volume(Math.Pow(input.Value, power));
            }

            throw new MathematicalArgumentException();
        }
Exemple #3
0
        public static SIUnit Pow(Length input, double power)
        {
            if (power == 2)
            {
                return new Area(Math.Pow(input.Value, power), dynSettings.Controller.UnitsManager);
            }
            else if (power == 3)
            {
                return new Volume(Math.Pow(input.Value, power), dynSettings.Controller.UnitsManager);
            }

            throw new MathematicalArgumentException();
        }
        public void SetLengthsFromString()
        {
            var units = new UnitsManager();

            //feet tests
            var length = new Dynamo.Units.Length(1.0, units);

            length.SetValueFromString("1' 3\"");
            Assert.AreEqual(0.381, length.Value, 0.001);

            length.SetValueFromString("1' 2\"");
            Assert.AreEqual(0.3556, length.Value, 0.001);

            length.SetValueFromString("30.48 cm");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("1 ft");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("12 in");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("1' 0\"");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("0.3 m");
            Assert.AreEqual(0.3, length.Value, 0.001);

            length.SetValueFromString("304.8 mm");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("1' 2 1/2\"");
            Assert.AreEqual(0.3683, length.Value, 0.001);

            length.SetValueFromString("14 1/2\"");
            Assert.AreEqual(0.3683, length.Value, 0.001);
        }
        public void UnitsNegatives()
        {
            var length = new Length(-2.0);
            var area = new Area(-2.0);
            var volume = new Volume(-2.0);

            Assert.AreEqual(-2.0, length.Value);
            Assert.AreEqual(-2.0, area.Value);
            Assert.AreEqual(-2.0, volume.Value);

            Assert.AreEqual(new Length(-2.0), new Length(10.0) - new Length(12.0));
            Assert.AreEqual(new Area(-2.0), new Area(10.0) - new Area(12.0));
            Assert.AreEqual(new Volume(-2.0), new Volume(10.0) - new Volume(12.0));
        }
        public void ToFractonialInchRepresentation()
        {
            var length = new Dynamo.Units.Length(0.03175); //1.25"

            SIUnit.LengthUnit = DynamoLengthUnit.FractionalInch;
            Assert.AreEqual("1 1/4\"", length.ToString());

            length.Value = -0.03175;
            Assert.AreEqual("-1 1/4\"", length.ToString());

            //test just the fractional case
            length.Value = 0.00635; //1/4"
            Assert.AreEqual("1/4\"", length.ToString());

            length.Value = -0.00635; //-1/4"
            Assert.AreEqual("-1/4\"", length.ToString());

            //test just the whole case
            length.Value = 0.0254; //1"
            Assert.AreEqual("1\"", length.ToString());

            length.Value = -0.0254;
            Assert.AreEqual("-1\"", length.ToString());

            //test some edge cases
            length.Value = 0.0;
            Assert.AreEqual("0\"", length.ToString());

            length.Value = 0.000396875; //1/64"
            Assert.AreEqual("1/64\"", length.ToString());

            length.Value = 0.025146; //.99"
            Assert.AreEqual("1\"", length.ToString());
        }
        public void Sorting()
        {
            //tests of units IComparability
            var l1 = new Length(-13.0);
            var l2 = new Length(27.0);
            var l3 = new Length(0.0);
            var l4 = new Length(.0000001);

            var lengths = new List<Length> {l4, l3, l1, l2};
            lengths.Sort();

            Assert.AreEqual(l1.Value, lengths[0].Value);
            Assert.AreEqual(l2.Value, lengths[3].Value);
            Assert.AreEqual(l3.Value, lengths[1].Value);
            Assert.AreEqual(l4.Value, lengths[2].Value);

            var a2 = new Area(27.0);
            var a3 = new Area(0.0);
            var a4 = new Area(.0000001);

            var areas = new List<Area> {a4, a3, a2};
            areas.Sort();

            Assert.AreEqual(a2.Value, areas[2].Value);
            Assert.AreEqual(a3.Value, areas[0].Value);
            Assert.AreEqual(a4.Value, areas[1].Value);

            var v2 = new Volume(27.0);
            var v3 = new Volume(0.0);
            var v4 = new Volume(.0000001);

            var volumes = new List<Volume> {v4, v3, v2};
            volumes.Sort();

            Assert.AreEqual(v2.Value, volumes[2].Value);
            Assert.AreEqual(v3.Value, volumes[0].Value);
            Assert.AreEqual(v4.Value, volumes[1].Value);

            //test that we're not comparing units
            //that can't be compared
            var mixedList = new List<SIUnit> {l2, a4, v4};
            Assert.Throws<InvalidOperationException>(mixedList.Sort);
        }
        public void SetLengthsFromString()
        {
            //feet tests
            var length = new Dynamo.Units.Length(1.0);

            length.SetValueFromString("1' 3\"");
            Assert.AreEqual(0.381, length.Value, 0.001);

            length.SetValueFromString("1' 2\"");
            Assert.AreEqual(0.3556, length.Value, 0.001);

            length.SetValueFromString("30.48 cm");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("1 ft");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("12 in");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("1' 0\"");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("0.3 m");
            Assert.AreEqual(0.3, length.Value, 0.001);

            length.SetValueFromString("304.8 mm");
            Assert.AreEqual(0.3048, length.Value, 0.001);

            length.SetValueFromString("1' 2 1/2\"");
            Assert.AreEqual(0.3683, length.Value, 0.001);

            length.SetValueFromString("14 1/2\"");
            Assert.AreEqual(0.3683, length.Value, 0.001);
        }
Exemple #9
0
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     SIUnit measure = null;
     if (parameter is Length)
     {
         measure = new Length(0.0, dynSettings.Controller.UnitsManager);
     }
     else if (parameter is Area)
     {
         measure = new Area(0.0, dynSettings.Controller.UnitsManager);
     }
     else if (parameter is Volume)
     {
         measure = new Volume(0.0, dynSettings.Controller.UnitsManager);
     }
     measure.SetValueFromString(value.ToString());
     return measure.Value;
 }
Exemple #10
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SIUnit measure = null;

            if (parameter is Length)
            {
                measure = new Length((double)value, dynSettings.Controller.UnitsManager);
            }
            else if (parameter is Area)
            {
                measure = new Area((double)value, dynSettings.Controller.UnitsManager);
            }
            else if (parameter is Volume)
            {
                measure = new Volume((double)value, dynSettings.Controller.UnitsManager);
            }
            return measure.ToString();
        }