Exemplo n.º 1
0
        public void GetSatisfyingNumbersTest()
        {
            var qs = new Quizzes();

            CollectionAssert
            .AreEqual(new[] { 3, 6, 9, 12, 15, 18 }, qs.GetSatisfyingNumbers(20, n => n % 3 == 0));
        }
Exemplo n.º 2
0
        public async Task AddingHints(ulong id, [Remainder] string url1)
        {
            if (!IsHavingThisRole((SocketGuildUser)Context.User, "Developer") &&
                !IsHavingThisRole((SocketGuildUser)Context.User, "Quiz Manager"))
            {
                return;
            }
            Quiz selected = Quizzes.GetQuiz(id);

            if (selected == null)
            {
                await Context.Channel.SendMessageAsync("`NO QUIZ FOUND WITH THAT ID`");

                return;
            }
            if (selected.Hints.Count >= 3)
            {
                await Context.Channel.SendMessageAsync("`CAN'T ADD MORE HINT`");

                return;
            }

            Quizzes.AddingHints(selected, url1);
            await Context.Channel.SendMessageAsync("`HINT HAS BEEN ADDED`");
        }
        public RoundViewModelTest()
        {
            _quizzes            = GenerateQuizzesList();
            _selectedQuizIndex  = _random.Next(_quizzes.Count);
            _selectedQuiz       = _quizzes[_selectedQuizIndex];
            _selectedRoundIndex = _random.Next(_selectedQuiz.QuizRounds.Count);
            _selectedRound      = _selectedQuiz.QuizRounds[_selectedRoundIndex];

            _quizServiceMock = new Mock <IQuizService>();
            _quizServiceMock.Setup(qS => qS.GetAllQuizzes()).ReturnsAsync(_quizzes);
            _quizServiceMock.Setup(qS => qS.DeleteQuiz(It.IsAny <int>())).ReturnsAsync(true);
            _quizServiceMock.Setup(qS => qS.EditQuiz(It.IsAny <int>(), It.IsAny <Quiz>())).ReturnsAsync(true);
            _roundServiceMock = new Mock <IRoundService>();
            _roundServiceMock.Setup(rS => rS.EditRound(It.IsAny <int>(), It.IsAny <Round>())).ReturnsAsync(true);
            _navigationServiceExMock = new Mock <INavigationServiceEx>();
            _navigationServiceExMock.Setup(nS => nS.GoBack()).Returns(true);
            _navigationServiceExMock.Setup(nS => nS.Navigate(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <NavigationTransitionInfo>())).Returns(true);
            _messengerCacheMock = new Mock <IMessengerCache>();
            _messengerCacheMock.Setup(mC => mC.CachedSelectedQuiz).Returns(_selectedQuiz);
            _messengerCacheMock.Setup(mC => mC.CachedSelectedRound).Returns(_selectedRound);

            _sender = new QuizzenViewModel(_quizServiceMock.Object, _navigationServiceExMock.Object);
            _sender.EditQuizCommand.Execute(_selectedQuizIndex);
            _intermediate = new EditQuizViewModel(_quizServiceMock.Object, _navigationServiceExMock.Object, _messengerCacheMock.Object);
            _intermediate.NavigateToRoundCommand.Execute(_selectedRound);
            _sut = new RoundViewModel(_roundServiceMock.Object, _navigationServiceExMock.Object, _messengerCacheMock.Object);
        }
Exemplo n.º 4
0
        public void AddQuiz(Quizze q)
        {
            List <Quizze> temp = Quizzes.ToList();

            temp.Add(q);
            Quizzes = temp;
        }
