protected override (SegmentationStatus status, ReadOnlySequence <byte>?segment) Read(ReadOnlySequence <byte> buffer) { var startOfSegment = Starts.Select(start => buffer.PositionOf(start)).FirstOrDefault(start => start != null); if (startOfSegment != null) { var segment = buffer.Slice(startOfSegment.Value); var endOfSegment = segment.PositionOf(End); if (endOfSegment != null) { var completeSegment = segment.Slice(0, segment.GetPosition(1, endOfSegment.Value)); if (this.Options.HasFlag(SegmentionOptions.SecondStartInvalid)) { var secondStart = Starts.Select(start => completeSegment.PositionOf(start)).FirstOrDefault(start => start != null); if (secondStart != null) { // Second start detected return(SegmentationStatus.Invalid, buffer.Slice(0, secondStart.Value)); } } return(SegmentationStatus.Complete, completeSegment); } else if (this.MaxLength.HasValue && buffer.Length > this.MaxLength) { var leftover = buffer.Length % this.MaxLength.Value; buffer = buffer.Slice(0, buffer.GetPosition(-leftover, buffer.End)); return(SegmentationStatus.Invalid, buffer); } } return(SegmentationStatus.Incomplete, null); }
private void ExpandStarts() { Contract.Assert(Lengths.CompressedData == null, "Lengths must be decompressed prior to optimizing starts"); var count = Starts.Count; int priorStart = Starts.MinValue; int priorLength = 0; int max = 0; for (int i = 0; i < count; i++) { int startOffset = Starts.GetIndexDirect(i); int newValue; if (startOffset == 0) { // 0 is reserved to indicate this span starts at the same position as the prior start newValue = priorStart; } else { // This is a delta from the end of the previous span + 1 (0 is reserved) var priorEnd = priorStart + priorLength; newValue = priorEnd + startOffset - 1; } Starts[i] = newValue; priorStart = newValue; priorLength = Lengths[i]; max = Math.Max(newValue, max); } var newStartsMinByteWidth = NumberUtils.GetByteWidth(max - Starts.MinValue); Contract.Assert(newStartsMinByteWidth == Starts.ValueByteWidth); }
public void FeatureMatcherGeneratesCorrectTypeNameInMismatchDescription() { var sut = Describe.Object <AnotherFlatClass>() .Property(x => x.Id, new FakeMatcher <Guid>(false, "", i => "")); sut.ShouldHaveMismatchDescriptionForValue(new AnotherFlatClass(), Starts.With("was a(n) AnotherFlatClass where:")); }
private void Starts_Tick(object sender, EventArgs e) { try { if (list.Items.Count >= 1) { lblStatus.Text = "Working"; list.SelectedIndex = 0; flag(); fillData(); Starts.Stop(); Verify.Start(); } else { Starts.Stop(); Returns.Start(); lblStatus.Text = "Stopped"; MessageBox.Show("Sem dados em lista", "Acabou"); } } catch (Exception ex) { Starts.Stop(); Returns.Start(); MessageBox.Show(ex.Message); } }
public void It_Can_Handle_Recursive_Rules() { IRuleParser ListParser() { var list = new List <string>(); return(Starts.With ( A.Word(list.Add), One.Of ( The.Symbol("}"), A.Rule <List <string> >(ListParser, rest => list.AddRange(rest)) ) ).ReturnsNode(list)); } var parser = ListParser(); string src = "a b c d e f g}"; var tokens = new Lexer().ToTokens(src); var resultList = parser .FeedAll(tokens) .AssertComplete <List <string> >(); var expectedList = new string[] { "a", "b", "c", "d", "e", "f", "g" }; Assert.Equal(expectedList, resultList); }
public void FeatureMatcherGeneratesCorrectTypeNameInDescription() { var sut = Describe.Object <AnotherFlatClass>() .Property(x => x.Id, new FakeMatcher <Guid>(true, "", i => "")); sut.ShouldHaveDescription(Starts.With("a(n) AnotherFlatClass where:")); }
public string ToString(string format, IFormatProvider formatProvider) { switch (format) { case null: case "N": return("None"); case "F": return(FirstName); case "L": return(LastName); case "C": return(Country); case "S": return(Starts.ToString()); case "W": return(Wins.ToString()); case "A": return($"{FirstName} {LastName},{Country}; start:{Starts}, wins:{Wins}"); default: throw new FormatException($"Format {format} not supproted"); } }
internal void Expand(OptimizationContext context) { if (!Optimized) { return; } Starts.ExpandData(context); Lengths.ExpandData(context); SharedIndices.ExpandData(context); if (!StartsExpanded) { ExpandStarts(); } ExpandLists(context); if (FullLength == 0) { var end = Starts[Starts.Count - 1] + Lengths[Lengths.Count - 1]; FullLength = end - Starts.MinValue + 1; } Optimized = false; }
public string ToString(string format, IFormatProvider formatProvider) { switch (format) { case null: case "N": return(ToString()); case "F": return(FirstName); case "L": return(LastName); case "C": return(Country); case "S": return(Starts.ToString()); case "W": return(Wins.ToString()); case "A": return(String.Format("{0} {1}, {2}; starts: {3}, wins: {4}", FirstName, LastName, Country, Starts, Wins)); default: throw new FormatException(String.Format( "Format {0} not supported", format)); } }
public async Task StartHandle(string id, CancellationToken token) { Console.WriteLine($"start handling {id}"); await mStartsLock.WaitAsync(token); Starts.Add(id); mStartsLock.Release(); }
public void No_match_if_string_does_not_end_with_substring() { var matcher = Starts.With("bob"); var matches = matcher.Matches("the cat sat on the mat"); Assert.That(matches, Is.False()); }
private void btnStop_Click(object sender, EventArgs e) { Starts.Stop(); Verify.Stop(); Returns.Start(); lblStatus.Text = "Stopped"; MessageBox.Show("successfully stopped!", "stopped"); }
public void Describe_mismatch() { var matcher = Starts.With("bob"); var description = new StringDescription(); matcher.DescribeMismatch("the cat sat on the mat", description); Assert.That(description.ToString(), Is.EqualTo("was \"the cat sat on the mat\"")); }
public void Describe_to() { var matcher = Starts.With("bob"); var description = new StringDescription(); matcher.DescribeTo(description); Assert.That(description.ToString(), Is.EqualTo("a string starting with \"bob\"")); }
public void Describe_mismatch_if_thrown_exception_does_not_match_predicate() { var matcher = new ThrowsMatcher <ArgumentNullException>().With(e => e.Message == "something else"); var description = new StringDescription(); matcher.DescribeMismatch(DoIt, description); NHAssert.That(description.ToString(), Starts.With("the exception was of the correct type, but did not match the predicate")); }
public void Describe_mismatch_if_action_throws_different_exception() { var matcher = new ThrowsMatcher <NullReferenceException>(); var description = new StringDescription(); matcher.DescribeMismatch(DoIt, description); NHAssert.That(description.ToString(), Starts.With("an exception of type System.ArgumentNullException was thrown")); }
public CharRange(byte[,] range) : this() { for (int i = 0; i < range.GetLength(0); i++) { Starts.Add((char)range[i, 0]); Ends.Add((char)range[i, 1]); } }
private void OptimizeStarts(OptimizationContext context) { Contract.Assert(Lengths.CompressedData == null, "Lengths must be decompressed prior to optimizing starts"); //var starts = Starts.GetReadOnlyList().ToList(); context.Stream.Position = 0; var startsDataLength = Starts.Data.Length; context.Stream.Write(Starts.Data, 0, startsDataLength); var count = Starts.Count; int priorStart = Starts.MinValue; int priorLength = 0; int max = 0; for (int i = 0; i < count; i++) { int start = Starts[i]; int newValue; if (start == priorStart) { newValue = 0; } else { // If not equal to prior start // We store the delta from the end of the prior span + 1 (0 is reserved for starting at the same position as the prior segment) // NOTE: This must be non-negative. var priorEnd = priorStart + priorLength; var priorEndOffset = start - priorEnd; if (priorEndOffset < 0) { throw new InvalidOperationException( $"priorEndOffset: {priorEndOffset} priorStart: {priorStart} priorLength: {priorLength} start: {start}"); } newValue = priorEndOffset + 1; } Starts.SetIndexDirect(i, newValue); priorStart = start; priorLength = Lengths[i]; max = Math.Max(newValue, max); } var newStartsMinByteWidth = NumberUtils.GetByteWidth(max); if (newStartsMinByteWidth > Starts.ValueByteWidth) { context.Stream.Position = 0; context.Stream.Read(Starts.Data, 0, startsDataLength); StartsExpanded = true; } }
protected override (SegmentationStatus status, ReadOnlySequence <byte>?segment) Read(ReadOnlySequence <byte> buffer) { var startOfSegment = Starts.Select(start => buffer.PositionOf(start)).FirstOrDefault(start => start != null); if (startOfSegment != null) { var segment = buffer.Slice(startOfSegment.Value); if (segment.Length >= FixedLength) { var completeSegment = segment.Slice(0, buffer.GetPosition(FixedLength, startOfSegment.Value)); if (this.Options.HasFlag(SegmentionOptions.SecondStartInvalid)) { var secondStart = Starts.Select(start => completeSegment.PositionOf(start)).FirstOrDefault(start => start != null); if (secondStart != null) { // Second start detected return(SegmentationStatus.Invalid, buffer.Slice(0, secondStart.Value)); } } if (ExtensionDefinition != null) { var valueData = completeSegment.Slice(ExtensionDefinition.Postion, ExtensionDefinition.Length); //TODO, drop the endian check... only support little and convert var set = this.ExtensionDefinition.Endianness == Endianness.Little ? valueData.ToArray() : valueData.ToArray().Reverse().ToArray(); ulong extendedLength = 0; for (var i = 0; i < this.ExtensionDefinition.Length; i++) { extendedLength |= (ulong)set[i] << (8 * i); } var actualLength = FixedLength + (long)extendedLength; if (segment.Length < actualLength) { return(SegmentationStatus.Incomplete, buffer); } completeSegment = segment.Slice(0, buffer.GetPosition(actualLength, startOfSegment.Value)); } return(SegmentationStatus.Complete, completeSegment); } } else if (buffer.Length > this.FixedLength) { var leftover = buffer.Length % this.FixedLength; buffer = buffer.Slice(0, buffer.GetPosition(-leftover, buffer.End)); return(SegmentationStatus.Invalid, buffer); } return(SegmentationStatus.Incomplete, buffer); }
public void You_Can_Compose_Multiple_Rules() { var funcDef = new FunctionDefinition(); var classDef = new ClassDefinition(); classDef.Functions = new List <FunctionDefinition>(); var funcParser = Starts .With ( The.Keyword("function"), A.Word(n => funcDef.Name = n), The.Symbol("("), The.Symbol(")"), The.Symbol("{"), The.Symbol("}") ) .ReturnsNode(funcDef); var classParser = Starts .With ( The.Keyword("class"), A.Word(n => classDef.Name = n), The.Symbol("{"), A.Rule <FunctionDefinition>(() => funcParser, classDef.Functions.Add), The.Symbol("}") ) .ReturnsNode(classDef); // Generate some tokens to parse with the parser we just made string src = @" class FooBar { function DoThing() {} } "; var tokens = new Lexer().ToTokens(src).ToArray(); var result = classParser.FeedAll(tokens); // Assert that it correctly did stuff. result.AssertComplete(); Assert.Equal(classDef, result.node); Assert.Equal("FooBar", classDef.Name); Assert.Contains(funcDef, classDef.Functions); Assert.Equal("DoThing", funcDef.Name); }
public void One_Of_Works() { IRuleParser AlphabetParser() { return(Starts .With ( The.Word("a"), The.Word("b"), The.Word("c"), The.Word("d") ) .ReturnsNode("abcd")); } IRuleParser AberahamParser() { return(Starts .With ( The.Word("a"), The.Word("b"), The.Word("e"), The.Word("raham") // laziness ) .ReturnsNode("aberaham")); } var node = new TestNode(); var oneOfParser = Starts .With ( One.Of ( A.Rule <string>(AlphabetParser, t => node.name = t), A.Rule <string>(AberahamParser, t => node.name = t) ) ) .ReturnsNode(node); string src = "a b e raham"; var tokens = new Lexer().ToTokens(src); var result = oneOfParser.FeedAll(tokens); var resultNode = result.AssertComplete <TestNode>(); Assert.Equal(node, resultNode); Assert.Equal("aberaham", resultNode.name); }
private void Verify_Tick(object sender, EventArgs e) { try { if (web.Document.Body.InnerText.Contains("Thanks")) { SystemSounds.Asterisk.Play(); approved.Items.Add(list.SelectedItem + "|Live|By Kamikaze|1$|"); _nApproved++; lblLive.Text = _nApproved.ToString(); list.Items.RemoveAt(0); lblList.Text = list.Items.Count.ToString(); Verify.Stop(); Returns.Start(); Starts.Start(); } else if (web.Document.Body.InnerText.Contains("Error Processing Contribution")) { _nReproved++; lblDie.Text = _nReproved.ToString(); list.Items.RemoveAt(0); lblList.Text = list.Items.Count.ToString(); Verify.Stop(); Returns.Start(); Starts.Start(); } else { _nReproved++; lblDie.Text = _nReproved.ToString(); list.Items.RemoveAt(0); lblList.Text = list.Items.Count.ToString(); Verify.Stop(); Returns.Start(); Starts.Start(); } } catch (Exception ex) { Starts.Stop(); Verify.Stop(); Returns.Start(); MessageBox.Show(ex.Message); } }
public void Update() { foreach (var component in Starts) { component.Start(); } Starts.Clear(); foreach (var dispose in Disposers) { Updates.Remove(dispose); } Disposers.Clear(); foreach (var component in Updates) { component.Update(); } }
/// <summary> /// Gets or sets the start and end of the range at the specified index. /// </summary> /// <param name="i"></param> /// <returns></returns> public KeyValuePair <char, char> this[int i] { get { var kvp = new KeyValuePair <char, char>(Starts[i], Ends[i]); return(kvp); } set { if (Starts.Count <= i) { Starts[i] = value.Key; Ends[i] = value.Value; } else { Starts.Add(value.Key); Ends.Add(value.Value); } } }
private void HandlerEvent(BaseComponent component, EventType eventType) { if ((eventType & EventType.Awake) == EventType.Awake) { if (component.IsAwake) { return; } component.Awake(); component.IsAwake = true; } else if ((eventType & EventType.Start) == EventType.Start) { Starts.Add(component); } else if ((eventType & EventType.Update) == EventType.Update) { Updates.Add(component); } }
internal void Optimize(OptimizationContext context) { if (Optimized) { return; } if (FullLength == 0) { var end = Starts[Starts.Count - 1] + Lengths[Lengths.Count - 1]; FullLength = end - Starts.MinValue + 1; } OptimizeStarts(context); Starts.Optimize(context); Lengths.Optimize(context); SharedIndices.Optimize(context); OptimizeLists(context); Optimized = true; }
public void You_Can_Express_An_Empty_Class() { var classDef = new ClassDefinition(); var classParser = Starts .With ( The.Keyword("class"), A.Word(name => classDef.Name = name), The.Symbol("{"), The.Symbol("}") ) .ReturnsNode(classDef); // Generate some tokens to parse with the parser we just made string src = "class FooBar {}"; var tokens = new Lexer().ToTokens(src); var result = classParser.FeedAll(tokens); // Assert that it correctly did stuff. result.AssertComplete(); Assert.Equal(classDef, result.node); Assert.Equal("FooBar", classDef.Name); }
public void Match_if_string_ends_with_substring() { Assert.That("the cat sat on the mat", Starts.With("the")); }
public void Case_insensitive_match_if_string_ends_with_substring() { Assert.That("the cat sat on the mat", Starts.With("The").CaseInsensitive()); }
/// <inheritdoc /> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; if (Type != null) { hashCode = hashCode * 59 + Type.GetHashCode(); } if (Visible != null) { hashCode = hashCode * 59 + Visible.GetHashCode(); } if (LegendGroup != null) { hashCode = hashCode * 59 + LegendGroup.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (UId != null) { hashCode = hashCode * 59 + UId.GetHashCode(); } if (Ids != null) { hashCode = hashCode * 59 + Ids.GetHashCode(); } if (CustomData != null) { hashCode = hashCode * 59 + CustomData.GetHashCode(); } if (Meta != null) { hashCode = hashCode * 59 + Meta.GetHashCode(); } if (MetaArray != null) { hashCode = hashCode * 59 + MetaArray.GetHashCode(); } if (HoverLabel != null) { hashCode = hashCode * 59 + HoverLabel.GetHashCode(); } if (Stream != null) { hashCode = hashCode * 59 + Stream.GetHashCode(); } if (UiRevision != null) { hashCode = hashCode * 59 + UiRevision.GetHashCode(); } if (X != null) { hashCode = hashCode * 59 + X.GetHashCode(); } if (Y != null) { hashCode = hashCode * 59 + Y.GetHashCode(); } if (Z != null) { hashCode = hashCode * 59 + Z.GetHashCode(); } if (U != null) { hashCode = hashCode * 59 + U.GetHashCode(); } if (V != null) { hashCode = hashCode * 59 + V.GetHashCode(); } if (W != null) { hashCode = hashCode * 59 + W.GetHashCode(); } if (Starts != null) { hashCode = hashCode * 59 + Starts.GetHashCode(); } if (MaxDisplayed != null) { hashCode = hashCode * 59 + MaxDisplayed.GetHashCode(); } if (SizeRef != null) { hashCode = hashCode * 59 + SizeRef.GetHashCode(); } if (Text != null) { hashCode = hashCode * 59 + Text.GetHashCode(); } if (HoverText != null) { hashCode = hashCode * 59 + HoverText.GetHashCode(); } if (HoverTemplate != null) { hashCode = hashCode * 59 + HoverTemplate.GetHashCode(); } if (HoverTemplateArray != null) { hashCode = hashCode * 59 + HoverTemplateArray.GetHashCode(); } if (ShowLegend != null) { hashCode = hashCode * 59 + ShowLegend.GetHashCode(); } if (CAuto != null) { hashCode = hashCode * 59 + CAuto.GetHashCode(); } if (CMin != null) { hashCode = hashCode * 59 + CMin.GetHashCode(); } if (CMax != null) { hashCode = hashCode * 59 + CMax.GetHashCode(); } if (CMid != null) { hashCode = hashCode * 59 + CMid.GetHashCode(); } if (ColorScale != null) { hashCode = hashCode * 59 + ColorScale.GetHashCode(); } if (AutoColorScale != null) { hashCode = hashCode * 59 + AutoColorScale.GetHashCode(); } if (ReverseScale != null) { hashCode = hashCode * 59 + ReverseScale.GetHashCode(); } if (ShowScale != null) { hashCode = hashCode * 59 + ShowScale.GetHashCode(); } if (ColorBar != null) { hashCode = hashCode * 59 + ColorBar.GetHashCode(); } if (ColorAxis != null) { hashCode = hashCode * 59 + ColorAxis.GetHashCode(); } if (Opacity != null) { hashCode = hashCode * 59 + Opacity.GetHashCode(); } if (LightPosition != null) { hashCode = hashCode * 59 + LightPosition.GetHashCode(); } if (Lighting != null) { hashCode = hashCode * 59 + Lighting.GetHashCode(); } if (HoverInfo != null) { hashCode = hashCode * 59 + HoverInfo.GetHashCode(); } if (HoverInfoArray != null) { hashCode = hashCode * 59 + HoverInfoArray.GetHashCode(); } if (Scene != null) { hashCode = hashCode * 59 + Scene.GetHashCode(); } if (IdsSrc != null) { hashCode = hashCode * 59 + IdsSrc.GetHashCode(); } if (CustomDataSrc != null) { hashCode = hashCode * 59 + CustomDataSrc.GetHashCode(); } if (MetaSrc != null) { hashCode = hashCode * 59 + MetaSrc.GetHashCode(); } if (XSrc != null) { hashCode = hashCode * 59 + XSrc.GetHashCode(); } if (YSrc != null) { hashCode = hashCode * 59 + YSrc.GetHashCode(); } if (ZSrc != null) { hashCode = hashCode * 59 + ZSrc.GetHashCode(); } if (USrc != null) { hashCode = hashCode * 59 + USrc.GetHashCode(); } if (VSrc != null) { hashCode = hashCode * 59 + VSrc.GetHashCode(); } if (WSrc != null) { hashCode = hashCode * 59 + WSrc.GetHashCode(); } if (HoverTemplateSrc != null) { hashCode = hashCode * 59 + HoverTemplateSrc.GetHashCode(); } if (HoverInfoSrc != null) { hashCode = hashCode * 59 + HoverInfoSrc.GetHashCode(); } return(hashCode); } }