public void MethodIntersectWith_Return(double minFirst, double maxFirst, double minSecond, double maxSecond, bool result) { var first = new FrequencyGroup(minFirst, maxFirst); var second = new FrequencyGroup(minSecond, maxSecond); first.IntersectWith(second).Should().Be(result); }
public void MethodContains_Return(double value, bool isContains) { var group = new FrequencyGroup(0, 0.5); var result = group.Contains(value); result.Should().Be(isContains); }
private void Find_Click(object sender, EventArgs e) { var defaultTime = "Choose time"; var defaultWeather = "Choose weather"; var defaultDistrict = "Choose district"; var isDefaultTimeTo = string.Equals(_timeTo.SelectedItem.ToString(), defaultTime, OrdinalIgnoreCase); var isDefaultTimeFrom = string.Equals(_timeFrom.SelectedItem.ToString(), defaultTime, OrdinalIgnoreCase); var isDefaultWeather = string.Equals(_weather.SelectedItem.ToString(), defaultWeather, OrdinalIgnoreCase); var isDefaultDistrict = string.Equals(_district.SelectedItem.ToString(), defaultDistrict, OrdinalIgnoreCase); if (isDefaultTimeTo && isDefaultTimeFrom && isDefaultWeather && isDefaultDistrict) { Toast.MakeText(this, "Select minimum one criteria", ToastLength.Short).Show(); _gridView.Adapter = null; return; } var to = isDefaultTimeTo ? string.Empty : _timeTo.SelectedItem.ToString(); var from = isDefaultTimeFrom ? string.Empty : _timeFrom.SelectedItem.ToString(); var weather = isDefaultWeather ? string.Empty : _weather.SelectedItem.ToString(); var location = isDefaultDistrict ? string.Empty : _district.SelectedItem.ToString(); var freqRepo = new FrequencyRepository(); var criterya = new FrequencyGroup { To = to, From = from, Weather = weather, Location = location }; try { var frequency = freqRepo.GetFrequencyByCriterya(criterya); if (frequency.Count > 0) { _gridViewItems = new ArrayList(frequency); ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, _gridViewItems); _gridView.Adapter = adapter; } else { resetGridAndPopulateMsg(); } } catch { resetGridAndPopulateMsg(); } }
public void Add(string name, FrequencyGroup frequencyGroup, int fontSize) { if (tags.ContainsKey(name)) { throw new ArgumentException($"Group {name} already exist"); } if (fontSize <= 0) { throw new ArgumentException($"Font size can't be negative or zero, but was {fontSize}"); } foreach (var sizeGroup in tags) { if (sizeGroup.Value.FrequencyGroup.IntersectWith(frequencyGroup)) { throw new ArgumentException($"Group {name} intersect with {sizeGroup.Key}"); } } tags.Add(name, new TagGroup(fontSize, frequencyGroup)); }
public List <long> GetFrequencyByCriterya(FrequencyGroup criterya) { IEnumerable <FrequencyGroup> frequencyGroups = _frequencyGroups; if (!string.IsNullOrEmpty(criterya.To)) { //frequencyGroups = frequencyGroups.Where(x => string.Equals(x.To, criterya.To, OrdinalIgnoreCase)); frequencyGroups = frequencyGroups.Where(x => int.Parse(x.To) >= int.Parse(criterya.To)); } if (!string.IsNullOrEmpty(criterya.From)) { //frequencyGroups = frequencyGroups.Where(x => string.Equals(x.From, criterya.From, OrdinalIgnoreCase)); frequencyGroups = frequencyGroups.Where(x => int.Parse(x.From) <= int.Parse(criterya.From)); } if (!string.IsNullOrEmpty(criterya.To) && !string.IsNullOrEmpty(criterya.From)) { var duration = Math.Abs(int.Parse(criterya.From) - int.Parse(criterya.To)); frequencyGroups = frequencyGroups.Where(x => Math.Abs(int.Parse(x.From) - int.Parse(x.To)) <= duration); } /*if (!string.IsNullOrEmpty(criterya.Weather)) * { * frequencyGroups = frequencyGroups.Where(x => string.Equals(x.Weather, criterya.Weather, OrdinalIgnoreCase)); * }*/ if (!string.IsNullOrEmpty(criterya.Location)) { frequencyGroups = frequencyGroups.Where(x => string.Equals(x.Location, criterya.Location, OrdinalIgnoreCase)); } var frequencies = new List <long>(); foreach (var freq in frequencyGroups) { frequencies.AddRange(freq.Frequencies); } return(frequencies.Count > 0 ? frequencies.Distinct().ToList() : new List <long>()); }