Exemplo n.º 5
0
        public async Task AddingDrops(ulong id, ulong idItem)
        {
            if (!IsHavingThisRole((SocketGuildUser)Context.User, "Developer") &&
                !IsHavingThisRole((SocketGuildUser)Context.User, "Quiz Manager"))
            {
                return;
            }
            Quiz selected = Quizzes.GetQuiz(id);

            if (selected == null)
            {
                await Context.Channel.SendMessageAsync("`NO QUIZ FOUND WITH THAT ID`");

                return;
            }
            if (selected.Drop.Count >= 3)
            {
                await Context.Channel.SendMessageAsync("`CAN'T ADD MORE DROPS`");

                return;
            }
            Item drop = Drops.GetSpecificItem(idItem);

            if (drop == null)
            {
                await Context.Channel.SendMessageAsync("`NO ITEM FOUND WITH THAT ID`");

                return;
            }
            Quizzes.AddingDrops(selected, drop);
            await Context.Channel.SendMessageAsync("`DROP HAS BEEN ADDED`");
        }
Exemplo n.º 6
0
        public void LeaveQuiz()
        {
            var player = GetCurrentPlayer();
            var quiz   = GetCurrentQuiz();

            if (quiz == null)
            {
                Clients.Caller.message("You are not in a room");
            }
            else
            {
                // Delete Quiz room if no players are in it
                if (quiz.Players.Count - 1 == 0)
                {
                    Groups.Remove(Context.ConnectionId, quiz.Name);
                    Quizzes.Remove(quiz);
                }
                else
                {
                    quiz.Players.Remove(player);
                    PlayersInLobby(quiz);
                    MessageGroup(player.Name + " left the room", quiz.Name);
                    Groups.Remove(Context.ConnectionId, quiz.Name);
                }

                player.Score = 0;
                player.Ready = false;
                Clients.Caller.reset();
                Clients.Caller.message("Left room '" + quiz.Name + "'");
            }
        }
Exemplo n.º 7
0
        public async Task Answering([Remainder] string answer)
        {
            if (!GlobalVar.QuizHasBeenStarted)
            {
                return;
            }
            if (!IsHavingThisRole((SocketGuildUser)Context.User, "Survivor"))
            {
                return;
            }
            if (UserAccounts.IsDead(Context.User))
            {
                return;
            }
            UserAccount user  = UserAccounts.GetUserAccount(Context.User);
            ulong       id    = GlobalVar.Selected.ID;
            int         point = Quizzes.CheckAnswer(answer, id);

            if (point == 0)
            {
                return;
            }
            await Context.Channel.SendMessageAsync($"{Context.User.Mention} {point} point(s)");

            UserAccounts.TempPoints(user, point);
        }
Exemplo n.º 8
0
 public override Task DivideLine(string line)
 {
     Console.WriteLine($"{DateTime.Now} Thread {Thread.CurrentThread.ManagedThreadId} started job.");
     if (line.Contains(" LOGIN: "******" LOGIN MISC: "))
     {
         LoginMisc.Add(line);
     }
     if (line.Contains(" QUIT MISC: "))
     {
         QuitMisc.Add(line);
     }
     if (line.Contains("TC: [Civilian Workers]"))
     {
         Team.Add(line);
     }
     if (line.Contains(" Hosted Civilian event; "))
     {
         Events.Add(line);
     }
     if (line.Contains(" created a quiz of '"))
     {
         Quizzes.Add(line);
     }
     Console.WriteLine($"{DateTime.Now} Thread {Thread.CurrentThread.ManagedThreadId} ended job.");
     return(Task.CompletedTask);
 }
        public CorrectViewModelTest()
        {
            _teams = GenerateTeamList();
            _enabledTeams = new Teams();

            foreach(Team team in _teams)
            {
                if (team.TeamEnabled)
                {
                    _enabledTeams.Add(team);
                }
            }

            _quizzes = GenerateQuizzesList();
            _rounds = _quizzes.Where(q => q.QuizEnabled).FirstOrDefault().QuizRounds;

            _teamServiceMock = new Mock<ITeamService>();
            _teamServiceMock.Setup(tS => tS.GetAllTeams()).ReturnsAsync(_teams);
            _teamServiceMock.Setup(tS => tS.PatchTeamScore(It.IsAny<int>(), It.IsAny<int>())).ReturnsAsync(true);
            _roundServiceMock = new Mock<IRoundService>();
            _roundServiceMock.Setup(rS => rS.GetAllRoundsByEnabledQuiz()).ReturnsAsync(_rounds);
            _navigationServiceExMock = new Mock<INavigationServiceEx>();

            _sut = new CorrectViewModel(_teamServiceMock.Object, _roundServiceMock.Object, _navigationServiceExMock.Object);
        }
