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));
        }
Beispiel #2
0
 public VolumeInput()
 {
     _measure = new Volume(0.0);
     OutPortData.Add(new PortData("volume", "The volume. Stored internally as decimal meters cubed.", typeof(FScheme.Value.Container)));
     RegisterAllPorts();
 }
        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 SetVolumeFromString()
        {
            var volume = new Volume(1.0);

            volume.SetValueFromString("1 mm³");
            Assert.AreEqual(1.0e-9, volume.Value, 0.001);

            volume.SetValueFromString("1mm³");
            Assert.AreEqual(1.0e-9, volume.Value, 0.001);

            volume.SetValueFromString("1 mm3");
            Assert.AreEqual(1.0e-9, volume.Value, 0.001);

            volume.SetValueFromString("1 cumm");
            Assert.AreEqual(1.0e-9, volume.Value, 0.001);

            volume.SetValueFromString("1 cm³");
            Assert.AreEqual(1.0e-6, volume.Value, 0.001);

            volume.SetValueFromString("1cm³");
            Assert.AreEqual(1.0e-6, volume.Value, 0.001);

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

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

            volume.SetValueFromString("1 m³");
            Assert.AreEqual(1, volume.Value, 0.001);

            volume.SetValueFromString("1m³");
            Assert.AreEqual(1, volume.Value, 0.001);

            volume.SetValueFromString("1 m3");
            Assert.AreEqual(1, volume.Value, 0.001);

            volume.SetValueFromString("1 cum");
            Assert.AreEqual(1, volume.Value, 0.001);

            volume.SetValueFromString("1 in³");
            Assert.AreEqual(1.6387e-5, volume.Value, 0.001);

            volume.SetValueFromString("1in³");
            Assert.AreEqual(1.6387e-5, volume.Value, 0.001);

            volume.SetValueFromString("1 in3");
            Assert.AreEqual(1.6387e-5, volume.Value, 0.001);

            volume.SetValueFromString("1 cuin");
            Assert.AreEqual(1.6387e-5, volume.Value, 0.001);

            volume.SetValueFromString("1 ft³");
            Assert.AreEqual(0.0283168, volume.Value, 0.001);

            volume.SetValueFromString("1ft³");
            Assert.AreEqual(0.0283168, volume.Value, 0.001);

            volume.SetValueFromString("1 ft3");
            Assert.AreEqual(0.0283168, volume.Value, 0.001);

            volume.SetValueFromString("1 cuft");
            Assert.AreEqual(0.0283168, volume.Value, 0.001);
        }
Beispiel #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;
 }
Beispiel #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();
        }
Beispiel #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); });
        }