public static void Load() { try { slot1 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner1); slot2 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner2); //Soon riot will introduce multiple heals, mark my words. var barrierNames = new[] { "summonerbarrier" }; if (barrierNames.Contains(slot1.Name)) { barrierSpell = new Spell(SpellSlot.Summoner1); summonerBarrier = SpellSlot.Summoner1; } else if (barrierNames.Contains(slot2.Name)) { barrierSpell = new Spell(SpellSlot.Summoner2); summonerBarrier = SpellSlot.Summoner2; } else { Console.WriteLine("You don't have barrier f****t"); return; } Game.PrintChat("<font color='#CC0000'>Sorry!</font> Barrier is not supported yet"); //Obj_AI_Base.OnProcessSpellCast += OnProcessSpellCast; //DamagePrediction.OnTargettedSpellWillKill += DamagePrediction_OnTargettedSpellWillKill; } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); } }
public static void Init() { slot1 = _Player.Spellbook.GetSpell(SpellSlot.Summoner1); slot2 = _Player.Spellbook.GetSpell(SpellSlot.Summoner2); var smiteNames = new[] { "s5_summonersmiteplayerganker", "itemsmiteaoe", "s5_summonersmitequick", "s5_summonersmiteduel", "summonersmite" }; if (smiteNames.Contains("smite")) { smite = new Spell.Targeted(SpellSlot.Summoner1, (uint) 560f); smiteSlot = SpellSlot.Summoner1; } if (smiteNames.Contains("smite")) { smite = new Spell.Targeted(SpellSlot.Summoner2, (uint) 560f); smiteSlot = SpellSlot.Summoner2; } Smiterino = Program.Menu.AddSubMenu("Auto Smite", "Smite"); Smiterino.AddGroupLabel("Auto Smite Settings"); Smiterino.AddSeparator(); Smiterino.Add("smiteActive", new CheckBox("Smite Active")); Smiterino.Add("drawHp", new CheckBox("Draw HP Bar on Minions")); Smiterino.Add("autoSmite", new KeyBind("AutoSmite Active HotKey", true, KeyBind.BindTypes.PressToggle, 'N')); Game.OnUpdate += OnUpdate; Drawing.OnDraw += OnDraw; }
public void PrimeTests() { var sieves = new List<IPrimeSieve>() { //new SimpleSieve(10), new HalfSizeSieve(10), }; foreach (var sieve in sieves) { CollectionAssert.AreEqual(new[] { 2, 3, 5, 7 }, sieve.GetPrimes()); } sieves = new List<IPrimeSieve>() { //new SimpleSieve(100), new HalfSizeSieve(100), }; var numbers = new[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; foreach (var sieve in sieves) { CollectionAssert.AreEqual(numbers, sieve.GetPrimes()); for (int i = 0; i < 100; i++) { Assert.True((numbers.Contains(i) && sieve.IsPrime(i)) || !(numbers.Contains(i) || sieve.IsPrime(i))); } } }
public void Trivial() { var objs = new object[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G' }; var c = objs.Length; var w = new int[c][]; var gr1 = new[] { 'A', 'B', 'C' }; var gr2 = new[] { 'D', 'E', 'F', 'G' }; for (int i = 0; i < c; i++) { w[i] = new int[c]; for (int j = 0; j < c; j++) { if (i == j) w[i][j] = 200; else if (gr1.Contains((char)objs[i]) && gr1.Contains((char)objs[j])) w[i][j] = 100; else if (gr2.Contains((char)objs[i]) && gr2.Contains((char)objs[j])) w[i][j] = 100; else w[i][j] = 0; } } var m = new Modularity(objs, w); Console.WriteLine("Start:" + m.CalcTotalModularity()); int iter = 1; while (m.Iterate(true)) Console.WriteLine("Iter[" + iter++ + "]:" + m.CalcTotalModularity() + ", nodes=" + m.NodesCount); Console.WriteLine("Result:" + m.CalcTotalModularity()); Console.WriteLine("fin"); Debug.Assert(m.NodesCount == 2); }
public static void Load() { try { slot1 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner1); slot2 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner2); //Soon riot will introduce multiple ignote, mark my words. var igniteNames = new[] { "summonerdot" }; if (igniteNames.Contains(slot1.Name)) { igniteSpell = new Spell(SpellSlot.Summoner1); summonerDot = SpellSlot.Summoner1; } else if (igniteNames.Contains(slot2.Name)) { igniteSpell = new Spell(SpellSlot.Summoner2); summonerDot = SpellSlot.Summoner2; } else { Console.WriteLine("You don't have ignite f****t"); return; } Game.OnUpdate += OnUpdate; } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); } }
public static void Load() { try { slot1 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner1); slot2 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner2); //Soon riot will introduce multiple cleanses, mark my words. var cleanseNames = new[] { "summonerboost" }; if (cleanseNames.Contains(slot1.Name)) { cleanseSpell = new Spell(SpellSlot.Summoner1, 550f); summonerCleanse = SpellSlot.Summoner1; } else if (cleanseNames.Contains(slot2.Name)) { cleanseSpell = new Spell(SpellSlot.Summoner2, 550f); summonerCleanse = SpellSlot.Summoner2; } Game.OnUpdate += OnUpdate; } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); } }
public static void Load() { try { slot1 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner1); slot2 = Entry.Player.Spellbook.GetSpell(SpellSlot.Summoner2); //Soon riot will introduce multiple heals, mark my words. var healNames = new[] { "summonerheal" }; if (healNames.Contains(slot1.Name)) { healSpell = new Spell(SpellSlot.Summoner1, 550f); summonerHeal = SpellSlot.Summoner1; } else if (healNames.Contains(slot2.Name)) { healSpell = new Spell(SpellSlot.Summoner2, 550f); summonerHeal = SpellSlot.Summoner2; } else { Console.WriteLine("You don't have heal f****t"); return; } Obj_AI_Base.OnProcessSpellCast += OnProcessSpellCast; Game.OnUpdate += OnUpdate; } catch (Exception e) { Console.WriteLine("An error occurred: '{0}'", e); } }
private void CheckSet(System.Collections.Hashtable wordset) { Assert.AreEqual(3, wordset.Count); Assert.IsTrue(wordset.Contains("ONE")); // case is not modified Assert.IsTrue(wordset.Contains("two")); // surrounding whitespace is removed Assert.IsTrue(wordset.Contains("three")); Assert.IsFalse(wordset.Contains("four")); }
public void fidns_factors_for_100() { var helper = new FactorsHelper(); var result = helper.Factors(100); var expected = new[] { 2, 4, 5, 10, 20, 25, 50 }; Assert.IsTrue(result.All(r => expected.Contains(r))); Assert.IsFalse(result.Any(r => !expected.Contains(r))); }
/// <summary> /// Drops the BackgroundImage property /// </summary> /// <param name="properties">properties to remove BackGroundImage from</param> protected override void PreFilterProperties(System.Collections.IDictionary properties) { base.PreFilterProperties (properties); if (properties.Contains("BackgroundImage") == true) properties.Remove("BackgroundImage"); if (properties.Contains("DrawGrid") == true) properties.Remove("DrawGrid"); }
public void LookupContains() { var lookup = new[] { "hi", "bye" }.ToLookup(c => c[0].ToString()); Assert.IsTrue(lookup.Contains("h")); Assert.IsFalse(lookup.Contains("d")); Assert.IsFalse(lookup.Contains(null)); }
public void LookupContainsNull() { var lookup = new[] { "hi", "bye", "42" }.ToLookup(c => (Char.IsNumber(c[0]) ? null : c[0].ToString())); Assert.IsTrue(lookup.Contains("h")); Assert.IsTrue(lookup.Contains(null)); Assert.IsFalse(lookup.Contains("d")); }
public void Contains2() { var arr = new[] { 1, 2 }; ForEachProvider(db => AreEqual( from p in Parent where arr.Contains(p.ParentID) select p, from p in db.Parent where arr.Contains(p.ParentID) select p)); }
void _PcapDevice_PcapOnPacketArrival(object sender, Packet packet) { if (!(packet is TCPPacket)) return; TCPPacket _TCPPacket = (TCPPacket)packet; //_SortedList.Add(_TCPPacket.SequenceNumber, _TCPPacket); byte[] _data = _TCPPacket.TCPData; if ((_data.Length == 0 || _data.Length == 6) && !_TCPPacket.Fin) return; Direction _Direction; int port; string ip; int[] remoteport = new[] { 80 }; if (remoteport.Contains(_TCPPacket.DestinationPort)) { _Direction = Direction.Sended; port = _TCPPacket.SourcePort; ip = _TCPPacket.DestinationAddress; } else if (remoteport.Contains(_TCPPacket.SourcePort)) { _Direction = Direction.Received; port = _TCPPacket.DestinationPort; ip = _TCPPacket.SourceAddress; } else return; Client _Client = (from c in _List where c.Port == port select c).FirstOrDefault(); if (_TCPPacket.Fin) { if (_Client != null) { _List.Remove(_Client); } return; } if (_Client == null) { _Client = new Client { ip = ip, Port = port }; i++; _Client.i = i; _List.Add(_Client); } if (_Direction == Direction.Sended) { Save(_TCPPacket, _Direction, _Client, _Client._SendStream); } else { Save(_TCPPacket, _Direction, _Client, _Client._ReceiveStream); } }
public static void ShowParsedCommand(ConsoleCommand consoleCommand, TextWriter consoleOut) { if (!consoleCommand.TraceCommandAfterParse) { return; } string[] skippedProperties = new []{ "Command", "OneLineDescription", "LongDescription", "Options", "TraceCommandAfterParse", "RemainingArgumentsCount", "RemainingArgumentsHelpText", "RequiredOptions" }; var properties = consoleCommand.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => !skippedProperties.Contains(p.Name)); var fields = consoleCommand.GetType().GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance) .Where(p => !skippedProperties.Contains(p.Name)); Dictionary<string,string> allValuesToTrace = new Dictionary<string, string>(); foreach (var property in properties) { object value = property.GetValue(consoleCommand, new object[0]); allValuesToTrace[property.Name] = value != null ? value.ToString() : "null"; } foreach (var field in fields) { allValuesToTrace[field.Name] = MakeObjectReadable(field.GetValue(consoleCommand)); } consoleOut.WriteLine(); string introLine = String.Format("Executing {0}", consoleCommand.Command); if (string.IsNullOrEmpty(consoleCommand.OneLineDescription)) introLine = introLine + ":"; else introLine = introLine + " (" + consoleCommand.OneLineDescription + "):"; consoleOut.WriteLine(introLine); foreach(var value in allValuesToTrace.OrderBy(k => k.Key)) consoleOut.WriteLine(" " + value.Key + " : " + value.Value); consoleOut.WriteLine(); }
public void Equality( System.Collections.ObjectModel.Collection<Tuple<object>> sut ) { var item = new object(); var first = Tuple.Create( item ); var second = Tuple.Create( item ); Assert.False( sut.Contains( second ) ); sut.Add( first ); Assert.True( sut.Contains( second ) ); }
/// public virtual System.Collections.Generic.IList<Tuple<int, float>> Recommend( int user_id, int n = -1, System.Collections.Generic.ICollection<int> ignore_items = null, System.Collections.Generic.ICollection<int> candidate_items = null) { if (candidate_items == null) candidate_items = Enumerable.Range(0, MaxItemID - 1).ToList(); if (ignore_items == null) ignore_items = new int[0]; System.Collections.Generic.IList<Tuple<int, float>> ordered_items; if (n == -1) { var scored_items = new List<Tuple<int, float>>(); foreach (int item_id in candidate_items) if (!ignore_items.Contains(item_id)) { float score = Predict(user_id, item_id); if (score > float.MinValue) scored_items.Add(Tuple.Create(item_id, score)); } ordered_items = scored_items.OrderByDescending(x => x.Item2).ToArray(); } else { var comparer = new DelegateComparer<Tuple<int, float>>( (a, b) => a.Item2.CompareTo(b.Item2) ); var heap = new IntervalHeap<Tuple<int, float>>(n, comparer); float min_relevant_score = float.MinValue; foreach (int item_id in candidate_items) if (!ignore_items.Contains(item_id)) { float score = Predict(user_id, item_id); if (score > min_relevant_score) { heap.Add(Tuple.Create(item_id, score)); if (heap.Count > n) { heap.DeleteMin(); min_relevant_score = heap.FindMin().Item2; } } } ordered_items = new Tuple<int, float>[heap.Count]; for (int i = 0; i < ordered_items.Count; i++) ordered_items[i] = heap.DeleteMax(); } return ordered_items; }
public void Configure(System.Collections.IDictionary properties) { if (properties.Contains("keyPrefix")) { _keyPrefix = (string)properties["keyPrefix"]; } if (properties.Contains("timeoutHours")) { _timeout = TimeSpan.Parse((string)properties["timeoutHours"]); } _memcachedClient = new MemcachedClient(); }
public void Array_01_Contains() { var names = new[] { "Stephanie Süss", "Manuela Zucker", "Franziska Ner", "Dr. Rainer Hohn" }; var employeesQuery = from e in companyExampleContext.Employees where names.Contains(e.Name) orderby e.Name select e; Assert.AreEqual(4, employeesQuery.Count()); foreach (var employee in employeesQuery) { Assert.IsTrue(names.Contains(employee.Name)); } }
public DateTime2Convention() { string[] specialColumns = new[] { "CreatedDate" }; this.Properties<DateTime>() .Where(p => !specialColumns.Contains(p.Name)) .Configure(c => c.HasColumnType("datetime2")); this.Properties<DateTime>() .Where(p => specialColumns.Contains(p.Name)) .Configure(c => c.HasColumnType("datetime2") .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed) ); }
private static bool IsTheWordWhole(string inputline, int index) { char[] separators = new[] { ' ', '.', '-', ',', ';', ':' ,'\n'}; bool wordIsWhole = false; if ((index+5 < inputline.Length)&&(separators.Contains(inputline[index+5]))) { wordIsWhole = true; } else if ((index - 1 > -1) && (separators.Contains(inputline[index + 5]))) { wordIsWhole = true; } return wordIsWhole; }
public void Contains4() { var arr = new[] { 1, 2 }; var expected = from p in Parent where arr.Contains(p.ParentID) select p; ForEachProvider(data => AreEqual(expected, CompiledQuery.Compile<ITestDataContext,IQueryable<Parent>>(db => from p in db.Parent where arr.Contains(p.ParentID) select p)(data))); }
private static IOrderedEnumerable<KeyValuePair<string, int>> CountWords(string file, Predicate<string> condition) { StreamReader sr = new StreamReader(file); var counts = new Dictionary<string, int>(); var special = new[] { '-', '_', '\'' }; while (!sr.EndOfStream) { int c = sr.Read(); while (c != -1 && !(char.IsLetterOrDigit((char)c) || special.Contains((char)c))) { c = sr.Read(); } if (c == -1) { break; } else { StringBuilder sb = new StringBuilder(); while (c != -1 && (char.IsLetterOrDigit((char)c) || special.Contains((char)c))) { sb.Append((char)c); c = sr.Read(); } string s = sb.ToString().ToLower(); if (condition(s)) { if (counts.ContainsKey(s)) { counts[s]++; } else { counts[s] = 1; } } } } sr.Close(); return counts.OrderBy(kvp => kvp.Key).OrderBy(kvp => kvp.Value); }
public static void ContainsOnConstantMustBeMatchedWithEntity() { var names = new[] { "a", "b", "c" }; { // TODO: Consider supporting this particular case via partial evaluation var ex = Assert.Throws<NotSupportedException>(() => Translate(Robots.Where(r => names.Contains("a")))); Assert.Contains("Unknown source", ex.Message); } { var ex = Assert.Throws<NotSupportedException>(() => Translate(Robots.Where(r => names.Contains(r.Name.ToLower())))); Assert.Contains("Unknown source", ex.Message); } }
public void GetQuotes() { // create list of stocks var stocks = new[] { new Stock { Symbol = "MSFT" }, new Stock { Symbol = "YHOO" } }; var expectedQuotes = new[] { new StockQuote { Symbol = "MSFT" }, new StockQuote { Symbol = "YHOO" } }; // set up fake logger var logger = A.Fake<ILog>(); // set up first fake data provider var marketDataProvider1 = A.Fake<IYahooMarketDataProvider>(); A.CallTo(() => marketDataProvider1.GetQuotes(A<IEnumerable<Stock>>.Ignored)) .Throws<Exception>(); // set up second fake data provider var marketDataProvider2 = A.Fake<IYahooMarketDataProvider>(); A.CallTo(() => marketDataProvider2.GetQuotes(A<IEnumerable<Stock>>.Ignored)) .Returns(expectedQuotes); // create Yahoo market data provider var yahooMarketDataProvider = new YahooMarketDataProvider(logger, new[] { marketDataProvider1, marketDataProvider2 }); // get quotes from provider IEnumerable<StockQuote> actualQuotes = yahooMarketDataProvider.GetQuotes(stocks); // check that a call was made to get the stock quote select A.CallTo(() => marketDataProvider1.GetQuotes(stocks)).MustHaveHappened(); A.CallTo(() => marketDataProvider2.GetQuotes(stocks)).MustHaveHappened(); A.CallTo(() => logger.Warn(A<string>.Ignored, A<Exception>.Ignored)).MustHaveHappened(); // check that quotes returned are the same as the quotes returned by the result translator actualQuotes.Should().OnlyContain(q => expectedQuotes.Contains(q)); }
public void Test5() { IEnumerable<int> ids = new[] { 1, 2 }; var eids = Parent .Where(p => ids.Contains(p.ParentID)) .Select(p => p.Value1 == null ? p.ParentID : p.ParentID + 1) .Distinct(); var expected = eids.Select(id => new { id, Count1 = Child.Where(p => p.ParentID == id).Count(), Count2 = Child.Where(p => p.ParentID == id && p.ParentID == _testValue).Count(), }); ForEachProvider(db => { var rids = db.Parent .Where(p => ids.Contains(p.ParentID)) .Select(p => p.Value1 == null ? p.ParentID : p.ParentID + 1) .Distinct(); var result = rids.Select(id => new { id, Count1 = db.Child.Where(p => p.ParentID == id).Count(), Count2 = db.Child.Where(p => p.ParentID == id && p.ParentID == _testValue).Count(), }); AreEqual(expected, result); }); }
protected AutoSuspendApplication() { var host = new SuspensionHost(); var launchNew = new[] { ApplicationExecutionState.ClosedByUser, ApplicationExecutionState.NotRunning, }; host.IsLaunchingNew = _launched .Where(x => launchNew.Contains(x.PreviousExecutionState)) .Select(_ => Unit.Default); host.IsResuming = _launched .Where(x => x.PreviousExecutionState == ApplicationExecutionState.Terminated) .Select(_ => Unit.Default); var unpausing = new[] { ApplicationExecutionState.Suspended, ApplicationExecutionState.Running, }; host.IsUnpausing = _launched .Where(x => unpausing.Contains(x.PreviousExecutionState)) .Select(_ => Unit.Default); var shouldPersistState = new Subject<SuspendingEventArgs>(); Suspending += (o, e) => shouldPersistState.OnNext(e); host.ShouldPersistState = shouldPersistState.Select(x => { var deferral = x.SuspendingOperation.GetDeferral(); return Disposable.Create(deferral.Complete); }); var shouldInvalidateState = new Subject<Unit>(); UnhandledException += (o, e) => shouldInvalidateState.OnNext(Unit.Default); host.ShouldInvalidateState = shouldInvalidateState; SuspensionHost = host; }
public override void OnAuthorization(AuthorizationContext filterContext) { base.OnAuthorization(filterContext); if (filterContext.HttpContext.User.Identity.IsAuthenticated) { var userId = filterContext.HttpContext.User.Identity.GetUserId(); var userManager = filterContext.HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); var currentUser = userManager.FindById(userId); if (currentUser.EmailConfirmed == false) { //取得 URLHelper var urlHelper = new UrlHelper(filterContext.RequestContext); //將路徑名稱組合 var currentControllerAndActionName = string.Concat(filterContext.RouteData.Values["controller"], "_", filterContext.RouteData.Values["action"]); //明確開放[登入][登出][EMAIL驗證] var allowAction = new[] { "Account_Login", "Account_LogOff", "Account_VerifyMail" }; if (allowAction.Contains(currentControllerAndActionName) == false) { //所有沒有通過EMAIL驗證的都導向驗證頁面(請視專案需求調整) var redirect = new RedirectResult(urlHelper.Action("VerifyMail", "Account")); filterContext.Result = redirect; } } } }
public override void ExtractTerms(System.Collections.Hashtable terms) { if (terms.Contains(term) == false) { terms.Add(term, term); } }
protected override void PreFilterProperties(System.Collections.IDictionary properties) { base.PreFilterProperties(properties); foreach (string p in propsToRemove) if (properties.Contains(p)) properties.Remove(p); }