コード例 #1
0
        public void IsBorder_CorrectBorder()
        {
            // добавил ProgramImage, Calculater
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            Calculater item          = new Calculater(image);
            bool       correctanswer = true;
            int        h             = 3;
            int        w             = 3;
            int        x             = 1;
            int        y             = 1;

            //ProgramImage item = new ProgramImage();
            int[,] matrix = new int[w, h];
            for (int I = 0; I < w; I++)
            {
                for (int J = 0; J < h; J++)
                {
                    matrix[1, 1] = 1;
                }
            }
            Assert.AreEqual(item.IsBorder(matrix, x, y, h, w), correctanswer);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rberger247/kaur-code
        static void Main(string[] args)
        {
            Calculater calculater = new Calculater();

            Console.WriteLine(calculater.Add(12, 45, 78, 9));
            Console.WriteLine(calculater.Multiply(12, 45, 78, 8));
        }
コード例 #3
0
ファイル: NameSpace1.cs プロジェクト: mryyomutga/CS_Exercise
        // myLibを使った計算の処理
        static void Routine2()
        {
            int[]      box1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            double[]   box2 = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.0 };
            int        n1 = 1, n2 = 2, n3 = 3, n4 = 4, n5 = 5;
            double     d1 = 1.1, d2 = 2.2, d3 = 3.3, d4 = 4.4, d5 = 5.5;
            Calculater calc = new Calculater();

            var sumn = calc.Sum(n1, n2, n3, n4, n5);
            var sumd = calc.Sum(d1, d2, d3, d4, d5);

            var ave1 = calc.Average(sumn, 5);
            var ave2 = calc.Average(sumd, 5);
            var ave3 = calc.Average(box1);
            var ave4 = calc.Average(box2);

            Console.WriteLine("sum(box1) : {0}", calc.Sum(box1));
            Console.WriteLine("sum(n) : {0}", sumn);
            Console.WriteLine("sum(d) : {0}", sumd);
            Console.WriteLine("average(sumn) : {0}", ave1);
            Console.WriteLine("average(sumd) : {0}", ave2);
            Console.WriteLine("average(box1) : {0}", ave3);
            Console.WriteLine("average(box2) : {0}", ave4);
            Console.WriteLine("average(inputs) : {0}", calc.Average(d1, d2, d3, d4, d5));
        }
コード例 #4
0
        public void ShouldMulReturnTwentyWhenPassFiveandFour()
        {
            Calculater sut    = new Calculater();
            int        result = sut.Mul(4, 5);

            Assert.AreEqual(20, result);
        }
コード例 #5
0
        public void ShouldAddReturnTwentyWhenPassFiveandFour()
        {
            //Average
            Calculater sut    = new Calculater();
            int        result = sut.Add(5, 4);

            Assert.That(result, Is.EqualTo(20));
        }
コード例 #6
0
        public void ShouldAddReturnNineWhenPassFiveandFour()
        {
            //Average
            Calculater sut    = new Calculater();
            int        result = sut.Add(5, 4);

            Assert.AreEqual(9, result);
        }
コード例 #7
0
        public void 一分一種方法()
        {
            // 1
            var target   = new Calculater();
            int actual   = target.Ways(1);
            var expected = 1;

            Assert.AreEqual(expected, actual);
        }
