Esempio n. 1
0
        public void TestApplyApproachRateQueries()
        {
            const string query          = "ar>=9 difficult";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("difficult", filterCriteria.SearchText.Trim());
            Assert.AreEqual(1, filterCriteria.SearchTerms.Length);
            Assert.IsNotNull(filterCriteria.ApproachRate.Min);
            Assert.Greater(filterCriteria.ApproachRate.Min, 8.9f);
            Assert.Less(filterCriteria.ApproachRate.Min, 9.0f);
            Assert.IsNull(filterCriteria.ApproachRate.Max);
        }
Esempio n. 2
0
        public void TestApplyDrainRateQueriesByDrKeyword()
        {
            const string query          = "dr>2 quite specific dr<:6";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("quite specific", filterCriteria.SearchText.Trim());
            Assert.AreEqual(2, filterCriteria.SearchTerms.Length);
            Assert.Greater(filterCriteria.DrainRate.Min, 2.0f);
            Assert.Less(filterCriteria.DrainRate.Min, 2.1f);
            Assert.Greater(filterCriteria.DrainRate.Max, 6.0f);
            Assert.Less(filterCriteria.DrainRate.Min, 6.1f);
        }
Esempio n. 3
0
        public void TestApplyStarQueries(string variant)
        {
            string query          = $"{variant}<4 easy";
            var    filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("easy", filterCriteria.SearchText.Trim());
            Assert.AreEqual(1, filterCriteria.SearchTerms.Length);
            Assert.IsNotNull(filterCriteria.StarDifficulty.Max);
            Assert.Greater(filterCriteria.StarDifficulty.Max, 3.99d);
            Assert.Less(filterCriteria.StarDifficulty.Max, 4.00d);
            Assert.IsNull(filterCriteria.StarDifficulty.Min);
        }
Esempio n. 4
0
        public void TestApplyStatusQueries()
        {
            const string query          = "I want the pp status=ranked";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("I want the pp", filterCriteria.SearchText.Trim());
            Assert.AreEqual(4, filterCriteria.SearchTerms.Length);
            Assert.AreEqual(BeatmapOnlineStatus.Ranked, filterCriteria.OnlineStatus.Min);
            Assert.IsTrue(filterCriteria.OnlineStatus.IsLowerInclusive);
            Assert.AreEqual(BeatmapOnlineStatus.Ranked, filterCriteria.OnlineStatus.Max);
            Assert.IsTrue(filterCriteria.OnlineStatus.IsUpperInclusive);
        }
Esempio n. 5
0
        public void TestApplyDivisorQueries()
        {
            const string query          = "that's a time signature alright! divisor:12";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("that's a time signature alright!", filterCriteria.SearchText.Trim());
            Assert.AreEqual(5, filterCriteria.SearchTerms.Length);
            Assert.AreEqual(12, filterCriteria.BeatDivisor.Min);
            Assert.IsTrue(filterCriteria.BeatDivisor.IsLowerInclusive);
            Assert.AreEqual(12, filterCriteria.BeatDivisor.Max);
            Assert.IsTrue(filterCriteria.BeatDivisor.IsUpperInclusive);
        }
Esempio n. 6
0
        public void TestApplyBPMQueries()
        {
            const string query          = "bpm>:200 gotta go fast";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("gotta go fast", filterCriteria.SearchText.Trim());
            Assert.AreEqual(3, filterCriteria.SearchTerms.Length);
            Assert.IsNotNull(filterCriteria.BPM.Min);
            Assert.Greater(filterCriteria.BPM.Min, 199.99d);
            Assert.Less(filterCriteria.BPM.Min, 200.00d);
            Assert.IsNull(filterCriteria.BPM.Max);
        }
Esempio n. 7
0
        public void TestApplyOverallDifficultyQueries()
        {
            const string query          = "od>4 easy od<8";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("easy", filterCriteria.SearchText.Trim());
            Assert.AreEqual(1, filterCriteria.SearchTerms.Length);
            Assert.Greater(filterCriteria.OverallDifficulty.Min, 4.0);
            Assert.Less(filterCriteria.OverallDifficulty.Min, 4.1);
            Assert.Greater(filterCriteria.OverallDifficulty.Max, 7.9);
            Assert.Less(filterCriteria.OverallDifficulty.Max, 8.0);
        }
Esempio n. 8
0
        public void TestApplyDoubleConditionQueries()
        {
            const string query          = "give me maps with 6<stars<8 please";
            var          filterCriteria = new FilterCriteria();

            FilterQueryParser.ApplyQueries(filterCriteria, query);
            Assert.AreEqual("give me maps with  please", filterCriteria.SearchText.Trim());
            Assert.AreEqual(5, filterCriteria.SearchTerms.Length);
            Assert.IsNotNull(filterCriteria.StarDifficulty.Max);
            Assert.Greater(filterCriteria.StarDifficulty.Max, 7.99d);
            Assert.Less(filterCriteria.StarDifficulty.Max, 8.00d);
            Assert.IsNotNull(filterCriteria.StarDifficulty.Min);
            Assert.Greater(filterCriteria.StarDifficulty.Min, 6.00d);
            Assert.Less(filterCriteria.StarDifficulty.Min, 6.10d);
        }
Esempio n. 9
0
        public async Task <ActionResult <IEnumerable <ProjectTask> > > Filter(string query)
        {
            var tasksResult = await _taskRepository.Get();

            if (tasksResult.Failure)
            {
                return(ControllerUtilities.CheckResult(tasksResult));
            }

            try
            {
                var parser = new FilterQueryParser <ProjectTask>(ProjectTask.Specifications);
                var filter = parser.MakeFilter(query);
                return(tasksResult
                       .Value
                       .Where(task => filter(task))
                       .ToList());
            }
            catch
            {
                return(BadRequest());
            }
        }