Exemplo n.º 10
0
 public void GetExamFromStringTest()
 {
     var examStr = @"{""Student"" : ""lluis"", ""Score"" : ""9.0""}";
     var qs = new Quizzes();
     var ret = qs.GetExamFromString(examStr);
     Assert.AreEqual("lluis", ret.Student);
     Assert.AreEqual(9.0m, ret.Score);
 }
Exemplo n.º 11
0
 public int GetScore(Quiz which)
 {
     try {
         return(Scores [Quizzes.IndexOf(which)]);
     } catch (IndexOutOfRangeException) {
         return(0);
     }
 }
Exemplo n.º 12
0
        public async Task <IActionResult> SubmitQuiz(long id, [FromBody] QuizModel quizModel)
        {
            if (!await Quizzes.CheckIfQuizExists(id))
            {
                return(NotFound());
            }

            return(Ok(await Quizzes.SubmitQuiz(id, User.Id(), quizModel)));
        }
Exemplo n.º 13
0
        public override int GetHashCode()
        {
            int result = Name.GetHashCode();

            result = 31 * result + Id.GetHashCode();
            result = 31 * result + Theme.GetHashCode();
            result = 31 * result + Quizzes.GetHashCode();
            return(result);
        }
Exemplo n.º 14
0
 public void AddQuiz(string categoryName)
 {
     Quizzes.Add(new Quiz
     {
         Id        = Guid.NewGuid(),
         Category  = categoryName,
         Timestamp = DateTime.Now
     });
 }
Exemplo n.º 15
0
        public void GetExamFromStringTest()
        {
            var examStr = @"{""Student"" : ""lluis"", ""Score"" : ""9.0""}";
            var qs      = new Quizzes();
            var ret     = qs.GetExamFromString(examStr);

            Assert.AreEqual("lluis", ret.Student);
            Assert.AreEqual(9.0m, ret.Score);
        }
Exemplo n.º 16
0
 public void AddQuizPoint(Guid quizId)
 {
     Quizzes.ForEach(q =>
     {
         if (q.Id == quizId)
         {
             q.Points++;
         }
     });
 }
Exemplo n.º 17
0
 public void CompleteQuiz(Guid quizId)
 {
     Quizzes.ForEach(q =>
     {
         if (q.Id == quizId)
         {
             q.IsCompleted = true;
         }
     });
 }
Exemplo n.º 18
0
        public async Task <IActionResult> Update(long id, [FromBody] QuizFormModel model)
        {
            if (!await Quizzes.CheckIfQuizExists(id))
            {
                return(NotFound());
            }
            await Quizzes.Update(id, model);

            return(Ok());
        }
