Skip to content

Commit

Permalink
Various tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
langsamu committed Dec 20, 2024
1 parent ce4ac11 commit 6077bfe
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.4" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.4" />
</ItemGroup>
</Project>
</Project>
80 changes: 40 additions & 40 deletions GraphEngine.Tests/BinaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,51 @@ public static IEnumerable<object[]> Data
{
get
{
yield return new object[] { Linq.ExpressionType.Add };
yield return new object[] { Linq.ExpressionType.AddAssign };
yield return new object[] { Linq.ExpressionType.AddAssignChecked };
yield return new object[] { Linq.ExpressionType.AddChecked };
yield return new object[] { Linq.ExpressionType.And };
yield return new object[] { Linq.ExpressionType.AndAlso, typeof(bool) };
yield return new object[] { Linq.ExpressionType.AndAssign };
yield return new object[] { Linq.ExpressionType.ArrayIndex, typeof(int[]), typeof(int) };
yield return new object[] { Linq.ExpressionType.Assign };
yield return new object[] { Linq.ExpressionType.Coalesce, typeof(object) };
yield return new object[] { Linq.ExpressionType.Divide };
yield return new object[] { Linq.ExpressionType.DivideAssign };
yield return new object[] { Linq.ExpressionType.Equal };
yield return new object[] { Linq.ExpressionType.ExclusiveOr };
yield return new object[] { Linq.ExpressionType.ExclusiveOrAssign };
yield return new object[] { Linq.ExpressionType.GreaterThan };
yield return new object[] { Linq.ExpressionType.GreaterThanOrEqual };
yield return new object[] { Linq.ExpressionType.LeftShift };
yield return new object[] { Linq.ExpressionType.LeftShiftAssign };
yield return new object[] { Linq.ExpressionType.LessThan };
yield return new object[] { Linq.ExpressionType.LessThanOrEqual };
yield return new object[] { Linq.ExpressionType.Modulo };
yield return new object[] { Linq.ExpressionType.ModuloAssign };
yield return new object[] { Linq.ExpressionType.Multiply };
yield return new object[] { Linq.ExpressionType.MultiplyAssign };
yield return new object[] { Linq.ExpressionType.MultiplyAssignChecked };
yield return new object[] { Linq.ExpressionType.MultiplyChecked };
yield return new object[] { Linq.ExpressionType.NotEqual };
yield return new object[] { Linq.ExpressionType.Or };
yield return new object[] { Linq.ExpressionType.OrAssign };
yield return new object[] { Linq.ExpressionType.OrElse, typeof(bool) };
yield return new object[] { Linq.ExpressionType.Power, typeof(double) };
yield return new object[] { Linq.ExpressionType.PowerAssign, typeof(double) };
yield return new object[] { Linq.ExpressionType.RightShift };
yield return new object[] { Linq.ExpressionType.RightShiftAssign };
yield return new object[] { Linq.ExpressionType.Subtract };
yield return new object[] { Linq.ExpressionType.SubtractAssign };
yield return new object[] { Linq.ExpressionType.SubtractAssignChecked };
yield return new object[] { Linq.ExpressionType.SubtractChecked };
yield return [Linq.ExpressionType.Add];
yield return [Linq.ExpressionType.AddAssign];
yield return [Linq.ExpressionType.AddAssignChecked];
yield return [Linq.ExpressionType.AddChecked];
yield return [Linq.ExpressionType.And];
yield return [Linq.ExpressionType.AndAlso, typeof(bool)];
yield return [Linq.ExpressionType.AndAssign];
yield return [Linq.ExpressionType.ArrayIndex, typeof(int[]), typeof(int)];
yield return [Linq.ExpressionType.Assign];
yield return [Linq.ExpressionType.Coalesce, typeof(object)];
yield return [Linq.ExpressionType.Divide];
yield return [Linq.ExpressionType.DivideAssign];
yield return [Linq.ExpressionType.Equal];
yield return [Linq.ExpressionType.ExclusiveOr];
yield return [Linq.ExpressionType.ExclusiveOrAssign];
yield return [Linq.ExpressionType.GreaterThan];
yield return [Linq.ExpressionType.GreaterThanOrEqual];
yield return [Linq.ExpressionType.LeftShift];
yield return [Linq.ExpressionType.LeftShiftAssign];
yield return [Linq.ExpressionType.LessThan];
yield return [Linq.ExpressionType.LessThanOrEqual];
yield return [Linq.ExpressionType.Modulo];
yield return [Linq.ExpressionType.ModuloAssign];
yield return [Linq.ExpressionType.Multiply];
yield return [Linq.ExpressionType.MultiplyAssign];
yield return [Linq.ExpressionType.MultiplyAssignChecked];
yield return [Linq.ExpressionType.MultiplyChecked];
yield return [Linq.ExpressionType.NotEqual];
yield return [Linq.ExpressionType.Or];
yield return [Linq.ExpressionType.OrAssign];
yield return [Linq.ExpressionType.OrElse, typeof(bool)];
yield return [Linq.ExpressionType.Power, typeof(double)];
yield return [Linq.ExpressionType.PowerAssign, typeof(double)];
yield return [Linq.ExpressionType.RightShift];
yield return [Linq.ExpressionType.RightShiftAssign];
yield return [Linq.ExpressionType.Subtract];
yield return [Linq.ExpressionType.SubtractAssign];
yield return [Linq.ExpressionType.SubtractAssignChecked];
yield return [Linq.ExpressionType.SubtractChecked];
}
}

