Exemplo n.º 1
0
        public new static BaseMeasure Random()
        {
            var m = new BaseMeasure();

            m.SetRandomValues();
            return(m);
        }
Exemplo n.º 2
0
        public void MultiplySameMeasuresTest()
        {
            var m1 = new BaseMeasure("s");

            Measures.Instance.Add(m1);
            var m = m1.Multiply(m1);

            Assert.AreEqual("s^2", m.Formula());
        }
Exemplo n.º 3
0
        public void ReciprocalTest()
        {
            var m1 = new BaseMeasure("a");

            Measures.Instance.Add(m1);
            var m = m1.Reciprocal();

            Assert.AreEqual("a^-1", m.Formula());
        }
Exemplo n.º 4
0
        public Measure Multiply(BaseMeasure m, bool isDivide = false)
        {
            var t1 = new MeasureTerm(this, 1);
            var t2 = isDivide? new MeasureTerm(m, -1) : new MeasureTerm(m, 1);
            var t  = new MeasureTerms {
                t1, t2
            };

            return(new DerivedMeasure(t));
        }
Exemplo n.º 5
0
        public void MultiplyBaseWithDerivedTest()
        {
            var m1 = new BaseMeasure("v");

            Measures.Instance.Add(m1);
            var m  = m1.Multiply(m1);
            var m2 = m1.Multiply(m);

            Assert.AreEqual("v^3", m2.Formula());
        }
Exemplo n.º 6
0
        public void DivideTest()
        {
            var m1 = new BaseMeasure("a");
            var m2 = new BaseMeasure("b");

            Measures.Instance.Add(m1);
            Measures.Instance.Add(m2);
            var m = m1.Divide(m2);

            Assert.AreEqual("a^1*b^-1", m.Formula());
        }
Exemplo n.º 7
0
        [TestMethod] public void MultiplyTest()
        {
            var m1 = new BaseMeasure("v");
            var m2 = new BaseMeasure("t");

            Measures.Instance.Add(m1);
            Measures.Instance.Add(m2);
            var m = m1.Multiply(m2);

            Assert.AreEqual("v^1*t^1", m.Formula());
        }
Exemplo n.º 8
0
 public void CleanTests()
 {
     quantity1    = null;
     quantity2    = null;
     quantity3    = null;
     quantity4    = null;
     baseMeasure1 = null;
     baseMeasure2 = null;
     baseUnit1    = null;
     baseUnit2    = null;
     baseUnit3    = null;
 }
Exemplo n.º 9
0
        public void MultiplySameUnitsTest()
        {
            var m1 = new BaseMeasure("a");

            Measures.Instance.Add(m1);
            var u = new BaseUnit(m1, 1, "s", "pikkus");

            Units.Instance.Add(u);
            var m = u.Multiply(u);

            Assert.AreEqual("a^2", m.Measure.Name);
            Assert.AreEqual("s^2", m.Formula());
        }
Exemplo n.º 10
0
        public void ReciprocalTest()
        {
            var m1 = new BaseMeasure("a");

            Measures.Instance.Add(m1);
            var u = new BaseUnit(m1, 1, "s", "pikkus");

            Units.Instance.Add(u);
            var m = u.Reciprocal();

            Assert.AreEqual("s^-1", m.Formula());
            Assert.AreEqual("a^-1", m.Measure.Name);
        }
Exemplo n.º 11
0
        public void ExponentiationTest()
        {
            var m1 = new BaseMeasure("a");

            Measures.Instance.Add(m1);
            var m = m1.Exponentiation(5);
            var s = m1.Exponentiation(1);
            var c = m1.Exponentiation(0);
            var a = m1.Exponentiation(-5);

            Assert.AreEqual("a^5", m.Formula());
            Assert.AreEqual("a", s.Formula());
            Assert.AreEqual("a^-5", a.Formula());
        }
Exemplo n.º 12
0
 public void InitTests()
 {
     t  = new DerivedMeasure();
     m1 = new BaseMeasure("v");
     m2 = new BaseMeasure("t");
     m3 = new BaseMeasure("c");
     Measures.Instance.Add(m1);
     Measures.Instance.Add(m2);
     Measures.Instance.Add(m3);
     d1 = (DerivedMeasure)m1.Multiply(m2);
     d2 = (DerivedMeasure)m1.Multiply(m1);
     d3 = (DerivedMeasure)m3.Multiply(m3);
     d4 = (DerivedMeasure)m1.Multiply(m3);
 }
Exemplo n.º 13
0
 public void CleanTests()
 {
     t   = null;
     bm1 = null;
     bm2 = null;
     bm3 = null;
     m1  = null;
     m2  = null;
     m3  = null;
     d1  = null;
     d2  = null;
     d3  = null;
     d4  = null;
 }
Exemplo n.º 14
0
        public void MultiplyBaseWithDerivedTest()
        {
            var m1 = new BaseMeasure("v");

            Measures.Instance.Add(m1);
            var u = new BaseUnit(m1, 1, "s", "pikkus");

            Units.Instance.Add(u);
            var m  = u.Multiply(u);
            var m2 = u.Multiply(m);

            Assert.AreEqual("s^3", m2.Formula());
            Assert.AreEqual("v^3", m2.Measure.Name);
        }