Exemplo n.º 19
0
        public async Task CreateQuiz(bool priv, string name, string max)
        {
            string trimmedName = name == null ? "" : name.Trim();

            if (Quizzes.FirstOrDefault(quiz => quiz.Name == trimmedName) == null)
            {
                int maxPlayers;
                if (trimmedName == "none")
                {
                    Clients.Caller.message("Can not make room with name of 'none'");
                }
                else if (!int.TryParse(max, out maxPlayers))
                {
                    Clients.Caller.message("Room creation failed: max must be an integer");
                }
                else if (maxPlayers < 2)
                {
                    Clients.Caller.message("Room creation failed: maximum players must be greater than 1");
                }
                else
                {
                    var player = GetCurrentPlayer();

                    if (trimmedName == "")
                    {
                        trimmedName = player.Name + "'s room";
                    }
                    else if (trimmedName.Length > 35)
                    {
                        trimmedName = trimmedName.Substring(0, 35);
                    }

                    if (IsInRoom())
                    {
                        LeaveQuiz();
                    }

                    if (maxPlayers > 20)
                    {
                        maxPlayers = 20;
                    }

                    await Groups.Add(Context.ConnectionId, trimmedName);

                    Quizzes.Add(new Quiz(priv, trimmedName, maxPlayers, player));
                    Clients.Caller.message("Room '" + trimmedName + "' created");
                    Clients.Caller.inRoom(true, trimmedName, maxPlayers);
                    PlayersInLobby(GetCurrentQuiz());
                }
            }
            else
            {
                Clients.Caller.message("Room already exists");
            }
        }
Exemplo n.º 20
0
        public async Task <IActionResult> Remove(long id)
        {
            if (!await Quizzes.CheckIfQuizExists(id))
            {
                return(NotFound());
            }

            await Quizzes.Remove(id);

            return(Ok());
        }
Exemplo n.º 21
0
        public async Task <IActionResult> Fetch(long id)
        {
            var quiz = await Quizzes.Fetch(id);

            if (quiz == null)
            {
                return(NotFound());
            }

            return(Ok(quiz));
        }
Exemplo n.º 22
0
        public QuizzenViewModelTest()
        {
            _quizzes = GenerateQuizzesList();

            _quizServiceMock = new Mock <IQuizService>();
            _quizServiceMock.Setup(qS => qS.GetAllQuizzes()).ReturnsAsync(_quizzes);
            _navigationServiceExMock = new Mock <INavigationServiceEx>();
            _navigationServiceExMock.Setup(nS => nS.Navigate(It.IsAny <string>(), It.IsAny <object>(), It.IsAny <NavigationTransitionInfo>())).Returns(true);

            _sut = new QuizzenViewModel(_quizServiceMock.Object, _navigationServiceExMock.Object);
        }
Exemplo n.º 23
0
        public async Task <ActionResult> Put(int id, [FromBody] Quizzes quiz)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            _context.Entry(quiz).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok(quiz));
        }
Exemplo n.º 24
0
        public async Task <IActionResult> Get(long id)
        {
            var result = await Quizzes.GetFull(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(Mapper.Map <QuizModel>(result)));
        }
Exemplo n.º 25
0
 public Quiz MapQuiz(Quizzes quiz)
 {
     return(quiz == null ? null : new Quiz
     {
         Active = quiz.Active,
         EndTime = quiz.EndTime,
         ID = quiz.Id,
         StartTime = quiz.StartTime,
         Title = quiz.Title,
         Type = quiz.Type
     });
 }
Exemplo n.º 26
0
        public void SetScore(Quiz which, bool correctlySolved)
        {
            var index = Quizzes.IndexOf(which);

            Log.Debug(TAG, string.Format("Setting score for {0} with index {1}", which, index));
            if (index == -1)
            {
                return;
            }

            Scores [index] = correctlySolved ? GoodScore : NoScore;
        }
Exemplo n.º 27
0
        public void Parse1to3NumberTest()
        {
            var strInput =
                @"
    _  _ 
  | _| _|
  ||_  _|
";
            var qs = new Quizzes();

            Assert.AreEqual(123, qs.ParseNumber(strInput));
        }
Exemplo n.º 28
0
        public void ParseBoardError()
        {
            var strInput =
                @"
   | O |
-----------
   |
-----------
   | O | O 
";
            var qs  = new Quizzes();
            var ret = qs.ParseBoard(strInput);
        }
