Пример #1
0
        public void Add_Zero_Returns0()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("0");

            Assert.AreEqual(0, result);
        }
Пример #2
0
        public void Add_NumbersNewLineAndSeparatedByComma_Returns6()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("1\n2,3");

            Assert.AreEqual(6, result);
        }
Пример #3
0
        public void Add_MultipleCharDelimiter_Returns6()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//[***]\n1***2***3");

            Assert.AreEqual(6, result);
        }
Пример #4
0
        public void Add_IgnoreNegativeNumbers_Returns1()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//;\n-1,1");

            Assert.AreEqual(1, result);
        }
Пример #5
0
        public void Add_IgnoreNumbersGreaterThan1000_Returns2()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//;\n1001;2");

            Assert.AreEqual(2, result);
        }
Пример #6
0
    static void Main(string[] args)
    {
        System.Console.WriteLine("Call methods from MathLibrary.DLL:");

        if (args.Length != 2)
        {
            System.Console.WriteLine("Usage: TestCode <num1> <num2>");
            return;
        }

        long num1 = long.Parse(args[0]);
        long num2 = long.Parse(args[1]);

        long sum        = AddClass.Add(num1, num2);
        long product    = MultiplyClass.Multiply(num1, num2);
        long difference = SubtractionClass.Subtract(num1, num2);
        long final      = DivisionClass.Divide(num1, num2);

        System.Console.WriteLine("Addition: {0} + {1} = {2}", num1, num2, sum);

        System.Console.WriteLine("Multiplication: {0} * {1} = {2}", num1, num2, product);

        System.Console.WriteLine("Subtraction: {0} - {1} = {2}", num1, num2, difference);

        System.Console.WriteLine("Division: {0} / {1} = {2}", num1, num2, final);
    }
Пример #7
0
        public void Add_SemicolonDelimiterSpecified_Returns3()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//;\n1;2");

            Assert.AreEqual(3, result);
        }
Пример #8
0
        public void Add_TrimSpaceAndCombineCharactersThatConnect_Returns16()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//[$]\n1 2$3,1");

            Assert.AreEqual(16, result);
        }
Пример #9
0
        public void Add_NumbersSeparatedByComma_Returns3()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("0,1,2");

            Assert.AreEqual(3, result);
        }
Пример #10
0
        public void Add_FwdSlashFwdSlash_Returns0()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//");

            Assert.AreEqual(0, result);
        }
Пример #11
0
        public void Add_IgnoreStringsBoundByWrongDelimiter_Returns3()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//[$]\n1%2,3");

            Assert.AreEqual(3, result);
        }
Пример #12
0
        public void Add_MultipleDelimitersThatHaveMultipleChar_Returns6()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("//[**][%%]\n1**2%%3");

            Assert.AreEqual(6, result);
        }
Пример #13
0
        public void Add_EmptyString_Returns0()
        {
            var addclass = new AddClass();
            var result   = addclass.Add("");

            Assert.AreEqual(0, result);
        }
Пример #14
0
        static void Main(string[] args)
        {
            long result1 = AddClass.Add(2, 3);
            long result2 = MultiClass.Multi(2, 3);

            Console.WriteLine($"result1={result1},result2={ result2}");
        }
Пример #15
0
        // main function
        public static void Main(String[] args)
        {
            // Panggil semua fungsi
            // AddClass.Add()
            System.Console.WriteLine("The result of 100 + 35 is {0}", AddClass.Add(100, 35));

            // MultiClass.Multiply()
            System.Console.WriteLine("The result of 27 * 5 is {0}", MultiClass.Multiply(27, 5));

            // FactorialClass.Factorial()
            System.Console.WriteLine("The result of 5! is {0}", FactorialClass.Factorial(5));
        }
Пример #16
0
    public static void Main(string[] args)
    {
        if (args.Length != 2)
        {
            Console.WriteLine("Usage : Test <num1> <num2>");
            return;
        }
        int num1 = int.Parse(args[0]);
        int num2 = int.Parse(args[1]);

        int sum  = AddClass.Add(num1, num2);
        int mult = MultiplyClass.Multiply(num1, num2);

        Console.WriteLine("{0} + {1} => {2}", num1, num2, sum);
        Console.WriteLine("{0} * {1} => {2}", num1, num2, mult);
    }
