예제 #1
0
        static void Main(string[] args)
        {
            int currCount = 0;

            var Buzz     = new Buzz();
            var Fizz     = new Fizz();
            var FizzBuzz = new FizzBuzz();

            int fizzAmt     = Fizz.SetFizz();
            int buzzAmt     = Buzz.SBuzz();
            int fizzBuzzAmt = FizzBuzz.SetFizzBuzz();

            while (FizzBuzz.fizzBuzzCount < fizzBuzzAmt)
            {
                Fizz.RunFizz(currCount, fizzAmt);
                Buzz.RBuzz(currCount, buzzAmt);
                FizzBuzz.RunFizzBuzz(currCount, fizzAmt, buzzAmt);

                currCount++;
            }

            Console.WriteLine("Fizz: " + Fizz.fizzCount);
            Console.WriteLine("Buzz: " + Buzz.buzzCount);
            Console.WriteLine("FizzBuzz: " + FizzBuzz.fizzBuzzCount);
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] GameSession gameSession)
        {
            SqlConnectionString sqlConnectionString = new SqlConnectionString();
            string connectionString = sqlConnectionString.GetSqlConnectionString();

            Question questionHelper = new Question()
            {
                SqlConnectionString = connectionString
            };

            User userHelper = new User()
            {
                SqlConnectionString = connectionString
            };

            JWT jwtHelper = new JWT();

            Buzz buzzHelper = new Buzz()
            {
                SqlConnectionString = connectionString
            };

            int user = jwtHelper.GetUserFromJWT(gameSession.JWT);

            Question.QuestionStatus questionStatus =
                await questionHelper.GetQuestionStatusFromUserAsync(jwtHelper.GetUserFromJWT(gameSession.JWT));

            await buzzHelper.BuzzAsync(user, questionStatus.question);

            await _hubContext.Clients.All.SendAsync(
                $"User{await userHelper.GetAlexFromQuestionAsync(questionStatus.question)}",
                await userHelper.GetUserNameFromUserAsync(user));

            return(new OkObjectResult(JsonConvert.SerializeObject(new { Success = true })));
        }
예제 #3
0
        public void ConcreteImplementation()
        {
            // Create your concrete implementation
            var fizz = new Fizz(3);
            var buzz = new Buzz(5);

            // Set it as the implementation of an interface
            _moq.Use <IFizz>(fizz);
            _moq.Create <FizzBuzzGame>().Fizz.Should().BeSameAs(fizz);

            // Or use for all interfaces
            _moq.Use(buzz).ForAllImplementedInterfaces();
            _moq.Create <FizzBuzzGame>().Buzz.Should().BeSameAs(buzz);

            // Allow you to set a default value for value types
            _moq.Use(25);
            _moq.Create <Fizz>().Divisor.Should().Be(25);

            // Allow you to set a default value for reference types
            _moq.Use("GitHub");
            _moq.Create <StringCtor>().Text.Should().Be("GitHub");

            // ### Shortcuts
            // Shortcut for creating a concrete type, and using this instance for all implemented interfaces.
            // e.g. syntactic sugar for _moq.Use(_moq.Create<Leaf>).ForAllImplementedInterfaces()
            var leaf = _moq.Use <Leaf>();

            _moq.Create <Branch>().Leaf.Should().BeSameAs(leaf);
        }
예제 #4
0
        public Buzz Create(Buzz b)
        {
            Buzz buzz = Buzzes.Add(b);

            nest.SaveChanges();
            return(buzz);
        }
