public void DateTimeSecondTest() { var start = new DateTime(2000, 1, 1); var range = RangeEx.Create(start, 3, DateRangeType.Second).ToArray(); Assert.Equal(new[] { new DateTime(2000, 1, 1, 0, 0, 0), new DateTime(2000, 1, 1, 0, 0, 1), new DateTime(2000, 1, 1, 0, 0, 2), }, range); }
public void DateTimeYearTest() { var start = new DateTime(2000, 1, 1); var range = RangeEx.Create(start, 3, DateRangeType.Year).ToArray(); Assert.Equal(new[] { new DateTime(2000, 1, 1, 0, 0, 0), new DateTime(2001, 1, 1, 0, 0, 0), new DateTime(2002, 1, 1, 0, 0, 0), }, range); }
public void Test1() { var taken = new List <string>(); for (int i = 0; i < 20; i++) { var generator = new StringGenerator("$d$d", 0); var items = generator.Take(5, taken.ToArray()); taken.AddRange(items); } Assert.Equal(RangeEx.Create(0, 100), taken.Select(x => int.Parse(x)).OrderBy(x => x)); }
static void Main(string[] args) { var chinese = EnumerableEx.Concat( RangeEx.Create(0x2E80, 0x2EFF - 0x2E80 + 1), RangeEx.Create(0x3400, 0x4DBF - 0x3400 + 1), RangeEx.Create(0x4E00, 0x9FFF - 0x4E00 + 1), RangeEx.Create(0xF900, 0xFAFF - 0xF900 + 1)); var sb = new StringBuilder(); var success = 0; var fail = 0; foreach (var c in chinese) { var ch = (char)c; var str = ch.ToString(); try { var pinyins = GetOriginPinyin(ch); var simplified = Converter.Convert(str, Direction.TraditionalToSimplified); var traditional = Converter.Convert(str, Direction.SimplifiedToTraditional); var tag = "null"; sb.AppendLine($@"{" ".Repeat(12)}new ChineseWord {{ Pinyins = new[] {{ {pinyins.Select(pinyin => $@"""{pinyin}""").Join(", ")} }}, Simplified = ""{simplified}"", Traditional = ""{traditional}"", Tag = {tag} }},"); success++; } catch { fail++; } Console.WriteLine($"s:{success}\tf:{fail}\tt:{success + fail}"); } var csFile = Build(sb.ToString()); File.WriteAllText("../../../Basic.cs", csFile); Console.WriteLine("File saved: Basic.cs"); }
// gets the destination private async Task GetDestination(CommandEventArgs e, string Destination, string OriginID, int Iterations) { _WebClient.BaseAddress = BaseUrl; Uri DestURI = new Uri($"{BaseUrl}/location?input={Destination}"); string DestName = null; string DestX = null; string DestY = null; string DestID = null; // Subscribes to the event when the webclient has finished loading a page _WebClient.DownloadStringCompleted += async(s, m) => { if (_destinationDone != true) { string Response = m.Result; XmlDocument doc = new XmlDocument(); doc.LoadXml(Response); XmlElement root = doc.DocumentElement; XmlNodeList StopLocation = root.SelectNodes("//LocationList/StopLocation"); XmlNodeList CoordLocation = root.SelectNodes("//LocationList/CoordLocation"); if (root.FirstChild.Name == "StopLocation") { if (StopLocation != null) { DestName = StopLocation.Item(0).Attributes[0].Value; DestX = StopLocation.Item(0).Attributes[1].Value; DestY = StopLocation.Item(0).Attributes[2].Value; DestID = StopLocation.Item(0).Attributes[3].Value; } else { await e.Channel.SendMessage("Destination returned null try again"); } } if (root.FirstChild.Name == "CoordLocation") { try { if (CoordLocation != null) { DestName = CoordLocation.Item(0).Attributes[0].Value; DestX = CoordLocation.Item(0).Attributes[1].Value; DestY = CoordLocation.Item(0).Attributes[2].Value; DestID = CoordLocation.Item(0).Attributes[3].Value; } else { await e.Channel.SendMessage("Destination returned null try again"); } } catch (IndexOutOfRangeException RangeEx) { await e.Channel.SendMessage("Query failed try again"); await e.Channel.SendMessage(RangeEx.ToString()); } } _destinationDone = true; await PlanTrip(OriginID, DestX, DestY, DestName, e, Iterations); } }; _WebClient.DownloadStringAsync(DestURI); }
public void IntTest1() { var range = RangeEx.Create(95, 6).ToArray(); Assert.Equal(new[] { 95, 96, 97, 98, 99, 100 }, range); }
public void IntTest2() { var range = RangeEx.Create(95, 6, prev => prev / 2).ToArray(); Assert.Equal(new[] { 95, 47, 23, 11, 5, 2 }, range); }