Beispiel #1
0
 public ConstNode(ITerminalNode terminal, bool b) : base(terminal)
 {
     Mean = new BoolMean(b);
 }
        public void Operations()
        {
            var       funs = new GenFunctions();
            IReadMean i1 = new IntMean(20), i2 = new IntMean(5), i3 = new IntMean(0);
            IReadMean r1 = new RealMean(2.4), r2 = new RealMean(0.6), r3 = new RealMean(120);
            IReadMean d1 = new TimeMean(RTime(60)), d2 = new TimeMean(RTime(70));
            IReadMean s1 = new StringMean("Abc"), s2 = new StringMean("sT");

            IReadMean m = Calc(funs, "Plus_ii", DataType.Integer, i1, i2);

            Assert.AreEqual(25, m.Integer);
            Assert.IsNull(m.Error);
            Assert.AreEqual(3.0, Calc(funs, "Plus_rr", DataType.Integer, r1, r2).Real);
            Assert.AreEqual(RTime(62), Calc(funs, "Plus_dr", DataType.Time, d1, r3).Date);
            Assert.AreEqual(RTime(62), Calc(funs, "Plus_rd", DataType.Time, r3, d1).Date);
            Assert.AreEqual("AbcsT", Calc(funs, "Plus_ss", DataType.String, s1, s2).String);

            Assert.AreEqual(-20, Calc(funs, "Minus_i", DataType.Integer, i1).Integer);
            Assert.AreEqual(-2.4, Calc(funs, "Minus_r", DataType.Real, r1).Real);
            Assert.AreEqual(15, Calc(funs, "Minus_ii", DataType.Integer, i1, i2).Integer);
            Assert.IsTrue(Math.Abs(1.8 - Calc(funs, "Minus_rr", DataType.Real, r1, r2).Real) < 0.001);
            Assert.AreEqual(RTime(58), Calc(funs, "Minus_dr", DataType.Time, d1, r3).Date);
            Assert.AreEqual(-600, Calc(funs, "Minus_dd", DataType.Real, d1, d2).Integer);

            Assert.AreEqual(4.0, Calc(funs, "Divide_rr", DataType.Real, i1, i2).Real);
            m = Calc(funs, "Divide_rr", DataType.Real, i1, i3);
            Assert.AreEqual(0, m.Real);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(501, m.Error.Number);
            Assert.AreEqual(ErrQuality.Error, m.Error.Quality);
            Assert.AreEqual("Деление на 0", m.Error.Text);

            m = Calc(funs, "Multiply_rr", DataType.Integer, i3, m);
            Assert.AreEqual(0, m.Real);
            Assert.IsNull(m.Error);
            Assert.AreEqual(100, Calc(funs, "Multiply_ii", DataType.Integer, i1, i2).Integer);
            Assert.AreEqual(12, Calc(funs, "Multiply_rr", DataType.Integer, r1, i2).Real);

            Assert.AreEqual(4, Calc(funs, "Div_ii", DataType.Integer, i1, i2).Integer);
            m = Calc(funs, "Div_ii", DataType.Integer, i1, i3);
            Assert.AreEqual(0, m.Integer);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(511, m.Error.Number);
            Assert.AreEqual(ErrQuality.Error, m.Error.Quality);
            Assert.AreEqual("Деление на 0", m.Error.Text);

            Assert.AreEqual(5, Calc(funs, "Mod_ii", DataType.Integer, i2, i1).Integer);
            m = Calc(funs, "Mod_ii", DataType.Integer, i1, i3);
            Assert.AreEqual(0, m.Integer);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(521, m.Error.Number);
            Assert.AreEqual(ErrQuality.Error, m.Error.Quality);

            IReadMean i4 = new IntMean(-2), r4 = new RealMean(-1.1);

            Assert.AreEqual(79.62624, Calc(funs, "Power_rr", DataType.Real, r1, i2).Real);
            Assert.AreEqual(0, Calc(funs, "Power_rr", DataType.Real, i3, i4).Real);
            Assert.AreEqual(-32, Calc(funs, "Power_rr", DataType.Real, i4, i2).Real);
            Assert.AreEqual(531, Calc(funs, "Power_rr", DataType.Real, i4, r4).Error.Number);
            Assert.AreEqual(532, Calc(funs, "Power_rr", DataType.Real, i3, i3).Error.Number);

            IReadMean s3 = new StringMean("A*c"), s4 = new StringMean("Ab?"), s5 = new StringMean("");

            Assert.IsTrue(Calc(funs, "Like_ss", DataType.Boolean, s1, s1).Boolean);
            Assert.IsTrue(Calc(funs, "Like_ss", DataType.Boolean, s1, s3).Boolean);
            Assert.IsTrue(Calc(funs, "Like_ss", DataType.Boolean, s1, s4).Boolean);
            Assert.IsFalse(Calc(funs, "Like_ss", DataType.Boolean, s1, s2).Boolean);
            Assert.IsFalse(Calc(funs, "Like_ss", DataType.Boolean, s1, s5).Boolean);
            Assert.IsFalse(Calc(funs, "Like_ss", DataType.Boolean, s5, s3).Boolean);
            Assert.IsTrue(Calc(funs, "Like_ss", DataType.Boolean, s5, s5).Boolean);

            Assert.IsTrue(Calc(funs, "Equal_uu", DataType.Integer, i1, i1).Boolean);
            Assert.IsFalse(Calc(funs, "Equal_uu", DataType.Integer, s4, s3).Boolean);
            Assert.IsTrue(Calc(funs, "Equal_uu", DataType.Integer, s1, s1).Boolean);

            Assert.IsFalse(Calc(funs, "NotEqual_uu", DataType.Integer, i1, i1).Boolean);
            Assert.IsTrue(Calc(funs, "NotEqual_uu", DataType.Integer, s4, s3).Boolean);
            Assert.IsFalse(Calc(funs, "NotEqual_uu", DataType.Integer, s1, s1).Boolean);

            Assert.IsFalse(Calc(funs, "Less_uu", DataType.Integer, i1, i2).Boolean);
            Assert.IsFalse(Calc(funs, "Less_uu", DataType.Integer, r2, r2).Boolean);
            Assert.IsTrue(Calc(funs, "Less_uu", DataType.Integer, s1, s2).Boolean);

            Assert.IsFalse(Calc(funs, "LessEqual_uu", DataType.Integer, i1, i2).Boolean);
            Assert.IsTrue(Calc(funs, "LessEqual_uu", DataType.Integer, r2, r2).Boolean);
            Assert.IsTrue(Calc(funs, "LessEqual_uu", DataType.Integer, s1, s2).Boolean);

            Assert.IsFalse(Calc(funs, "Greater_uu", DataType.Integer, i2, i1).Boolean);
            Assert.IsFalse(Calc(funs, "Greater_uu", DataType.Integer, r2, r2).Boolean);
            Assert.IsTrue(Calc(funs, "Greater_uu", DataType.Integer, s2, s1).Boolean);

            Assert.IsFalse(Calc(funs, "GreaterEqual_uu", DataType.Integer, i2, i1).Boolean);
            Assert.IsTrue(Calc(funs, "GreaterEqual_uu", DataType.Integer, r2, r2).Boolean);
            Assert.IsTrue(Calc(funs, "GreaterEqual_uu", DataType.Integer, s2, s1).Boolean);

            m = Calc(funs, "Divide_rr", DataType.Real, i1, i3);
            IReadMean b1 = new BoolMean(true), b2 = new BoolMean(false), b3 = new BoolMom(DateTime.MinValue, false, m.Error);

            m = Calc(funs, "Not_b", DataType.Boolean, b1);
            Assert.IsFalse(m.Boolean);
            Assert.IsNull(m.Error);
            m = Calc(funs, "Not_b", DataType.Boolean, b3);
            Assert.IsTrue(m.Boolean);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(501, m.Error.Number);

            m = Calc(funs, "Xor_bb", DataType.Boolean, b1, b2);
            Assert.IsTrue(m.Boolean);
            Assert.IsNull(m.Error);
            m = Calc(funs, "Xor_bb", DataType.Boolean, b2, b3);
            Assert.IsFalse(m.Boolean);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(501, m.Error.Number);
            m = Calc(funs, "Xor_bb", DataType.Boolean, b3, b3);
            Assert.IsFalse(m.Boolean);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(501, m.Error.Number);
            Assert.AreEqual(17, Calc(funs, "Xor_ii", DataType.Integer, i1, i2).Integer);

            m = Calc(funs, "Or_bb", DataType.Boolean, b1, b2);
            Assert.IsTrue(m.Boolean);
            Assert.IsNull(m.Error);
            m = Calc(funs, "Or_bb", DataType.Boolean, b1, b3);
            Assert.IsTrue(m.Boolean);
            Assert.IsNull(m.Error);
            m = Calc(funs, "Or_bb", DataType.Boolean, b2, b3);
            Assert.IsFalse(m.Boolean);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(501, m.Error.Number);
            Assert.AreEqual(21, Calc(funs, "Or_ii", DataType.Integer, i1, i2).Integer);

            m = Calc(funs, "And_bb", DataType.Boolean, b1, b2);
            Assert.IsFalse(m.Boolean);
            Assert.IsNull(m.Error);
            m = Calc(funs, "And_bb", DataType.Boolean, b1, b3);
            Assert.IsFalse(m.Boolean);
            Assert.IsNotNull(m.Error);
            Assert.AreEqual(501, m.Error.Number);
            m = Calc(funs, "And_bb", DataType.Boolean, b1, b1);
            Assert.IsTrue(m.Boolean);
            Assert.IsNull(m.Error);
            Assert.AreEqual(4, Calc(funs, "And_ii", DataType.Integer, i1, i2).Integer);
        }