public void Add_ExistingPrefix_Throw(params object[] prefix) { var sut = new PrefixDictionary <object, object>(); sut.Add(prefix, 1); Assert.That(() => sut.Add(prefix, 0), Throws.ArgumentException); }
public void Update_Prefix_WithNullValue_Works(params object[] prefix) { var sut = new PrefixDictionary <object, object>(); sut.Add(prefix, 1); Assert.That(() => sut.Update(prefix, null), Throws.Nothing); }
public void Add_Works(params object[] prefix) { var sut = new PrefixDictionary <object, object>(); sut.Add(prefix, 42); Assert.That(sut.GetMatches(prefix), Is.EquivalentTo(new[] { 42 })); }
public void Update_ExistingPrefix_Works(params object[] prefix) { var sut = new PrefixDictionary <object, object>(); sut.Add(prefix, 1); Assert.That(() => sut.Update(prefix, 0), Throws.Nothing); }
static Engine() { _prefixes = new PrefixDictionary(); _operators = new string[] { "+", "*", "/", "×", "÷", "(", ")", "%", "," }; _bitoperators = new string[] { "|AND|", "|OR|", "|NOT|", "|SHL|", "|SHR|" }; _functions = new List <FunctionInfo>(); _pluggable = new List <Type>(); try { ReflectLoad("ECalc.Maths"); } catch (Exception ex) { MainWindow.ErrorDialog(ex.Message); } }
public void GetMatches_Case5() { var sut = new PrefixDictionary <char, int>(); sut.Add("PRA", 0); sut.Add("PRE", 1); sut.Add("PRI", 2); var actual = sut.GetMatches("PREFIX").ToList(); var expected = new[] { 1 }; Assert.AreEqual(expected, actual); }
/// <summary> /// This event is triggered every time the a user sends a message in a channel, dm etc. that the bot has access to view. /// </summary> /// <param name="socketMessage"> /// The socket message. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> internal async Task MessageReceivedAsync(SocketMessage socketMessage) { if (!(socketMessage is SocketUserMessage Message) || Message.Channel is IDMChannel) { return; } var context = new Context(Client, Message, Provider); if (Config.LogUserMessages) { LogHandler.LogMessage(context); } var argPos = 0; if (DBConfig.Local.Developing && DBConfig.Local.PrefixOverride != null) { if (!Message.HasStringPrefix(DBConfig.Local.PrefixOverride, ref argPos)) { return; } } else { // Filter out all messages that don't start with our Bot Prefix, bot mention or server specific prefix. if (!(Message.HasStringPrefix(PrefixDictionary.Load().GuildPrefix(context.Guild.Id) ?? Config.Prefix, ref argPos) || Message.HasMentionPrefix(context.Client.CurrentUser, ref argPos))) { return; } } // Here we attempt to execute a command based on the user message var result = await CommandService.ExecuteAsync(context, argPos, Provider, MultiMatchHandling.Best); // Generate an error message for users if a command is unsuccessful if (!result.IsSuccess) { var _ = Task.Run(() => CmdErrorAsync(context, result, argPos)); } else { if (Config.LogCommandUsages) { LogHandler.LogMessage(context); } } }
public void GetMatches_Case6() { var sut = new PrefixDictionary <char, int>(); sut.Add("", 0); sut.Add("P", 1); sut.Add("PR", 2); sut.Add("PRE", 3); sut.Add("PREF", 4); sut.Add("PREFI", 5); sut.Add("PREFIX", 6); var actual = sut.GetMatches("PREFIX").ToList(); var expected = new[] { 0, 1, 2, 3, 4, 5, 6 }; Assert.AreEqual(expected, actual); }
public Task CustomPrefixAsync([Remainder] string prefix = null) { // Modify the prefix and then update the object within the database. var prefixDict = PrefixDictionary.Load(); if (prefix == null) { prefixDict.PrefixList.Remove(Context.Guild.Id); } else { prefixDict.PrefixList.Add(Context.Guild.Id, prefix); } prefixDict.Save(); // If prefix is null, we default back to the default bot prefix return(SimpleEmbedAsync($"Prefix is now: {prefix ?? ConfigModel.Prefix}")); }
public void Scenario1() { var sut = new PrefixDictionary <char, int>(); Assert.That(sut.Remove("P"), Is.False); Assert.That(() => sut.Add("P", 0), Throws.Nothing); Assert.That(sut.Remove("P"), Is.True); Assert.That(() => sut.Add("P", 0), Throws.Nothing); Assert.That(sut.Remove("P"), Is.True); Assert.That(() => sut.Update("P", 0), Throws.TypeOf <KeyNotFoundException>()); Assert.That(() => sut.Add("P", 0), Throws.Nothing); Assert.That(() => sut.Add("PREFIX", 1), Throws.Nothing); Assert.That(sut.GetMatches("PREFIX"), Is.EquivalentTo(new[] { 0, 1 })); Assert.That(sut.Remove("P"), Is.True); Assert.That(sut.GetMatches("PREFIX"), Is.EquivalentTo(new[] { 1 })); Assert.That(sut.Remove("PREFIX"), Is.True); Assert.That(sut.GetMatches("PREFIX"), Is.Empty); }
public void GetMatches_ModificationInEnumeration_Throw() { var sut = new PrefixDictionary <char, int>(); sut.Add("", 0); sut.Add("P", 1); sut.Add("PR", 2); sut.Add("PRE", 3); sut.Add("PREF", 4); sut.Add("PREFI", 5); sut.Add("PREFIX", 6); Assert.That(() => { foreach (var match in sut.GetMatches("PREFIX")) { sut.Add("TEST", 0); } }, Throws.InvalidOperationException); }
public void Add_NewPrefix_Works(params object[] prefix) { var sut = new PrefixDictionary <object, object>(); Assert.That(() => sut.Add(prefix, 0), Throws.Nothing); }
private static void RefreshListAsync(TextBox textBox, ListBox listBox, string word, PrefixDictionary<KeyValuePair<string, object>[]> dict, Action callback, StringComparison comparison) { var matches = dict.Search(word, false).Select(found => found.Value).SelectMany(found => found).ToList(); listBox.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate{ var ev = (QueryCandidatesEventHandler)textBox.GetValue(QueryCandidatesProperty); if(ev != null){ var e = new QueryCandidatesEventArgs(word); foreach(var del in ev.GetInvocationList()){ del.DynamicInvoke(new object[]{textBox, e}); if(e.Candidates != null){ matches.AddRange(e.Candidates); } } } })); listBox.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(delegate{ bool isIns = GetIsInsertAutomatically(textBox); listBox.ItemsSource = null; listBox.ItemsSource = matches.ToArray(); SetState(listBox, new AutoCompleteState(){TextBox = textBox}); listBox.SelectionChanged -= ListBox_SelectionChanged; if(isIns){ listBox.SelectionChanged += ListBox_SelectionChanged; } if(listBox.Items.Count > 0){ listBox.SelectedIndex = 0; listBox.ScrollIntoView(listBox.SelectedItem); } if(!isIns){ listBox.SelectionChanged += ListBox_SelectionChanged; } if(callback != null){ callback(); } })); }
public void GetMatches_NullEntry_Throw() { var sut = new PrefixDictionary <char, object>(); Assert.That(() => sut.GetMatches(null), Throws.ArgumentNullException); }
private void DisplayChange(object sender, RoutedEventArgs e) { string message = "Complex, Vector, Fraction and Matrix values not supported"; var s = (sender as MenuItem)?.Name; try { switch (s) { case "DispNumSys": var nd = new NumberSystemDisplayDialog(); nd.SetDisplay(Engine.Ans); MainWindow.ShowDialog(nd); return; case "DispText": var ntd = new NumberToTextDialog(); ntd.SetNumber(Engine.Ans); MainWindow.ShowDialog(ntd); return; case "DispFractions": if (!Helpers.IsSpecialType(Engine.Ans)) { var f = new Fraction((double)Engine.Ans); message = f.ToString(); } break; case "DispFileSize": if (!Helpers.IsSpecialType(Engine.Ans)) { double x = Convert.ToDouble(Engine.Ans); message = Helpers.DivideToFileSize(x); } break; case "DispPercent": if (!Helpers.IsSpecialType(Engine.Ans)) { double x = Convert.ToDouble(Engine.Ans); x *= 100; message = string.Format("{0}%", x); } break; case "DispPrefixes": if (!Helpers.IsSpecialType(Engine.Ans)) { var prefixes = new PrefixDictionary(); double x = Convert.ToDouble(Engine.Ans); message = prefixes.DivideToPrefix(x); } break; default: message = "Operation is not yet implemented in code. Sorry"; break; } } catch (Exception) { message = "Operation is not possible"; } MainWindow.ShowDialog("Result as Fraction", message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative); }
private string FormatDouble(double input) { if (PreferPrefixes) { var pfx = new PrefixDictionary(); return(pfx.DivideToPrefix(input)); } if (GroupByThousands) { string gchar = " "; string fchar = "."; if (double.IsNaN(input) || double.IsInfinity(input)) { return(input.ToString(CultureInfo.InvariantCulture)); } var sb = new StringBuilder(); bool passed = false; int j = 1; int i; char[] ar; string text = input.ToString(); if (text.Contains(fchar)) { for (i = text.Length - 1; i >= 0; i--) { if (!passed && text[i] != fchar[0]) { sb.Append(text[i]); } else if (text[i] == fchar[0]) { sb.Append(text[i]); passed = true; } if (passed && text[i] != fchar[0]) { sb.Append(text[i]); if (j % 3 == 0) { sb.Append(gchar); } j++; } } ar = sb.ToString().ToCharArray(); Array.Reverse(ar); return(new string(ar).Trim()); } else { for (i = text.Length - 1; i >= 0; i--) { sb.Append(text[i]); if (j % 3 == 0) { sb.Append(gchar); } j++; } ar = sb.ToString().ToCharArray(); Array.Reverse(ar); return(new string(ar).Trim()); } } else { return(input.ToString(CultureInfo.InvariantCulture)); } }
public ResistorColorDecoder() { InitializeComponent(); _prefixes = new PrefixDictionary(); }
public void Add_NullPrefix_Throw() { var sut = new PrefixDictionary <char, object>(); Assert.That(() => sut.Add(null, 1), Throws.ArgumentNullException); }
private string FormatDouble(double input) { if (PreferPrefixes) { var pfx = new PrefixDictionary(); return pfx.DivideToPrefix(input); } if (GroupByThousands) { string gchar = " "; string fchar = "."; if (double.IsNaN(input) || double.IsInfinity(input)) return input.ToString(CultureInfo.InvariantCulture); var sb = new StringBuilder(); bool passed = false; int j = 1; int i; char[] ar; string text = input.ToString(); if (text.Contains(fchar)) { for (i = text.Length - 1; i >= 0; i--) { if (!passed && text[i] != fchar[0]) sb.Append(text[i]); else if (text[i] == fchar[0]) { sb.Append(text[i]); passed = true; } if (passed && text[i] != fchar[0]) { sb.Append(text[i]); if (j % 3 == 0) sb.Append(gchar); j++; } } ar = sb.ToString().ToCharArray(); Array.Reverse(ar); return new string(ar).Trim(); } else { for (i = text.Length - 1; i >= 0; i--) { sb.Append(text[i]); if (j % 3 == 0) sb.Append(gchar); j++; } ar = sb.ToString().ToCharArray(); Array.Reverse(ar); return new string(ar).Trim(); } } else return input.ToString(CultureInfo.InvariantCulture); }
public CopyableTextBox() { InitializeComponent(); _dict = new PrefixDictionary(); }
public void Update_NewPrefix_Throw(params object[] prefix) { var sut = new PrefixDictionary <object, object>(); Assert.That(() => sut.Update(prefix, 0), Throws.TypeOf <KeyNotFoundException>()); }