public void CanCreateBinarySearchEngine()
        {
            const int minimumNumber = 0;
            const int maximumNumber = 1;

            var engine = new BinarySearchEngine(minimumNumber, maximumNumber);

            Assert.NotNull(engine);
        }
Пример #2
0
        public void TestBinarySearch4()
        {
            BinarySearchEngine engine = new BinarySearchEngine();

            int[] array  = new int[] { 1, 2, 3, 4 };
            bool  result = engine.Search(array, -1);

            Assert.AreEqual(false, result);
        }
        public void CanFindExpectedGuess()
        {
            const int minimumNumber = 0;
            const int maximumNumber = 1000;
            const int expectedGuess = 500;

            var engine      = new BinarySearchEngine(minimumNumber, maximumNumber);
            var actualGuess = engine.Guess;

            Assert.Equal(expectedGuess, actualGuess);
        }
        public void CanHandleGuessingWithBinarySearchEngine()
        {
            const int minimumNumber = 0;
            const int maximumNumber = 1000;
            const int expectedGuess = 500;

            var searchEngine   = new BinarySearchEngine(minimumNumber, maximumNumber);
            var displayHandler = new Mock <IDisplayHandler>().Object;

            var handler     = new GuessHandler(searchEngine, displayHandler);
            var actualGuess = handler.HandleGuess(minimumNumber, maximumNumber);

            Assert.Equal(expectedGuess, actualGuess);
        }
        /// <summary>
        ///     Initializes all of the components.
        /// </summary>
        private void Initialize()
        {
            _searchEngine = new BinarySearchEngine(_minimumNumber, _maximumNumber);
            _match        = new MatchFacade(MaximumRounds);
            _gameState    = GameState.Start;

            _displayHandler       = new DisplayHandler();
            _computerChosenNumber = new NumberPicker(_displayHandler, _maximumNumber, _minimumNumber);

            // Need to set on click events prior to hiding the user interface
            var attemptGuess = new AttemptGuess(_displayHandler, _computerChosenNumber);

            attemptGuess.SetOnClickForAttemptGuess();

            _displayHandler.HideUserInterface();

            _guessHandler  = new GuessHandler(_searchEngine, _displayHandler);
            _inputListener = new InputListener();
            _inputHandler  = new InputHandler(_displayHandler, _inputListener);
        }
 public void BinarySearchTest_WithNullValue()
 => Assert.Throws <ArgumentNullException>(() => BinarySearchEngine.BinarySearch(new string[] { "1", "2", "4" }, null));
 public void BinarySearchTest_WithNullArray()
 => Assert.Throws <ArgumentNullException>(() => BinarySearchEngine.BinarySearch(null, 4));
 public int?BinarySearchTest(int[] array, int value)
 => BinarySearchEngine.BinarySearch(array, value);