Skip to content

Commit

Permalink
Property renames and tiny code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyIvon committed Feb 17, 2024
1 parent 7122c3d commit ea4eefe
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/DatabaseBenchmark/Generators/ColumnItemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ private object[] ReadValues()
var values = new List<object>();

int index = 0;
while (results.Read() && (_options.MaxRows <= 0 || values.Count < _options.MaxRows))
while (results.Read() && (_options.MaxSourceRows <= 0 || values.Count < _options.MaxSourceRows))
{
if (_options.SkipRows <= 0 || index % (_options.SkipRows + 1) == 0)
if (_options.SkipSourceRows <= 0 || index % (_options.SkipSourceRows + 1) == 0)
{
values.Add(results.GetValue(_options.ColumnName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public bool Next()

public void Dispose() => _query.Dispose();

//TODO: Make shared between two generators
private void Initialize()
{
var table = new Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class ColumnItemGeneratorOptions : GeneratorOptionsBase

public WeightedListItem[] WeightedItems { get; set; }

public int MaxRows { get; set; } = 0;
public int MaxSourceRows { get; set; } = 0;

public int SkipRows { get; set; } = 0;
public int SkipSourceRows { get; set; } = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ColumnItemGeneratorTests()
}

[Fact]
public void GenerateValueFromItems()
public void GenerateValue()
{
var generator = new ColumnItemGenerator(_faker, _options, _database);

Expand All @@ -46,7 +46,7 @@ public void GenerateValueFromItems()
}

[Fact]
public void GenerateCollectionFromItems()
public void GenerateCollection()
{
var generator = new ColumnItemGenerator(_faker, _options, _database);

Expand All @@ -58,6 +58,20 @@ public void GenerateCollectionFromItems()
_database.CreateQueryExecutorFactory(Arg.Any<Table>(), Arg.Any<Query>()).Received(1);
}

[Fact]
public void GenerateValueWithMaxSourceRows()
{
_options.MaxSourceRows = 1;

var generator = new ColumnItemGenerator(_faker, _options, _database);

generator.Next();
var value = generator.Current;

Assert.Equal((int)value, TestQueryResults.Values[0]);
_database.CreateQueryExecutorFactory(Arg.Any<Table>(), Arg.Any<Query>()).Received(1);
}

private class TestQueryResults : IQueryResults
{
public static int[] Values = [1, 2, 3, 4, 5];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ColumnIteratorGeneratorTests()
}

[Fact]
public void Generate()
public void GenerateValue()
{
var generator = new ColumnIteratorGenerator(_options, _database);
var items = new List<object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void GenerateNoItemsError()
}

[Fact]
public void GenerateWeightedItemsTooHighTotalError()
public void GenerateFromWeightedItemsTooHighTotalError()
{
_weightedItems[0].Weight = 1;

Expand All @@ -145,7 +145,7 @@ public void GenerateWeightedItemsTooHighTotalError()
}

[Fact]
public void GenerateWeightedItemsNoItemsError()
public void GenerateFromWeightedItemsNoItemsError()
{
var generator = new ListItemGenerator(
_faker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ListIteratorGeneratorTests
];

[Fact]
public void Generate()
public void GenerateValue()
{
var generator = new ListIteratorGenerator(
new ListIteratorGeneratorOptions { Items = _items });
Expand Down

0 comments on commit ea4eefe

Please sign in to comment.