Exemplo n.º 15
0
        public void MultiplyTest()
        {
            var m1 = new BaseMeasure("a");

            Measures.Instance.Add(m1);
            var u1 = new BaseUnit(m1, 1, "s", "pikkus");
            var u2 = new BaseUnit(m1, 1, "t", "aeg");

            Units.Instance.Add(u1);
            Units.Instance.Add(u2);
            var u = u1.Multiply(u2);

            Assert.AreEqual("s*t", u.Formula());
            Assert.AreEqual("pikkus*aeg", u.Formula(true));
            Assert.AreEqual("a^2", u.Measure.Name);
        }
Exemplo n.º 16
0
 public void InitTests()
 {
     baseMeasure1 = new BaseMeasure("pikkus");
     baseMeasure2 = new BaseMeasure("aeg");
     baseUnit1    = new BaseUnit(baseMeasure1, 1, "m", "meeter");
     baseUnit2    = new BaseUnit(baseMeasure2, 1, "s", "sekund");
     baseUnit3    = new BaseUnit(baseMeasure1, 1000, "km", "kilomeeter");
     Measures.Instance.Add(baseMeasure1);
     Measures.Instance.Add(baseMeasure2);
     Units.Instance.Add(baseUnit1);
     Units.Instance.Add(baseUnit2);
     Units.Instance.Add(baseUnit3);
     quantity1 = new Quantity(200, baseUnit1);
     quantity2 = new Quantity(300, baseUnit2);
     quantity3 = new Quantity(400, baseUnit3);
     quantity4 = new Quantity(213.4565, baseUnit3);
 }
Exemplo n.º 17
0
        public void ExponentationTest()
        {
            var m1 = new BaseMeasure("a");

            Measures.Instance.Add(m1);
            var u = new BaseUnit(m1, 1, "s", "pikkus");

            Units.Instance.Add(u);
            var m = u.Exponentiation(4);
            var s = u.Exponentiation(1);
            var c = u.Exponentiation(0);
            var a = u.Exponentiation(-4);

            Assert.AreEqual("a^4", m.Measure.Name);
            Assert.AreEqual("s^4", m.Formula());
            Assert.AreEqual("s", s.Formula());
            Assert.AreEqual("s^-4", a.Formula());
        }
Exemplo n.º 18
0
        public void DivideTest()
        {
            var m1 = new BaseMeasure("a");
            var m2 = new BaseMeasure("b");

            Measures.Instance.Add(m1);
            Measures.Instance.Add(m2);
            var u1 = new BaseUnit(m1, 1, "s", "pikkus");
            var u2 = new BaseUnit(m2, 1, "t", "aeg");

            Units.Instance.Add(u1);
            Units.Instance.Add(u2);
            var u = u1.Divide(u2);

            Assert.AreEqual("s*t^-1", u.Formula());
            Assert.AreEqual("a^1*b^-1", u.Measure.Name);
            Assert.AreEqual("pikkus*aeg^-1", u.Formula(true));
        }
Exemplo n.º 19
0
        public ActionResult Result(MathViewModel quantity)
        {
            var m = BaseMeasure.Random();

            Measures.Instance.Add(m);
            var u1 = new BaseUnit(m, Unit.SetFactor(quantity.QuantityList[0].Unit), quantity.QuantityList[0].Unit, quantity.QuantityList[0].Unit);

            Units.Instance.Add(u1);
            var      q1 = new Quantity(quantity.QuantityList[0].Amount, u1);
            Quantity q2 = new Quantity();

            if (quantity.QuantityList[1].Unit != string.Empty)
            {
                var u2 = new BaseUnit(m, Unit.SetFactor(quantity.QuantityList[1].Unit), quantity.QuantityList[1].Unit, quantity.QuantityList[1].Unit);
                Units.Instance.Add(u2);
                q2 = new Quantity(quantity.QuantityList[1].Amount, u2);
            }
            quantity = SetResult(quantity, q1, q2);
            return(View("Index", quantity));
        }
Exemplo n.º 20
0
 public void InitTests()
 {
     t   = new DerivedUnit();
     bm1 = new BaseMeasure("pk");
     bm2 = new BaseMeasure("ae");
     bm3 = new BaseMeasure("mi");
     Measures.Instance.Add(bm1);
     Measures.Instance.Add(bm2);
     Measures.Instance.Add(bm3);
     m1 = new BaseUnit(bm1, 1, "s", "pikkus");
     m2 = new BaseUnit(bm2, 1, "t", "aeg");
     m3 = new BaseUnit(bm3, 1, "k", "midagi");
     Units.Instance.Add(m1);
     Units.Instance.Add(m2);
     Units.Instance.Add(m3);
     d1 = (DerivedUnit)m1.Multiply(m2); //s1*t1
     d2 = (DerivedUnit)m1.Multiply(m3); //s1*k1
     d3 = (DerivedUnit)m2.Multiply(m3); //t1*k1
     d4 = (DerivedUnit)m3.Multiply(m3); //k2
 }