Exemplo n.º 29
0
        public void ParseNumberErrorTest()
        {
            // HINT: Look at the last digit. It may look like a 3 but it is not well formed!
            var strInput =
                @"
    _  _ 
  | _| _ 
  ||_  _|
";
            var qs = new Quizzes();

            Assert.AreEqual(123, qs.ParseNumber(strInput));
        }
Exemplo n.º 30
0
        public bool QuizAnswer(string Answer, int index, out string message)
        {
            NeoQuizValue value = Quizzes.ElementAt(index) as NeoQuizValue;

            if (!value.answers.Contains(Answer))
            {
                message = "틀렸습니다.";
                return(false);
            }

            message = value.answers[0] + Environment.NewLine + "정답입니다!";
            return(true);
        }
Exemplo n.º 31
0
 public void GenerateBoard1()
 {
     var strInput = " o x    x";
     var qs = new Quizzes();
     Assert.AreEqual(@"
        | O |
     -----------
      X |   |
     -----------
        |   | X
     "
     , qs.GenerateBoard(strInput));
 }
Exemplo n.º 32
0
 public void GenerateBoard3()
 {
     var strInput = "ooxoxoxoo";
     var qs = new Quizzes();
     Assert.AreEqual(@"
      O | O | X
     -----------
      O | X | O
     -----------
      X | O | O
     "
     , qs.GenerateBoard(strInput));
 }
Exemplo n.º 33
0
        public async Task ShowAllQuiz()
        {
            if (!IsHavingThisRole((SocketGuildUser)Context.User, "Developer") &&
                !IsHavingThisRole((SocketGuildUser)Context.User, "Quiz Manager"))
            {
                return;
            }
            string formattedText = "";

            if (Quizzes.GetQuizzes().Count == 0)
            {
                await Context.Channel.SendMessageAsync("`No Quiz Has Been Made, Be The First to make One`");

                return;
            }
            foreach (var q in Quizzes.GetQuizzes())
            {
                formattedText += $"Quiz No-{q.ID}:\nDifficulty:{q.Difficulty}\n";
                switch (q.Type)
                {
                case "image":
                    formattedText += $"Type:Image\n";
                    break;

                case "sv":
                    formattedText += $"Type:Shadowverse Pic\n";
                    break;

                case "ost":
                    formattedText += $"Type:OST(OP/ED)\n";
                    break;

                case "bonus":
                    formattedText += $"Type:Bonus\n";
                    break;

                case "voice-sv":
                    formattedText += $"Type:Shadowverse Voice\n";
                    break;
                }
                formattedText += $"Right Answer : {q.RightAnswer}\n";
                formattedText += $"{q.URL}\n\n";
                if (formattedText.Length + 200 > 2048)
                {
                    await Context.Channel.SendMessageAsync($"{formattedText}");

                    formattedText = "";
                }
            }
            await Context.Channel.SendMessageAsync($"{formattedText}");
        }
Exemplo n.º 34
0
 public void MultiplicationTableTest()
 {
     var qs = new Quizzes();
     var table8 = new[]
                      {
                          1, 2, 3, 4, 5, 6, 7, 8,
                          2, 4, 6, 8, 10, 12, 14, 16,
                          3, 6, 9, 12, 15, 18, 21, 24,
                          4, 8, 12, 16, 20, 24, 28, 32,
                          5, 10, 15, 20, 25, 30, 35, 40,
                          6, 12, 18, 24, 30, 36, 42, 48,
                          7, 14, 21, 28, 35, 42, 49, 56,
                          8, 16, 24, 32, 40, 48, 56, 64
                      };
     CollectionAssert.AreEqual(table8, qs.MultiplicationTable(8));
 }