コード例 #8
0
        private void CalculateButton_OnClick(object sender, RoutedEventArgs e)
        {
            List <string> lst = Calculater.Calculate(_inSignals);

            for (int i = 0; i < lst.Count; i++)
            {
                _outTextBlocks[i].Text = lst[i].Split('#')[1];
            }
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: rberger247/kaur-code
        public static int Multiply(this Calculater calculater, params int[] data) // this followed by the class to be extended
        {
            int temp = 1;

            foreach (var item in data)
            {
                temp *= item;
            }
            return(temp);
        }
コード例 #10
0
        public void InputTest()
        {
            var calc = new Calculater();

            var result = calc.Calculate("1234567890N");

            Assert.AreEqual(-1234567890, result);

            calc.Close();
        }
コード例 #11
0
        public void 二分二種方法()
        {
            // 1 + 1
            // 2

            var target   = new Calculater();
            int actual   = target.Ways(2);
            var expected = 2;

            Assert.AreEqual(expected, actual);
        }
コード例 #12
0
        public void IndexViewModelNotNull()
        {
            SquareMatrix <double> square  = new SquareMatrix <double>(3);
            Calculater <double>   visitor = new Calculater <double>(square);

            Mock <SquareMatrix <double> > mock = new Mock <SquareMatrix <double> >();

            mock.Setup(m => m.Accept(visitor));

            DiagonalMatrix <double> matrix = new DiagonalMatrix <double>(mock.Object.Size);
        }
コード例 #13
0
        public void TestOpenClose()
        {
            var calc = new Calculater();

            Assert.NotNull(Process.GetProcesses().FirstOrDefault(p => p.ProcessName == "Calculator"));

            calc.Close();
            Thread.Sleep(1000); // wait a bit to ensure that Calculator is closed

            Assert.Null(Process.GetProcesses().FirstOrDefault(p => p.ProcessName == "Calculator"));
        }
コード例 #14
0
        public void TestAdd()
        {
            //arrange
            Calculater calculater  = new Calculater();
            float      expectedSum = 5f;

            //Act
            var actualSum = calculater.Add(2, 3);

            //Assert
            Assert.AreEqual(expectedSum, actualSum);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: Hannahayek/TrainingCSharp
        static void Main(string[] args)
        {
            var john = new Person();

            john.FirstName = "Hanna";
            john.LastName  = "hayek";
            john.introduce();

            Calculater calculater = new Calculater();

            var result = calculater.Add(10, 11);
        }
コード例 #16
0
        private void Calculate(object sender, RoutedEventArgs e)
        {
            var calculater = new Calculater();

            hiddenAnswerС.Visibility = Visibility.Visible;
            hiddenAnswerС.Content    = answer.Text + ". Ответ : " + calculater.Calculate(OptimizeString(answer.Text)).ToString();

            using (var writer = new StreamWriter(@"C:\Users\Яна\OneDrive\Рабочий стол\OPz\OPZWPF\file.txt", true))
            {
                writer.WriteLine(hiddenAnswerС.Content);
            }
        }
コード例 #17
0
        public void IsBorder_InvalidStartPoint()
        {
            // добавил ProgramImage, Calculater
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            Calculater item          = new Calculater(image);
            bool       correctanswer = false;
            int        h             = 3;
            int        w             = 3;
            int        x1            = -1;
            int        y1            = 0;
            int        x2            = -1;
            int        y2            = -1;
            int        x3            = 0;
            int        y3            = -1;
            int        x4            = -1;
            int        y4            = -1;
            int        x5            = w + 1;
            int        y5            = 0;
            int        x6            = w + 1;
            int        y6            = h + 1;
            int        x7            = 0;
            int        y7            = h + 1;
            int        x8            = w + 1;
            int        y8            = h + 1;

            //ProgramImage item = new ProgramImage();
            int[,] matrix = new int[w, h];
            for (int I = 0; I < w; I++)
            {
                for (int J = 0; J < h; J++)
                {
                    matrix[1, 1] = 1;
                }
            }
            Assert.AreEqual(item.IsBorder(matrix, x1, y1, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x2, y2, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x3, y3, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x4, y4, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x5, y5, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x6, y6, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x7, y7, h, w), correctanswer);
            Assert.AreEqual(item.IsBorder(matrix, x8, y8, h, w), correctanswer);
        }
コード例 #18
0
        public void  分三種方法()
        {
            // 1 + 1 + 1
            // 1 + 2
            // 2 + 1
            // 3

            var target   = new Calculater();
            int actual   = target.Ways(3);
            var expected = 4;

            Assert.AreEqual(expected, actual);
        }
コード例 #19
0
ファイル: StrategyPatten.cs プロジェクト: dt792/DesignPatten
        public void Run()
        {
            Calculater calculater = new Calculater();

            calculater.strategy = new SwingAddStrategy();
            List <int> intList = new List <int>()
            {
                2, 3, 4, 5, 7, 8, 9
            };

            Console.WriteLine(calculater.DoMath(intList));
            calculater.strategy = new AddStrategy();
            Console.WriteLine(calculater.DoMath(intList));
        }
コード例 #20
0
ファイル: BinExpUtil.cs プロジェクト: supuy-ruby/ZCompileCore
 public static string GetTypeName(Type ltype, Type rtype)
 {
     if (ltype == typeof(bool) && rtype == typeof(bool))
     {
         return("Bool");
     }
     if (ltype == typeof(int) && rtype == typeof(int))
     {
         return("Int");
     }
     if (Calculater.IsNumber(ltype) && Calculater.IsNumber(rtype))
     {
         return("Float");
     }
     return("Ref");
 }
コード例 #21
0
        public void 四分七種方法()
        {
            // 1 + 1 + 1 + 1
            // 2 + 1 + 1
            // 1 + 2 + 1
            // 1 + 1 + 2
            // 3 + 1
            // 1 + 3
            // 2 + 2

            var target   = new Calculater();
            int actual   = target.Ways(4);
            var expected = 7;

            Assert.AreEqual(expected, actual);
        }
コード例 #22
0
        public static void 启动()
        {
            列表 <string> L = new 列表 <string>();

            L.Add("AA");
            L.Add("BB");
            L.Add("CC");
            int i     = 1;
            int count = L.Count;

            while (Calculater.LEInt(i, count))
            {
                Console.Write(L[i]);
                i++;
            }
            Console.ReadKey();
        }
コード例 #23
0
        public static void practice13_1()
        {
            Calculater calA = new Calculater();
            Calculater calB = new Calculater();

            int a = 20;
            int b = 10;

            double x = 20.5;
            double y = 10.5;

            Console.WriteLine("a={0}, b={1}", a, b);
            Console.WriteLine("사칙연산 결과: {0},{1},{2},{3}", calA.Add(a, b), calA.Substract(a, b), calA.Multiply(a, b), calA.Divide(a, b));
            Console.WriteLine();
            Console.WriteLine("x={0}, y={1}", x, y);
            Console.WriteLine("사칙연산 결과: {0},{1},{2},{3:N6}", calB.Add(x, y), calB.Substract(x, y), calB.Multiply(x, y), calB.Divide(x, y));
        }
コード例 #24
0
        public void PerimetrNoMatrix()
        {
            // добавил ProgramImage, Calculater
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            Calculater item  = new Calculater(image);
            int        count = 0;

            count = item.Perimetr(null, 2, 800, 600);
            Assert.AreEqual(count, -1);
        }
コード例 #25
0
        public void SquareCalculate_InvalidHeightToCalculate_Above()
        {
            // добавил ProgramImage, Calculater
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            Calculater item          = new Calculater(image);
            int        correctanswer = -2;
            int        x             = 2;
            int        y             = 5;
            int        h             = 10;
            int        w             = 10;
            int        invalid_h     = 12;
            int        num           = 1;

            int[,] matrix = new int[w, h];
            for (int I = 0; I < w; I++)
            {
                for (int J = 0; J < h; J++)
                {
                    if (I == 5 && J == 5)
                    {
                        matrix[I, J] = 1;
                    }
                    else
                    {
                        matrix[I, J] = 0;
                    }
                }
            }
            //ProgramImage item = new ProgramImage();
            Assert.AreEqual(item.SquareCalculate(x, y, num, matrix, invalid_h, w), correctanswer);
        }
コード例 #26
0
        public void 五分十三種方法()
        {
            // 1 + 1 + 1 + 1 + 1
            // 2 + 1 + 1 + 1
            // 1 + 2 + 1 + 1
            // 1 + 1 + 2 + 1
            // 1 + 1 + 1 + 2
            // 3 + 1 + 1
            // 1 + 3 + 1
            // 1 + 1 + 3
            // 2 + 2 + 1
            // 2 + 1 + 2
            // 1 + 2 + 2
            // 3 + 2
            // 2 + 3

            var target   = new Calculater();
            int actual   = target.Ways(5);
            var expected = 13;

            Assert.AreEqual(expected, actual);
        }
コード例 #27
0
        public void SquareCalculate_CorrectCalculate()
        {
            // добавил создание ProgramImage и добавил картинку
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            int        correctanswer = 99;
            Calculater item          = new Calculater(image);
            int        x             = 2;
            int        y             = 2;
            int        num           = 1;
            int        h             = 10;
            int        w             = 10;

            int[,] matrix = new int[w, h];
            for (int I = 0; I < w; I++)
            {
                for (int J = 0; J < h; J++)
                {
                    if (I == 5 && J == 5)
                    {
                        matrix[I, J] = 1;
                    }
                    else
                    {
                        matrix[I, J] = 0;
                    }
                }
            }
            Assert.AreEqual(item.SquareCalculate(x, y, num, matrix, h, w), correctanswer);
        }
コード例 #28
0
ファイル: BinExpUtil.cs プロジェクト: supuy-ruby/ZCompileCore
 public static CalculaterMethodTypeEnum GetCalculaterMethodType(TokenKind opKind, Type ltype, Type rtype)
 {
     //Type calcType = typeof(Calculater);
     if (ltype == typeof(string) || rtype == typeof(string))
     {
         if (opKind == TokenKind.ADD)
         {
             return(CalculaterMethodTypeEnum.ContactString);
         }
     }
     if (opKind == TokenKind.ADD || opKind == TokenKind.SUB || opKind == TokenKind.MUL)
     {
         return(CalculaterMethodTypeEnum.MathOp);
     }
     if (opKind == TokenKind.DIV)
     {
         return(CalculaterMethodTypeEnum.MathDiv);
     }
     if (opKind == TokenKind.GT || opKind == TokenKind.GE || opKind == TokenKind.LT || opKind == TokenKind.LE)
     {
         return(CalculaterMethodTypeEnum.MathCompare);
     }
     if (opKind == TokenKind.AND || opKind == TokenKind.OR)
     {
         return(CalculaterMethodTypeEnum.Logic);
     }
     if (opKind == TokenKind.EQ || opKind == TokenKind.NE)
     {
         if (Calculater.IsNumber(ltype) && Calculater.IsNumber(rtype))
         {
             return(CalculaterMethodTypeEnum.MathCompare);
         }
         else
         {
             return(CalculaterMethodTypeEnum.RefCompare);
         }
     }
     return(CalculaterMethodTypeEnum.None);
 }
コード例 #29
0
        public void PerimetrNegativeNum()
        {
            // добавил ProgramImage, Calculater
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            Calculater item  = new Calculater(image);
            int        count = 0;

            int[,] matr = new int[1, 1];
            matr[0, 0]  = 2;
            count       = item.Perimetr(matr, -1, 2000, 2000);
            Assert.AreEqual(count, -1);
        }
コード例 #30
0
        public void IsBorder_NullMatrix()
        {
            // добавил ProgramImage, Calculater
            ProgramImage image = new ProgramImage();
            Bitmap       map   = new Bitmap(800, 600);

            for (int I = 0; I < 800; I++)
            {
                for (int J = 0; J < 600; J++)
                {
                    map.SetPixel(I, J, Color.Black);
                }
            }
            image.AddNewImage(map);
            Calculater item          = new Calculater(image);
            bool       correctanswer = false;
            int        h             = 3;
            int        w             = 3;
            int        x             = 1;
            int        y             = 1;

            //ProgramImage item = new ProgramImage();
            Assert.AreEqual(item.IsBorder(null, x, y, h, w), correctanswer);
        }