Esempio n. 1
0
        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));
        }
Esempio n. 2
0
 public AreaInput()
 {
     _measure = new Area(0.0);
     OutPortData.Add(new PortData("area", "The area. Stored internally as decimal meters squared.", typeof(FScheme.Value.Container)));
     RegisterAllPorts();
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void SetAreaFromString()
        {
            var area = new Area(1.0);

            area.SetValueFromString("1 mm²");
            Assert.AreEqual(1.0e-6 , area.Value, 0.001);

            area.SetValueFromString("1mm²");
            Assert.AreEqual(1.0e-6, area.Value, 0.001);

            area.SetValueFromString("1 mm2");
            Assert.AreEqual(1.0e-6, area.Value, 0.001);

            area.SetValueFromString("1 sqmm");
            Assert.AreEqual(1.0e-6, area.Value, 0.001);

            area.SetValueFromString("1 cm²");
            Assert.AreEqual(0.0001, area.Value, 0.001);

            area.SetValueFromString("1cm²");
            Assert.AreEqual(0.0001, area.Value, 0.001);

            area.SetValueFromString("1 cm2");
            Assert.AreEqual(0.0001, area.Value, 0.001);

            area.SetValueFromString("1 sqcm");
            Assert.AreEqual(0.0001, area.Value, 0.001);

            area.SetValueFromString("1 m²");
            Assert.AreEqual(1, area.Value, 0.001);

            area.SetValueFromString("1m²");
            Assert.AreEqual(1, area.Value, 0.001);

            area.SetValueFromString("1 m2");
            Assert.AreEqual(1, area.Value, 0.001);

            area.SetValueFromString("1 sqm");
            Assert.AreEqual(1, area.Value, 0.001);

            area.SetValueFromString("1 in²");
            Assert.AreEqual(0.00064516, area.Value, 0.001);

            area.SetValueFromString("1in²");
            Assert.AreEqual(0.00064516, area.Value, 0.001);

            area.SetValueFromString("1 in2");
            Assert.AreEqual(0.00064516, area.Value, 0.001);

            area.SetValueFromString("1 sqin");
            Assert.AreEqual(0.00064516, area.Value, 0.001);

            area.SetValueFromString("1 ft²");
            Assert.AreEqual(0.092903, area.Value, 0.001);

            area.SetValueFromString("1ft²");
            Assert.AreEqual(0.092903, area.Value, 0.001);

            area.SetValueFromString("1 ft2");
            Assert.AreEqual(0.092903, area.Value, 0.001);

            area.SetValueFromString("1 sqft");
            Assert.AreEqual(0.092903, area.Value, 0.001);
        }
Esempio n. 5
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;
 }
Esempio n. 6
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();
        }
Esempio n. 7
0
        public void UnitsNegatives()
        {
            //construction
            Assert.DoesNotThrow(() => { var test = new Units.Length(-2.0); });
            Assert.Throws<MathematicalArgumentException>(() => { var test = new Area(-2.0); });
            Assert.Throws<MathematicalArgumentException>(() => { var test = new Volume(-2.0); });

            var length = new Units.Length(2.0);
            var area = new Area(2.0);
            var volume = new Volume(2.0);

            Assert.Throws<MathematicalArgumentException>(() => { var test = new Area(10.0) - new Area(12.0); });
            Assert.Throws<MathematicalArgumentException>(() => { var test = new Volume(10.0) - new Volume(12.0); });
        }