Exemplo n.º 35
0
 public void OrderByAvgScoresDescendingTest()
 {
     var exams =
         new[]
             {
                 new Exam("anna", 9.5m), new Exam("anna", 7.0m), new Exam("anna", 8.0m),
                 new Exam("marcel", 7.0m), new Exam("marcel", 5.0m), new Exam("marcel", 8.0m),
                 new Exam("lluis", 9.0m), new Exam("lluis", 9.0m), new Exam("lluis", 9.0m),
                 new Exam("ari", 3.0m), new Exam("ari", 4.0m), new Exam("ari", 5.0m),
             };
     var qs = new Quizzes();
     CollectionAssert.AreEqual(new[] {"lluis", "anna", "marcel", "ari"}
                               , qs.OrderByAvgScoresDescending(exams));
 }
Exemplo n.º 36
0
 public void GenerateBoardError()
 {
     var strInput = "olakeaseo";
     var qs = new Quizzes();
     var ret = qs.GenerateBoard(strInput);
 }
Exemplo n.º 37
0
 public void ReverseStringTest()
 {
     var qs = new Quizzes();
     Assert.AreEqual("hola",qs.ReverseString("aloh"));
 }
Exemplo n.º 38
0
 public void PostfixCalcError()
 {
     var qs = new Quizzes();
     Assert.AreEqual(106, qs.PostFixCalc("5 5 + ja10ja * 2r4 + + +"));
 }
Exemplo n.º 39
0
 public void PostfixCalc1()
 {
     var qs = new Quizzes();
     Assert.AreEqual(100, qs.PostFixCalc("5 5 + 10 *"));
 }
Exemplo n.º 40
0
 public void FormatHexTest()
 {
     var qs = new Quizzes();
     Assert.AreEqual("FFCC00", qs.FormatHex(255, 204, 0), true);
 }
Exemplo n.º 41
0
 public void ParseNumberErrorTest()
 {
     // HINT: Look at the last digit. It may look like a 3 but it is not well formed!
     var strInput =
         @"
     _  _
       | _| _
       ||_  _|
     ";
     var qs = new Quizzes();
     Assert.AreEqual(123, qs.ParseNumber(strInput));
 }
Exemplo n.º 42
0
 public void GetOddNumbersTest()
 {
     var qs = new Quizzes();
     CollectionAssert.AreEqual(new[] { 1, 3, 5, 7, 9 }, qs.GetOddNumbers(10));
 }
Exemplo n.º 43
0
 public void Sum73FromStringTest()
 {
     var qs = new Quizzes();
     Assert.AreEqual(73, qs.SumString("5, 23; 42  \r\n\t 3 0"));
 }
Exemplo n.º 44
0
 public void GetSatisfyingNumbersTest()
 {
     var qs = new Quizzes();
     CollectionAssert
         .AreEqual(new[] {3, 6, 9, 12, 15, 18}, qs.GetSatisfyingNumbers(20, n => n%3 == 0));
 }
Exemplo n.º 45
0
 public void ParseBoard()
 {
     var strInput =
         @"
        | O | X
     -----------
        | X | O
     -----------
        | O | O
     ";
     var qs = new Quizzes();
     Assert.AreEqual(" ox xo oo", qs.ParseBoard(strInput));
 }
Exemplo n.º 46
0
 public void ParseBoardError()
 {
     var strInput =
         @"
        | O |
     -----------
        |
     -----------
        | O | O
     ";
     var qs = new Quizzes();
     var ret = qs.ParseBoard(strInput);
 }
Exemplo n.º 47
0
 public void Parse1to3NumberTest()
 {
     var strInput =
         @"
     _  _
       | _| _|
       ||_  _|
     ";
     var qs = new Quizzes();
     Assert.AreEqual(123, qs.ParseNumber(strInput));
 }
Exemplo n.º 48
0
 public void GetSecondBiggerNumberTest()
 {
     var qs = new Quizzes();
     Assert.AreEqual(8, qs.GetSecondGreatestNumber(new[] {1, 3, 8, 10, 5, 7}));
 }
Exemplo n.º 49
0
 public void FibonacciTest()
 {
     var qs = new Quizzes();
     Assert.AreEqual(8, qs.Fib(6));
 }