Ejemplo n.º 1
0
        public void ArrayStackSumTest()
        {
            arrayStack.Push(70);
            arrayStack.Push(30);

            Assert.AreEqual(100, Calculator2.Sum());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            #region 람다 연습
            // 델리게이트 키워드를 사용한 무명메소드
            CalcDelegate c1 = delegate(int a, int b)
            {
                return(a + b);
            };

            Console.WriteLine(c1(3, 4));

            // 람다식으로 표현한 익명메소드
            CalcDelegate c2 = (a, b) => a + b; //Delegate에 매개변수가 int 선언이 되어있으므로 생략이 가능
            Console.WriteLine(c2(3, 4));

            c2 = (a, b) =>
            {
                if (b == 0)
                {
                    return(null);
                }
                return(a / b);
            };
            Console.WriteLine(c2(10, 3));
            Console.WriteLine(c2(10, 0));
            #endregion

            // 2. 제네릭 타입의 델리게이트 참조변수 생성하면서 사칙연산 람다식 할당
            Calculator2 <double> c3 = (a, b) => a + b;

            // 3. 위 참조변수로 Calc 메소드 호출
            Calc <double>(3.14, 6.56, c3);
            Calc <int>(100, 200, (a, b) => a + b);
        }
Ejemplo n.º 3
0
        public void ArrayStackProductTest()
        {
            arrayStack.Push(3);
            arrayStack.Push(15);

            Assert.AreEqual(45, Calculator2.Product());
        }
Ejemplo n.º 4
0
        public void ArrayStackDifferenceTest()
        {
            arrayStack.Push(20);
            arrayStack.Push(35);

            Assert.AreEqual(15, Calculator2.Difference());
        }
Ejemplo n.º 5
0
        public void ArrayStackQuotientTest()
        {
            arrayStack.Push(3);
            arrayStack.Push(99);

            Assert.AreEqual(33, Calculator2.Quotient());
        }
Ejemplo n.º 6
0
        public IActionResult Create([FromForm] Calcilation calc)
        {
            Calculator2 calculator = new Calculator2();

            HttpContext.Session.SetString("result", (calculator.Caculation(calc).ToString()));
            ViewBag.result = HttpContext.Session.GetString("result");
            return(View());
        }
Ejemplo n.º 7
0
        public void ManagesZeroTest()
        {
            var input = "0*1";

            var result = Calculator2.Calculate(input);

            Assert.AreEqual(0, result);
        }
Ejemplo n.º 8
0
        public void CalculatesComplexOperationTest()
        {
            var input = "   3  - 98 * 44 /15-3  ";

            var result = Calculator2.Calculate(input);

            Assert.AreEqual(-287, result);
        }
Ejemplo n.º 9
0
        public void AppliesOperatorPrecedenceTest()
        {
            var input = "3+2*3";

            var result = Calculator2.Calculate(input);

            Assert.AreEqual(9, result);
        }
Ejemplo n.º 10
0
        public void CalculatesSimpleSumTest()
        {
            var simpleSum = "3+2";

            var result = Calculator2.Calculate(simpleSum);

            Assert.AreEqual(5, result);
        }
        public void Test_AverageByMedian()
        {
            IAvgMethod method = new MeanMeth();

            double expected = 8.0;

            double actual = Calculator2.CalculateAverange(method, values.ToArray());

            Assert.AreEqual(expected, actual, 0.000001);
        }
Ejemplo n.º 12
0
        public void Test_AverageByMedian2()
        {
            var calculator = new Calculator2();
            var computer   = new DoubleAverangeComputer2();

            double expected = 8.0;

            double actual = calculator.CalculateAverage(_values, computer.ComputeAverange);

            Assert.AreEqual(expected, actual, 0.000001);
        }
Ejemplo n.º 13
0
        public static void Main(string[] args)
        {
            Person shaon = new Person();

            shaon.firstName = "S M";
            shaon.lastName  = "Farhad";
            shaon.Introduce();

            Calculator calculator = new Calculator();                               // this class is in the same namespace

            Calculator2 calculator2 = new Calculator2();                            // this class is in a different namespace

            var result = calculator2.Add(2, 3);

            Console.WriteLine(result);
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            #region 람다 함수
            // 델리게이트 키워드를 사용한 무명 메소드
            CalcDelegate calc1 = delegate(int a, int b)
            {
                return(a + b);
            };
            Console.WriteLine(calc1(3, 4));

            //람다식으로 표현한 익명메소드
            CalcDelegate calc2 = (a, b) => a + b;
            Console.WriteLine(calc2(3, 4));

            calc2 = (a, b) =>
            {
                if (b == 0)
                {
                    return(null);
                }
                return(a / b);
            };
            Console.WriteLine(calc2(10, 3));
            if (calc2(10, 0) == null)
            {
                Console.WriteLine("0으로 못나눔");
            }
            else
            {
                Console.WriteLine(calc2(10, 0));
            }
            #endregion

            // 2. 제네릭 타입의 델리게이트 참조변수 생성하면서 사칙연산 람다식 할당
            Calculator2 <double> calc3 = (a, b) => a + b;

            // 3. 위 참조변수로 Calc 메소드 호출
            Calc <double>(3.14, 6.56, calc3);
            Calc <int>(100, 200, (a, b) => a + b);
        }
Ejemplo n.º 15
0
        public static void practice13_2()
        {
            Calculator2 <int> calInt = new Calculator2 <int>();
            int a = 20, b = 10;

            Console.WriteLine("a={0}, b={1}", a, b);
            Console.WriteLine("사칙연산 결과: {0},{1},{2},{3}",
                              calInt.Add(a, b),
                              calInt.Substract(a, b),
                              calInt.Multiply(a, b),
                              calInt.Divide(a, b));

            Console.WriteLine();

            Calculator2 <double> caldouble = new Calculator2 <double>();
            double x = 20.5, y = 10.5;

            Console.WriteLine("x={0}, y={1}", x, y);
            Console.WriteLine("사칙연산 결과: {0},{1},{2},{3}",
                              caldouble.Add(x, y),
                              caldouble.Substract(x, y),
                              caldouble.Multiply(x, y),
                              caldouble.Divide(x, y));
        }
Ejemplo n.º 16
0
 public GenericsExample()
 {
     Console.WriteLine(Calculator1.AreEqual <string>("A", "A") ? "Equal" : "Not Equal");
     Console.WriteLine(Calculator2 <string> .AreEqual("A", "A") ? "Equal" : "Not Equal");
 }
Ejemplo n.º 17
0
 // 사칙연산 처리 메소드
 static void Calc <T>(T a, T b, Calculator2 <T> CalcFunc)
 {
     Console.WriteLine(CalcFunc(a, b));
 }