Beispiel #1
0
        public void GetCandidatesCount_should_return_correct_value_if_there_are_multiple_candidates()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.Five);
            sut.AddCandidate(_position, Value.One);

            sut.GetCandidatesCount(_position).Should().Be(2);
        }
Beispiel #2
0
        public void AddCandidate_should_set_candidate_if_called_multiple_times_with_same_value()
        {
            var sut      = new Grid();
            var position = _position;

            sut.AddCandidate(position, Value.One);
            sut.AddCandidate(position, Value.One);
            sut.AddCandidate(position, Value.One);

            sut.GetCandidatesCount(position).Should().Be(1);
            sut.GetCandidates(position).Should().Be(Candidates.One);
        }
Beispiel #3
0
        public void ClearAllCandidates_should_remove_candidates_from_position()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.One);
            sut.AddCandidate(_position, Value.Five);

            sut.ClearCandidates(_position);

            sut.GetCandidates(_position).Should().Be(Candidates.None);
            sut.GetCandidatesCount(_position).Should().Be(0);
        }
Beispiel #4
0
        public void Restart_should_remove_candidates()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.One);
            sut.AddCandidate(_position, Value.Two);
            sut.AddCandidate(_position, Value.Three);

            sut.Restart();

            sut.GetCandidatesCount(_position).Should().Be(0);
            sut.GetCandidates(_position).Should().Be(Candidates.None);
        }
Beispiel #5
0
        public void AddCandidate_multiple_calls_should_combine_various_candidates()
        {
            var sut      = new Grid();
            var position = _position;

            sut.AddCandidate(position, Value.One);
            sut.AddCandidate(position, Value.Five);
            sut.AddCandidate(position, Value.Eight);

            sut.GetCandidatesCount(position).Should().Be(3);
            sut.HasCandidate(position, Value.One).Should().BeTrue();
            sut.HasCandidate(position, Value.Five).Should().BeTrue();
            sut.HasCandidate(position, Value.Eight).Should().BeTrue();
        }
Beispiel #6
0
        public void Clone_should_have_same_candidates()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.One);
            sut.AddCandidate(_position, Value.Two);
            sut.AddCandidate(_position, Value.Three);

            var actual = sut.Clone();

            actual.GetCandidatesCount(_position).Should().Be(3);
            actual.HasCandidate(_position, Value.One).Should().BeTrue();
            actual.HasCandidate(_position, Value.Two).Should().BeTrue();
            actual.HasCandidate(_position, Value.Three).Should().BeTrue();
        }
        private void SetValue(Grid grid, BitArray bitArray, Position pos)
        {
            // IsGiven?
            if (bitArray.Get(_counter++))
            {
                grid.SetValue(pos, GetValue(bitArray));
                grid.SetIsGiven(pos, true);
            }
            // IsInput?
            else if (bitArray.Get(_counter++))
            {
                grid.SetIsGiven(pos, false);
                grid.SetValue(pos, GetValue(bitArray));
            }
            else
            {
                grid.SetIsGiven(pos, false);
                grid.SetValue(pos, Value.None);

                foreach (var value in Value.NonEmpty)
                {
                    if (bitArray.Get(_counter++))
                    {
                        grid.AddCandidate(pos, value);
                    }
                }
            }
        }
Beispiel #8
0
        public void ClearCandidatesEverywhere_should_remove_all_candidates_from_all_positions()
        {
            var sut        = new Grid();
            var position00 = new Position(0, 0);
            var position88 = new Position(8, 8);

            sut.AddCandidate(position00, Value.One);
            sut.AddCandidate(position00, Value.Two);
            sut.AddCandidate(position88, Value.One);
            sut.AddCandidate(position88, Value.Two);

            sut.ClearCandidatesEverywhere();

            sut.GetCandidates(position00).Should().Be(Candidates.None);
            sut.GetCandidates(position88).Should().Be(Candidates.None);
        }
Beispiel #9
0
        public void HasCandidate_should_return_true_only_for_present_candidates()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.One);
            sut.AddCandidate(_position, Value.Two);

            sut.HasCandidate(_position, Value.One).Should().BeTrue();
            sut.HasCandidate(_position, Value.Two).Should().BeTrue();
            sut.HasCandidate(_position, Value.Three).Should().BeFalse();
            sut.HasCandidate(_position, Value.Four).Should().BeFalse();
            sut.HasCandidate(_position, Value.Five).Should().BeFalse();
            sut.HasCandidate(_position, Value.Six).Should().BeFalse();
            sut.HasCandidate(_position, Value.Seven).Should().BeFalse();
            sut.HasCandidate(_position, Value.Eight).Should().BeFalse();
            sut.HasCandidate(_position, Value.Nine).Should().BeFalse();
        }
Beispiel #10
0
        public void AddCandidate_should_set_candidate()
        {
            var sut      = new Grid();
            var position = _position;

            sut.AddCandidate(position, Value.One);

            sut.GetCandidatesCount(position).Should().Be(1);
            sut.GetCandidates(position).Should().Be(Candidates.One);
        }
Beispiel #11
0
        public void SetValue_should_remove_candidates()
        {
            var sut      = new Grid();
            var position = _position;

            sut.AddCandidate(position, Value.One);

            sut.SetValue(position, Value.Nine);

            sut.GetCandidates(position).Should().Be(Candidates.None);
        }
Beispiel #12
0
        public void RemoveCandidate_should_remove_existing_candidate()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.One);

            sut.RemoveCandidate(_position, Value.One);

            sut.GetCandidates(_position).Should().Be(Candidates.None);
            sut.GetCandidatesCount(_position).Should().Be(0);
        }
Beispiel #13
0
        public void ToggleCandidate_should_turn_off_candidate_if_it_is_present()
        {
            var sut = new Grid();

            sut.AddCandidate(_position, Value.One);

            sut.ToggleCandidate(_position, Value.One);

            sut.GetCandidatesCount(_position).Should().Be(0);
            sut.GetCandidates(_position).Should().Be(Candidates.None);
        }