Пример #17
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Calling methods from MyLibrary.DLL:");
        if (args.Length != 2)
        {
            Console.WriteLine("Usage: MyClient <num1> <num2>");
            return;
        }
        long num1    = long.Parse(args[0]);
        long num2    = long.Parse(args[1]);
        long sum     = AddClass.Add(num1, num2);
        long product = MultiplyClass.Multiply(num1, num2);

        Console.WriteLine("The sum of {0} and {1} is {2}", num1, num2, sum);
        Console.WriteLine("The product of {0} and {1} is {2}", num1, num2, product);
    }
Пример #18
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Calling methods from MyDLL.DLL");
        if (args.Length != 2)
        {
            Console.WriteLine("Usage: MyClient <num1> <num2>");
            return;
        }
        long num1    = long.Parse(args[0]);
        long num2    = long.Parse(args[1]);
        long sum     = AddClass.Add(ref num1, ref num2);
        long product = MultiplyClass.Multiply(num1, num2);

        Console.WriteLine("{0} + {1} = {2}", num1, num2, sum);
        Console.WriteLine("{0} * {1} = {2}", num1, num2, product);
    }
Пример #19
0
    public static void Main()
    {
        int num1, num2;
        int sum, mult;

        Console.Write("Enter Number 1 : ");
        num1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter Number 2 : ");
        num2 = Convert.ToInt32(Console.ReadLine());

        sum  = AddClass.Add(num1, num2);
        mult = MultClass.Mult(num1, num2);

        Console.WriteLine("Addition of {0} and {1} is : {2}", num1, num2, sum);
        Console.WriteLine("Multiplication of {0} and {1} is : {2}", num1, num2, mult);
    }
Пример #20
0
    static void Main(string[] args)
    {
        System.Console.WriteLine("Calling methods from MathLibrary.DLL:");

        if (args.Length != 2)
        {
            System.Console.WriteLine("Usage: TestCode <num1> <num2>");
            return;
        }

        long num1 = long.Parse(args[0]);
        long num2 = long.Parse(args[1]);

        long sum     = AddClass.Add(num1, num2);
        long product = MultiplyClass.Multiply(num1, num2);

        System.Console.WriteLine("{0} + {1} = {2}", num1, num2, sum);
        System.Console.WriteLine("{0} * {1} = {2}", num1, num2, product);
    }
Пример #21
0
        static void Main(string[] args)
        {
            //1
            Console.WriteLine("这是一个两数相加的程序:");
            //2获得输入:提示,获得输入
            Console.WriteLine("请输入加数:");
            string s = Console.ReadLine();

            Console.WriteLine("请输入被加数:");
            string s2 = Console.ReadLine();
            //3处理
            int      a   = Convert.ToInt32(s);
            int      a2  = Convert.ToInt32(s2);
            int      re  = 0;
            AddClass obj = new AddClass();

            re = obj.Add(a, a2);
            //4输出
            Console.WriteLine("计算的结果是:" + re);
            Console.ReadKey();
        }