Exemplo n.º 21
0
        public ActionResult Result(ComplexMathViewModel quantity)
        {
            var q1          = quantity.FirstQuantity;
            var q2          = quantity.SecondQuantity;
            var baseMeasure = BaseMeasure.Random();

            Measures.Instance.Add(baseMeasure);
            var derivedMeasure = DerivedMeasure.Random();

            Measures.Instance.Add(derivedMeasure);
            int i = 0;
            List <DerivedUnit> derivedUnits = new List <DerivedUnit>();

            foreach (string str in quantity.UnitList)
            {
                var baseUnit = new BaseUnit(baseMeasure, Unit.SetFactor(str), str, str);
                Units.Instance.Add(baseUnit);
                var derivedUnit = baseUnit.Exponentiation(quantity.PowerList[i]) as DerivedUnit;
                derivedUnit.Measure = derivedMeasure;
                Units.Instance.Add(derivedUnit);
                derivedUnits.Add(derivedUnit);
                i++;
                if (i == quantity.NumberOfUnits)
                {
                    break;
                }
            }
            for (int j = 0; j < quantity.NumberOfUnits - 1; j++)
            {
                var a = derivedUnits[j].Multiply(derivedUnits[j + 1]) as DerivedUnit;
                Units.Instance.Add(a);
                derivedUnits[j + 1] = a;
                if (j == quantity.NumberOfUnits - 2)
                {
                    q1.Unit = a.Name;
                    q2.Unit = a.Name;
                }
            }
            quantity = SetResults(quantity, q1, q2);
            return(View("Index", quantity));
        }
Exemplo n.º 22
0
 public MeasureTerm(BaseMeasure m, int power = 0)
 {
     this.measure = m ?? new BaseMeasure();
     this.power   = power;
 }
Exemplo n.º 23
0
        public ActionResult Result(FormulaeViewModel formulae)
        {
            DerivedMeasure derivedMeasure;
            var            m1 = new BaseMeasure(formulae.MeasureList[0]);
            var            m2 = new BaseMeasure(formulae.MeasureList[1]);

            Measures.Instance.Add(m1);
            Measures.Instance.Add(m2);

            if (formulae.SelectedOperation == "Divide")
            {
                derivedMeasure = m1.Divide(m2) as DerivedMeasure;
            }
            else
            {
                derivedMeasure = m1.Multiply(m2) as DerivedMeasure;
            }
            Measures.Instance.Add(derivedMeasure);
            int i = 0;
            List <DerivedUnit> derivedUnits = new List <DerivedUnit>();

            foreach (string str in formulae.UnitList1)
            {
                var baseUnit = new BaseUnit(m1, Unit.SetFactor(str), str, str);
                Units.Instance.Add(baseUnit);
                var derivedUnit = baseUnit.Exponentiation(formulae.PowerList1[i]) as DerivedUnit;
                derivedUnit.Measure = derivedMeasure;
                Units.Instance.Add(derivedUnit);
                derivedUnits.Add(derivedUnit);
                i++;
                if (i == formulae.NumberOfUnits1)
                {
                    i = 0;
                    break;
                }
            }
            foreach (string str in formulae.UnitList2)
            {
                var baseUnit = new BaseUnit(m2, Unit.SetFactor(str), str, str);
                Units.Instance.Add(baseUnit);
                DerivedUnit derivedUnit;
                if (formulae.SelectedOperation == "Divide")
                {
                    derivedUnit = baseUnit.Exponentiation(-formulae.PowerList2[i]) as DerivedUnit;
                }
                else
                {
                    derivedUnit = baseUnit.Exponentiation(formulae.PowerList2[i]) as DerivedUnit;
                }
                derivedUnit.Measure = derivedMeasure;
                Units.Instance.Add(derivedUnit);
                derivedUnits.Add(derivedUnit);
                i++;
                if (i == formulae.NumberOfUnits2)
                {
                    break;
                }
            }
            for (int j = 0; j < formulae.NumberOfUnits1 + formulae.NumberOfUnits2 - 1; j++)
            {
                var a = derivedUnits[j].Multiply(derivedUnits[j + 1]) as DerivedUnit;
                Units.Instance.Add(a);
                derivedUnits[j + 1] = a;
                if (a.Name == null)
                {
                    a.Name = "1";
                }
                if (j == formulae.NumberOfUnits1 + formulae.NumberOfUnits2 - 2)
                {
                    formulae.Result = "Unit: " + a.Name + " Measure: " + derivedMeasure.Name ?? derivedMeasure.Terms[0].MeasureId;
                }
            }
            return(View("Index", formulae));
        }
Exemplo n.º 24
0
        public Measure Divide(BaseMeasure m)
        {
            var s = Multiply(m, true);

            return(s);
        }
Exemplo n.º 25
0
 public void CleanTests()
 {
     b = null;
 }
Exemplo n.º 26
0
 public void InitTests()
 {
     b = new BaseMeasure("kiirus");
 }