public void Does_right_operation()
 {
     Assert.That(DynamicNumber.Add(8, 2) is int a && a == 10);
     Assert.That(DynamicNumber.Sub(8, 2) is int s && s == 6);
     Assert.That(DynamicNumber.Mul(8, 2) is int m && m == 16);
     Assert.That(DynamicNumber.Div(8, 2) is int d && d == 4);
 }
        private static object Add2 <T, R>(T lhs, R rhs)
        {
            var result = DynamicNumber.Add(lhs, rhs);

            "{0}: {1} + {2} = {3} ({4})".Print(typeof(T).Name, lhs, rhs, result, result.GetType());
            return(result);
        }
        public void Dynamic_number_examples()
        {
            object objInt    = 1;
            object objDouble = 1.1;

            Assert.That(DynamicNumber.Add(objInt, objDouble) is double d1 && d1 == 2.1);
            Assert.That(DynamicNumber.Multiply('2', "1.1") is double d2 && d2 == 2.2);
            Assert.That(DynamicNumber.TryParseIntoBestFit("1", out object result) && result is byte b && b == 1);
        }
Beispiel #4
0
        public override object Evaluate(object lhs, object rhs)
        {
            if (lhs is string || rhs is string)
            {
                var lhsString = lhs.ConvertTo <string>();
                var rhsString = rhs.ConvertTo <string>();
                return(string.Concat(lhsString, rhsString));
            }

            return(DynamicNumber.Add(lhs, rhs));
        }
        public void Can_apply_operations_to_strings_containing_numbers()
        {
            var result = DynamicNumber.Add("1", "1");

            Assert.That(result, Is.EqualTo(2));
        }
Beispiel #6
0
 public object add(object lhs, object rhs) => DynamicNumber.Add(lhs, rhs);