[TestMethod]
[DynamicData(nameof(Data))]
public void Regular(Linq.ExpressionType binaryType, System.Type leftType = null, System.Type rightType = null)
public void Regular(Linq.ExpressionType binaryType, System.Type? leftType = null, System.Type? rightType = null)
{
leftType ??= typeof(int);
rightType ??= leftType;
Expand Down
16 changes: 9 additions & 7 deletions GraphEngine.Tests/SampleClass.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// MIT License, Copyright 2020 Samu Lang

#pragma warning disable CA1051 // Do not declare visible instance fields
#pragma warning disable CA1801 // Review unused parameters
#pragma warning disable IDE0079 // Remove unnecessary suppression
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
#pragma warning disable CA2211 // Non-constant fields should not be visible
#pragma warning disable SA1401 // Fields should be private
#pragma warning disable SA1402 // File may only contain a single type
#pragma warning disable CA1822 // Mark members as static
#pragma warning disable IDE0060 // Remove unused parameter

namespace GraphEngine.Tests;

Expand All @@ -25,7 +26,7 @@ public class SampleClass
[IndexerName("Indexer")]
public string this[int index]
{
get => default;
get => default!;
set { }
}

Expand Down Expand Up @@ -70,8 +71,9 @@ public class SampleDerivedClass : SampleClass
{
}

#pragma warning restore CA1051 // Do not declare visible instance fields
#pragma warning restore CA1801 // Review unused parameters
#pragma warning restore IDE0060 // Remove unused parameter
#pragma warning restore CA1822 // Mark members as static
#pragma warning restore CA2211 // Non-constant fields should not be visible
#pragma warning restore SA1401 // Fields should be private
#pragma warning restore SA1402 // File may only contain a single type
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
#pragma warning restore IDE0079 // Remove unnecessary suppression
7 changes: 2 additions & 5 deletions GraphEngine/BaseBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public Member Member

internal static BaseBind Parse(NodeWithGraph node)
{
if (node is null)
{
throw new ArgumentNullException(nameof(node));
}
ArgumentNullException.ThrowIfNull(node);

return Vocabulary.RdfType.ObjectOf(node) switch
{
Expand All @@ -36,7 +33,7 @@ internal static BaseBind Parse(NodeWithGraph node)
INode t when t.Equals(Vocabulary.MemberBind) => new MemberBind(node),

null => throw new Exception($"type not found on node {node}"),
INode t => throw new Exception($"unknown bind type {t} on node {node}"),
var t => throw new Exception($"unknown bind type {t} on node {node}"),
};
}
}
7 changes: 2 additions & 5 deletions GraphEngine/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,15 @@ public ExpressionType? ExpressionType

