feat: implement generic data set manipulator, ref: NOISSUE
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
namespace TextParser.Tests;
|
||||
|
||||
using Parsing;
|
||||
using Parsing.Data;
|
||||
using Parsing.Schema;
|
||||
using Parsing.Schema.BuildingBlocks;
|
||||
using Parsing.Tokenization;
|
||||
|
||||
public class TextParserTests
|
||||
@@ -26,6 +26,10 @@ public class TextParserTests
|
||||
private const string testInput7 = @"adfdf1()324ddf3()()()svsdvs
|
||||
davnsldkvjs2()()m23423()()()
|
||||
mcsodkcn owdjnfj 1() asdfnad 23234 2()() sdvsdv";
|
||||
private const string testInput8 = @"2 4 6 4 1 3 5 4 7 2 4 6 8 3";
|
||||
private const string testInput9 = @"2 4 6 4 1
|
||||
3 5 4 7 6
|
||||
4 6 8 3 9";
|
||||
|
||||
[Fact]
|
||||
public void LineParser_TestSimpleRepetition()
|
||||
@@ -295,11 +299,11 @@ public class TextParserTests
|
||||
if (saw1)
|
||||
{
|
||||
indicator += 1;
|
||||
}
|
||||
}
|
||||
if (saw2)
|
||||
{
|
||||
indicator += 2;
|
||||
}
|
||||
}
|
||||
if (saw3)
|
||||
{
|
||||
indicator += 4;
|
||||
@@ -315,4 +319,74 @@ public class TextParserTests
|
||||
Assert.Equal(1, convertedData[4]);
|
||||
Assert.Equal(2, convertedData[5]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DataManipulator_SimpleOneDimensionalTest()
|
||||
{
|
||||
var schemaBuilder = new InputSchemaBuilder();
|
||||
var schema = schemaBuilder
|
||||
.Repeat()
|
||||
.Expect(InputType.Integer)
|
||||
.EndRepetition()
|
||||
.Build();
|
||||
|
||||
var parser = new TextParser<InputSchemaContext>(schema);
|
||||
var row = parser
|
||||
.SetInputText(testInput8)
|
||||
.Parse()
|
||||
.AsSingleStream<int>();
|
||||
|
||||
var searchSequence = new List<int> { 4, 6 };
|
||||
var manipulator = DefaultOneDimensionalManipulator.Create(row);
|
||||
var searchResults = manipulator.FindInSet(searchSequence);
|
||||
|
||||
Assert.Equal(3, searchResults.Count);
|
||||
Assert.Equal(1, searchResults[0].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(3, searchResults[1].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(10, searchResults[2].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(Direction.Forward, searchResults[0].Direction);
|
||||
Assert.Equal(Direction.Backward, searchResults[1].Direction);
|
||||
Assert.Equal(Direction.Forward, searchResults[2].Direction);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DataManipulator_SimpleTwoDimensionalTest()
|
||||
{
|
||||
var schemaBuilder = new InputSchemaBuilder();
|
||||
var schema = schemaBuilder
|
||||
.Repeat()
|
||||
.Expect(InputType.Integer)
|
||||
.EndRepetition()
|
||||
.Build();
|
||||
|
||||
var parser = new TextParser<InputSchemaContext>(schema);
|
||||
var row = parser
|
||||
.SetInputText(testInput9)
|
||||
.Parse()
|
||||
.AsListRows<int>();
|
||||
|
||||
var searchSequence = new List<int> { 4, 6 };
|
||||
var manipulator = DefaultTwoDimensionalManipulator.Create(row);
|
||||
var searchResults = manipulator.FindInSet(searchSequence);
|
||||
|
||||
Assert.Equal(6, searchResults.Count);
|
||||
Assert.Equal(0, searchResults[0].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(0, searchResults[0].DataIndex.GetIndices()[1]);
|
||||
Assert.Equal(2, searchResults[1].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(1, searchResults[1].DataIndex.GetIndices()[1]);
|
||||
Assert.Equal(2, searchResults[2].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(1, searchResults[2].DataIndex.GetIndices()[1]);
|
||||
Assert.Equal(1, searchResults[3].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(2, searchResults[3].DataIndex.GetIndices()[1]);
|
||||
Assert.Equal(3, searchResults[4].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(2, searchResults[4].DataIndex.GetIndices()[1]);
|
||||
Assert.Equal(3, searchResults[5].DataIndex.GetIndices()[0]);
|
||||
Assert.Equal(2, searchResults[5].DataIndex.GetIndices()[1]);
|
||||
Assert.Equal(Direction.E, searchResults[0].Direction);
|
||||
Assert.Equal(Direction.N, searchResults[1].Direction);
|
||||
Assert.Equal(Direction.SW, searchResults[2].Direction);
|
||||
Assert.Equal(Direction.E, searchResults[3].Direction);
|
||||
Assert.Equal(Direction.SE, searchResults[4].Direction);
|
||||
Assert.Equal(Direction.W, searchResults[5].Direction);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user