Example #1
0
    static public void Main()
    {
        NumberChecker n = new NumberChecker();

        String num1 = n.getNumber(), num2 = n.getNumber2(num1);

        int initialTotal = Convert.ToInt32(num1[0]) + Convert.ToInt32(num2[0]);

        for (int i = 1; i < num1.Length; i++)
        {
            if (Convert.ToInt32(num1[i]) + Convert.ToInt32(num2[i]) == initialTotal)
            {
                if (i == num1.Length - 1)
                {
                    Console.WriteLine(true);
                }
            }
            else
            {
                Console.WriteLine(false);
                break;
            }
        }

        Console.ReadKey();
    }
Example #2
0
        public void isOutOfRange(int a)
        {
            NumberChecker numberChecker = new NumberChecker();

            //Assert
            Assert.That(() => numberChecker.checkDivision(a), Throws.ArgumentException);
        }
Example #3
0
        public void DataDriven(int number, bool expectedResult)
        {
            var sut = new NumberChecker();

            var result = sut.IsLessThanTen(number);

            Assert.Equal(expectedResult, result);
        }
Example #4
0
        public void checkDivisionBy5And3(int a)
        {
            NumberChecker numberChecker = new NumberChecker();
            string        result        = numberChecker.checkDivision(a);

            //Assert
            Assert.That(result, Is.EqualTo("FizzBuzz"));
        }
Example #5
0
        public void isNotDividedBy3Or5(int a)
        {
            NumberChecker numberChecker = new NumberChecker();
            string        result        = numberChecker.checkDivision(a);

            //Assert
            Assert.That(result, Is.EqualTo(a.ToString()));
        }
Example #6
0
        static void Main(string[] args)
        {
            // 1. Tworzymy łańcuch odpowiedzialności
            var passwordChecker = new NumberChecker(new LengthChecker(new UpperLetterChecker(null)));

            var result = passwordChecker.Analyze("dahsjk%^^&*1231");

            Console.WriteLine(result.ActualPoints);
        }
Example #7
0
        public void NumberChecker_OutOfBoundsNumber_Exception(int number)
        {
            // Arrange
            INumberChecker defaultNumberChecker = new NumberChecker();
            async Task NumberCheckCode() => await defaultNumberChecker.CheckNumber(number);

            // Act && Assert
            Check.ThatCode(NumberCheckCode).Throws <ArgumentOutOfRangeException>();
        }
        public void Test_CheckIfNextIsPrimePowerOfTwo()
        {
            Assert.AreEqual(true, NumberChecker.CheckIfNextIsPrimePowerOfTwo(31));
            Assert.AreEqual(true, NumberChecker.CheckIfNextIsPrimePowerOfTwo(2047));

            Assert.AreEqual(false, NumberChecker.CheckIfNextIsPrimePowerOfTwo(32));
            Assert.AreEqual(false, NumberChecker.CheckIfNextIsPrimePowerOfTwo(16));
            Assert.AreEqual(false, NumberChecker.CheckIfNextIsPrimePowerOfTwo(6));
            Assert.AreEqual(false, NumberChecker.CheckIfNextIsPrimePowerOfTwo(-5));
        }
        public void Test_CheckIfPrime()
        {
            Assert.AreEqual(true, NumberChecker.CheckIfPrime(5));
            Assert.AreEqual(true, NumberChecker.CheckIfPrime(3));
            Assert.AreEqual(true, NumberChecker.CheckIfPrime(11));
            Assert.AreEqual(true, NumberChecker.CheckIfPrime(2053));
            Assert.AreEqual(true, NumberChecker.CheckIfPrime(2039));

            Assert.AreEqual(false, NumberChecker.CheckIfPrime(2047));
            Assert.AreEqual(false, NumberChecker.CheckIfPrime(-31));
            Assert.AreEqual(false, NumberChecker.CheckIfPrime(15));
            Assert.AreEqual(false, NumberChecker.CheckIfPrime(10));
            Assert.AreEqual(false, NumberChecker.CheckIfPrime(1000));
        }
Example #10
0
        private static IEnumerable <int> CheckNumbers(IEnumerable <int> numbers, NumberChecker checker)
        {
            List <int> result = new List <int>();

            foreach (var n in numbers)
            {
                //checker.Invoke(n);
                if (checker(n))
                {
                    result.Add(n);
                }
            }

            return(result);
        }