internal static Binder Parse(NodeWithGraph node)
{
if (node is null)
{
throw new ArgumentNullException(nameof(node));
}
ArgumentNullException.ThrowIfNull(node);

return Vocabulary.RdfType.ObjectOf(node) switch
{
INode t when t.Equals(Vocabulary.InvokeMember) => new InvokeMember(node),
INode t when t.Equals(Vocabulary.BinaryOperation) => new BinaryOperation(node),

null => throw new Exception($"type not found on node {node}"),
INode t => throw new Exception($"unknown binder type {t} on node {node}"),
var t => throw new Exception($"unknown binder type {t} on node {node}"),
};
}
}
2 changes: 1 addition & 1 deletion GraphEngine/Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace GraphEngine;

public class Graph : WrapperGraph
{
private static readonly IInferenceEngine Reasoner = new StaticRdfsReasoner();
private static readonly StaticRdfsReasoner Reasoner = new();

static Graph()
{
Expand Down
14 changes: 8 additions & 6 deletions GraphEngine/SerialisingVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class SerialisingVisitor(NodeWithGraph node) : Linq.ExpressionVisitor()
{
private readonly Dictionary<object, NodeWithGraph> mapping = [];
private readonly NodeWithGraph node = node ?? throw new ArgumentNullException(nameof(node));
private readonly Stack<NodeWithGraph> path = new ();
private readonly Stack<NodeWithGraph> path = new();
private bool initialised;

private NodeWithGraph Current => this.path.Peek();
Expand All @@ -36,7 +36,7 @@ private NodeWithGraph this[object index]
}
}

public override Linq.Expression Visit(Linq.Expression node)
public override Linq.Expression Visit(Linq.Expression? node)
{
using (this.Wrap(node))
{
Expand Down Expand Up @@ -298,7 +298,7 @@ protected override Linq.Expression VisitIndex(Linq.IndexExpression node)
return node;
}

protected override Linq.LabelTarget VisitLabelTarget(Linq.LabelTarget node)
protected override Linq.LabelTarget VisitLabelTarget(Linq.LabelTarget? node)
{
using (this.Wrap(node))
{
Expand Down Expand Up @@ -372,8 +372,9 @@ protected override Linq.Expression VisitMember(Linq.MemberExpression node)
{
var memberAccess = node.Member.MemberType switch
{
MemberTypes.Field => (MemberAccess)new Field(this.Current),
MemberTypes.Property => (MemberAccess)new Property(this.Current),
MemberTypes.Field => new Field(this.Current) as MemberAccess,
MemberTypes.Property => new Property(this.Current) as MemberAccess,
var mt => throw new Exception($"unknown member type {mt}")
};

memberAccess.Name = node.Member.Name;
Expand Down Expand Up @@ -411,6 +412,7 @@ protected override Linq.MemberBinding VisitMemberBinding(Linq.MemberBinding node
Linq.MemberAssignment binding => this.VisitMemberAssignment(binding),
Linq.MemberMemberBinding binding => this.VisitMemberMemberBinding(binding),
Linq.MemberListBinding binding => this.VisitMemberListBinding(binding),
var n => throw new Exception($"unknown member binding {n}")
};
}
}
Expand Down Expand Up @@ -716,7 +718,7 @@ private Type VisitType(System.Type type)
}
}

private IDisposable Wrap(object node) => new Wrapper(this, this[node]);
private Wrapper Wrap(object node) => new(this, this[node]);

private readonly struct Wrapper : IDisposable
{
Expand Down

0 comments on commit 6077bfe

Please sign in to comment.