Пример #22
0
    static void Main(string[] args)
    {
        #region Interface - Property caller
        Console.WriteLine();
        // Implementing property : Setting value to the property in IF extended class
        MyClass objMC = new MyClass();
        objMC.Name = "shiva";
        Console.WriteLine("Name provided (Interface) : " + objMC.Name);
        Console.WriteLine();

        IFTest objT = new IFTest();
        // Calling SaveData would be ambiguous (since both Interface has same method name). Compiler calls both implementation
        string strIsIdatastore   = (objT is IDataStore) ? "Yes" : "No";
        string strIsISerializabl = (objT is IDataStore) ? "Yes" : "No";
        objT.SaveData();
        Console.WriteLine("Is IDataStore called : " + strIsIdatastore);
        Console.WriteLine("Is ISerializabl called : " + strIsISerializabl);
        Console.WriteLine();

        // To call a specific member of the interface casting can be done accordingly
        ((ISerializabl)objT).SaveData();
        ((IDataStore)objT).SaveData();
        Console.WriteLine();

        EditBox edit = new EditBox();
        edit.SaveData();
        Console.WriteLine();
        #endregion

        #region Abstract class - sum caller
        // Abstract class cannot be instantiated
        AddClass objAC = new AddClass();
        int      sum   = objAC.Add(2, 3);
        Console.WriteLine("Sum of two nos (using Abstract Class) : " + sum);
        Console.WriteLine();
        #endregion

        #region Polymorphism - callign base class/derived class methods
        // Polymorphism : Calling base class method
        BaseClassPoly objBCP         = new BaseClassPoly();
        string        strWelcomeBase = objBCP.Welcome();
        Console.WriteLine(strWelcomeBase);
        Console.WriteLine();

        // calling derived class & methods
        DerivedClassPoly objDCP = new DerivedClassPoly();
        string           strWel = objDCP.Welcome("shiva");
        Console.WriteLine(strWel);
        Console.WriteLine(objDCP.DateDetails());
        Console.WriteLine(objDCP.Welcome());
        Console.WriteLine();
        #endregion

        #region Indexer - set & get for int & string indexers
        // Indexer. setting and getting values
        IndexerClass objIC = new IndexerClass();
        objIC[1] = 1;
        objIC[0] = 0;
        objIC[2] = 2;
        // This value cannot be assigned as indexer size is only 3 (zero based)
        // Inside indexer setter : Value would be assignd as Zero as the index is outside bounds of the array
        objIC[4] = 10;

        for (int i = 0; i <= 5; i++)
        {
            Console.WriteLine("Indexer value for objIC[" + i + "] : " + objIC[i]);
        }

        // Indexer can be overloaded. multiple indexers can co-exist in a class
        // below indexer returns String output for the day provided
        Console.WriteLine();
        string dayCount = objIC["FRI"];
        Console.WriteLine("Indexer day count for Friday : " + dayCount);
        Console.WriteLine();
        #endregion

        #region Delegates - sum/sub & multicast
        // delegates are references to method
        // Create an instance of the class & pass the method as reference to delegate object
        DelegateClass objDC = new DelegateClass();
        // Method can be passed as reference to delegate in below way also or can be assigned directly.
        // AddSubDelegate objAddSubDel = new AddSubDelegate(objDC.Add);
        AddSubDelegate objAddSubDel = objDC.Add;
        int            delsum       = objAddSubDel(1, 2);
        Console.WriteLine("Delegate := Sum & sub of 1 & 2 : " + delsum);

        // Multicast delegates
        Console.WriteLine();
        objDC = new DelegateClass();
        AddSubDelegate objAddSubMultiDel = null;
        objAddSubMultiDel  = new AddSubDelegate(objDC.Add);
        objAddSubMultiDel += new AddSubDelegate(objDC.Sub);

        int delSumSub = objAddSubMultiDel(1, 2);
        Console.WriteLine("Multicast Delgate : Add & sub of 1,2 methods called: " + delSumSub);
        //removing sub method
        objAddSubMultiDel -= new AddSubDelegate(objDC.Sub);
        Console.WriteLine("Multicast Delgate : removing sub of 1,2 method : " + objAddSubMultiDel(1, 2));
        Console.WriteLine();
        #endregion

        #region Events
        // call event class & assign ChangeEvent with the corresponding handler
        EventClass objEC = new EventClass();
        objEC.ChangeEvent += new MyDelegate(objEC.ChangeEventMethod);
        // ChangeEvent is called everytime when the setter is called in EventClass
        objEC.Price = 10;
        objEC.Price = 20;
        Console.WriteLine();
        #endregion

        #region Value & Reference
        ValueAndRefClass objVAR = new ValueAndRefClass();
        // Implicit Value types (like int) are always passed by value
        int a;
        objVAR.DoWork(out a);
        Console.WriteLine("Value of A is :" + a);
        Console.WriteLine();

        int b = 3;
        Console.WriteLine("Value of B before REF is :" + b);
        objVAR.DoWorkB(ref b);
        Console.WriteLine("Value of B after REF is :" + b);
        Console.WriteLine();

        // Object Types are impicitly passed by reference
        int[] nums = { 1, 3, 5 };
        objVAR.DoWorkObject(nums);

        int count = 0;
        foreach (int n in nums)
        {
            Console.WriteLine("Value of a[{0}] is {1}", count++, n);
        }
        Console.WriteLine();
        #endregion
    }