Example #11
0
        static void Main(string[] args)
        {
            List <bool> results = new List <bool>();

            string       lineRead    = InputSystem.ReadLine();
            NumberReader numbersRead = new NumberReader(lineRead);

            int num_A = numbersRead.Read_A();
            int num_B = numbersRead.Read_B();
            int num_C = numbersRead.Read_C();
            int num_D = numbersRead.Read_D();

            bool auxResult;

            auxResult = NumberChecker.IsNumberGreaterThanOtherNumber(num_B, num_C);
            results.Add(auxResult);

            auxResult = NumberChecker.IsNumberGreaterThanOtherNumber(num_D, num_A);
            results.Add(auxResult);

            int sumC_D = MathOperations.Sum(num_C, num_D);
            int sumA_B = MathOperations.Sum(num_A, num_B);

            auxResult = NumberChecker.IsNumberGreaterThanOtherNumber(sumC_D, sumA_B);
            results.Add(auxResult);

            auxResult = NumberChecker.IsNumberPositive(num_C);
            results.Add(auxResult);

            auxResult = NumberChecker.IsNumberPositive(num_D);
            results.Add(auxResult);

            auxResult = NumberChecker.IsNumberEven(num_A);
            results.Add(auxResult);

            CheckResults.CheckIfAllResultsAreTrue(results);

            Console.ReadKey();
        }
Example #12
0
 public void Then_the_result_is_false()
 {
     Assert.That(NumberChecker.TryGetCombinedNumberIfNumbersSumTo2020(new [] { firstNumber, secondNumber, thirdNumber }, out _), Is.False);
 }
Example #13
0
        public override void GenerateBoard(Panel panel)
        {
            GetBoard().SetPanel(panel);

            IGenerator gen  = _factory.CreateGenerator("NativeGenerator");
            int        size = 0;

            switch (GetDifficulty())
            {
            case Difficulty.Beginner:
                size      = 8;
                MineCount = 10;
                break;

            case Difficulty.Intermediate:
                size      = 16;
                MineCount = 40;
                break;

            case Difficulty.Expert:
                size      = 24;
                MineCount = 99;
                break;
            }

            // Create and filter the board
            GetBoard().MakeBoard(size);
            char[,] board = gen.GenerateBoard(size, MineCount);
            ICriteria boardFilter = new SizeChecker(board, GetDifficulty());

            boardFilter = new MinesChecker(boardFilter);
            boardFilter = new NumberChecker(boardFilter);
            board       = boardFilter.Verify();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    Square square;
                    switch (board[i, j])
                    {
                    case 'X':
                        square = new Mine(i, j);
                        break;

                    case '0':
                        square = new EmptySquare(i, j);
                        break;

                    default:
                        square = new NumberSquare(i, j, board[i, j] - '0');
                        break;
                    }

                    GetBoard().AddSquare(square);
                    AddSquareToGame(square);
                    //square.Button.Top += panel.Top;
                    //square.Button.Left += panel.Left;
                    panel.Controls.Add(square.Button);

                    square.Subscribe(this);
                }
            }

            // Start the game
            FlagCount           = MineCount;
            MineCountField.Text = FlagCount.ToString();
            GameTimer           = new GameTimer(TimerField);
            GameTimer.Start();
        }
Example #14
0
 public void Init()
 {
     numberChecker = new NumberChecker();
 }
Example #15
0
 public void Then_the_correct_number_is_not_returned()
 {
     Assume.That(NumberChecker.TryGetCombinedNumberIfNumbersSumTo2020(new [] { firstNumber, secondNumber, thirdNumber }, out var testValue), Is.False);
     Assert.That(testValue, Is.Null);
 }
Example #16
0
 public void Then_the_result_is_true()
 {
     Assume.That(firstNumber + secondNumber + thirdNumber, Is.EqualTo(2020));
     Assert.That(NumberChecker.TryGetCombinedNumberIfNumbersSumTo2020(new [] { firstNumber, secondNumber, thirdNumber }, out _), Is.True);
 }
Example #17
0
 public void Then_the_correct_number_is_returned()
 {
     Assume.That(firstNumber + secondNumber + thirdNumber, Is.EqualTo(2020));
     Assume.That(NumberChecker.TryGetCombinedNumberIfNumbersSumTo2020(new [] { firstNumber, secondNumber, thirdNumber }, out var testValue), Is.True);
     Assert.That(testValue, Is.EqualTo(firstNumber * secondNumber * thirdNumber));
 }