예제 #5
0
파일: Play.cs 프로젝트: JaehoonHyun/tdd
        public override int GetHashCode()
        {
            int hash = 1;

            if (buzz_ != null)
            {
                hash ^= Buzz.GetHashCode();
            }
            if (Where.Length != 0)
            {
                hash ^= Where.GetHashCode();
            }
            if (Who.Length != 0)
            {
                hash ^= Who.GetHashCode();
            }
            if (How.Length != 0)
            {
                hash ^= How.GetHashCode();
            }
            if (What.Length != 0)
            {
                hash ^= What.GetHashCode();
            }
            if (Why.Length != 0)
            {
                hash ^= Why.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #6
0
        public void OnlyOneBuzzHandledWhenQueueDisabled()
        {
            Buzz lateBuzz = new Buzz()
            {
                PlayerDisplayName = "Late",
                TeamId            = "743",
                Timestamp         = DateTime.Now,
                UserId            = DefaultBuzz.UserId + 1
            };

            TossupBonusPhaseState phaseState = new TossupBonusPhaseState(disableBuzzQueue: true);

            Assert.IsFalse(phaseState.HasBonus, "We shouldn't have a bonus until a correct buzz");
            Assert.AreEqual(PhaseStage.Tossup, phaseState.CurrentStage, "We should be in the tossup phase");

            phaseState.AddBuzz(DefaultBuzz);
            phaseState.AddBuzz(lateBuzz);

            Assert.IsTrue(phaseState.TryScoreBuzz(0), "Scoring the buzz should succeed");
            Assert.IsFalse(
                phaseState.TryGetNextPlayer(out _), "There shouldn't be another player after the incorrect buzz");
            Assert.IsFalse(phaseState.HasBonus, "We should still be on the tossup phase");

            phaseState.AddBuzz(lateBuzz);
            Assert.IsTrue(
                phaseState.TryGetNextPlayer(out _), "There should be a player after buzzing in again");
            Assert.IsTrue(phaseState.TryScoreBuzz(10), "Scoring the buzz the second time should succeed");
            Assert.AreEqual(PhaseStage.Bonus, phaseState.CurrentStage, "We should be in the bonus phase");
        }
예제 #7
0
        public void Delete(int id)
        {
            Buzz buzz = Buzzes.Find(id);

            if (buzz == null)
            {
                return;
            }
            nest.Buzzes.Remove(buzz);
            nest.SaveChanges();
        }
        public void UndoScoredTossup()
        {
            TossupBonusPhaseState phaseState = new TossupBonusPhaseState();

            phaseState.AddBuzz(DefaultBuzz);
            Assert.IsTrue(phaseState.TryScoreBuzz(-5), "Scoring the first buzz should succeed");

            Assert.IsTrue(
                phaseState.AlreadyBuzzedPlayerIds.Contains(DefaultBuzz.UserId),
                "Default player not in the list of already buzzed players");
            Assert.AreEqual(1, phaseState.Actions.Count, "Unexpected number of buzzes recorded");

            ulong  secondBuzzPlayerId = DefaultBuzz.UserId + 1;
            string secondTeamId       = $"{DefaultBuzz.TeamId}1";
            Buzz   incorrectBuzz      = new Buzz()
            {
                TeamId            = secondTeamId,
                PlayerDisplayName = "Bob",
                UserId            = secondBuzzPlayerId,
                Timestamp         = DateTime.Now + TimeSpan.FromSeconds(1)
            };

            phaseState.AddBuzz(incorrectBuzz);
            Assert.IsTrue(phaseState.TryScoreBuzz(0), "Scoring the second buzz should succeed");
            Assert.IsTrue(
                phaseState.AlreadyBuzzedPlayerIds.Contains(secondBuzzPlayerId),
                "Second player not in the list of already buzzed players");
            Assert.AreEqual(2, phaseState.Actions.Count, "Unexpected number of buzzes recorded after the second buzz");

            phaseState.Undo(out ulong?userId);
            Assert.AreEqual(secondBuzzPlayerId, userId, "Unexpected userId returned by Undo");
            Assert.IsTrue(
                phaseState.AlreadyScoredTeamIds.Contains(DefaultBuzz.TeamId),
                "Default player not in the list of already scored teams after the first undo");
            Assert.IsFalse(
                phaseState.AlreadyScoredTeamIds.Contains(secondTeamId),
                "Second player not in the list of already scored teams after the first undo");
            Assert.AreEqual(1, phaseState.Actions.Count, "Unexpected number of buzzes recorded after the first undo");

            phaseState.Undo(out userId);
            Assert.AreEqual(DefaultBuzz.UserId, userId, "Unexpected userId returned by Undo");
            Assert.IsFalse(
                phaseState.AlreadyScoredTeamIds.Contains(DefaultBuzz.TeamId),
                "Default player not in the list of already scored teams after the second undo");
            Assert.AreEqual(0, phaseState.Actions.Count, "Unexpected number of buzzes recorded after the second undo");
        }
    private static void CachedFizzBuzz(FizzBuzzSolver fb)
    {
        var fizzbuzzArray = new IFizzBuzz[fb.FizzBuzz];

        for (int i = 0; i < fb.FizzBuzz - 1; i++)
        {
            int s = i + 1;
            if (s % fb.Fizz == 0)
            {
                fizzbuzzArray[i] = new Fizz();
                Console.WriteLine("Fizz");
            }
            else
            if (s % fb.Buzz == 0)
            {
                fizzbuzzArray[i] = new Buzz();
                Console.WriteLine("Buzz");
            }
            else
            {
                fizzbuzzArray[i] = new NullFizzBuzz();
                Console.WriteLine(s);
            }
        }
        fizzbuzzArray[fb.FizzBuzz - 1] = new FizzBuzz();
        Console.WriteLine("FizzBuzz");
        NullFizzBuzz.value = fb.FizzBuzz;
        for (int j = 1; j < fb.Quotient; j++)
        {
            for (int i = 0; i < fb.FizzBuzz; i++)
            {
                NullFizzBuzz.value++;
                Console.WriteLine(fizzbuzzArray[i]);
            }
        }
        for (int i = 0; i < fb.Remainder; i++)
        {
            NullFizzBuzz.value++;
            Console.WriteLine(fizzbuzzArray[i]);
        }
    }
예제 #10
0
        public void BuzzTEst()
        {
            List <string> list = new List <string>();

            list.Add("1");
            list.Add("5");
            list.Add("7");
            list.Add("10");
            List <string> expectedlist = new List <string>();

            expectedlist.Add("1");
            expectedlist.Add("Buzz");
            expectedlist.Add("7");
            expectedlist.Add("Buzz");
            var newlist = new Buzz().swap(list);

            for (int i = 0; i < expectedlist.Count; i++)
            {
                Assert.AreEqual(expectedlist[i], newlist[i]);
            }
        }
예제 #11
0
        public void ConcreteImplementation()
        {
            // Create your concrete implementation
            var fizz = new Fizz(3);
            var buzz = new Buzz(5);

            // Set it as the implementation of an interface
            _moq.Use <IFizz>(fizz);
            _moq.Create <FizzBuzzGame>().Fizz.Should().BeSameAs(fizz);

            // Or use for all interfaces
            _moq.Use(buzz).ForAllImplementedInterfaces();
            _moq.Create <FizzBuzzGame>().Buzz.Should().BeSameAs(buzz);

            // Allow you to set a default value for value types
            _moq.Use(25);
            _moq.Create <Fizz>().Divisor.Should().Be(25);

            // Allow you to set a default value for reference types
            _moq.Use("GitHub");
            _moq.Create <StringCtor>().Text.Should().Be("GitHub");
        }
예제 #12
0
파일: Play.cs 프로젝트: JaehoonHyun/tdd
 public void MergeFrom(BuzzPlay other)
 {
     if (other == null)
     {
         return;
     }
     if (other.buzz_ != null)
     {
         if (buzz_ == null)
         {
             Buzz = new global::V1Advanced.Buzz();
         }
         Buzz.MergeFrom(other.Buzz);
     }
     if (other.Where.Length != 0)
     {
         Where = other.Where;
     }
     if (other.Who.Length != 0)
     {
         Who = other.Who;
     }
     if (other.How.Length != 0)
     {
         How = other.How;
     }
     if (other.What.Length != 0)
     {
         What = other.What;
     }
     if (other.Why.Length != 0)
     {
         Why = other.Why;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
예제 #13
0
        public void Should_be_return_false_when_value_is_not_multiple_of_three(int value)
        {
            var buzz = new Buzz();

            Assert.IsFalse(buzz.IsValid(value));
        }
예제 #14
0
        public void BuzzStringForNumberTest(int number, string expectResult)
        {
            var result = Buzz.FormatNumber(number);

            Assert.Equal(result, expectResult);
        }
예제 #15
0
 public ScoreAction(Buzz buzz, int score)
 {
     this.Buzz  = buzz;
     this.Score = score;
 }
예제 #16
0
        public void Condition_Should_Return_False_When_Number_Is_Not_A_Multiple_Of_5(int number)
        {
            var classUnderTest = new Buzz();

            Assert.False(classUnderTest.Condition(number));
        }
예제 #17
0
        public void Should_be_return_Buzz_when_value_is_not_multiple_of_three(int value)
        {
            var buzz = new Buzz();

            Assert.AreEqual(buzz.GetValue(value), "Buzz");
        }
예제 #18
0
        public void FilteredResult_Should_Return_Buzz()
        {
            var classUnderTest = new Buzz();

            Assert.That(classUnderTest.FilteredOutput, Is.EqualTo("Buzz"));
        }
예제 #19
0
        public void Should_be_return_a_empty_when_value_is_not_multiple_of_three(int value)
        {
            var buzz = new Buzz();

            Assert.AreEqual(buzz.GetValue(value), string.Empty);
        }