Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix less than/greater than operators in empty arrays #91

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/RulesEngine/Models/ImplicitObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,61 @@
// Licensed under the MIT License.
// https://github.com/asulwer/RulesEngine/issues/75

using System;
using System.Diagnostics.CodeAnalysis;

namespace RulesEngine.Models
{
[ExcludeFromCodeCoverage]
public class ImplicitObject
public class ImplicitObject : IEquatable<ImplicitObject>
{
public static implicit operator ImplicitObject(bool value) => default;
public static implicit operator ImplicitObject(bool _) => default;

public static implicit operator ImplicitObject(bool? value) => default;
public static implicit operator ImplicitObject(bool? _) => default;

public static implicit operator ImplicitObject(char value) => default;
public static implicit operator ImplicitObject(char _) => default;

public static implicit operator ImplicitObject(char? value) => default;
public static implicit operator ImplicitObject(char? _) => default;

public static implicit operator ImplicitObject(string value) => default;
public static implicit operator ImplicitObject(string _) => default;

public static implicit operator ImplicitObject(int value) => default;
public static implicit operator ImplicitObject(int _) => default;

public static implicit operator ImplicitObject(int? value) => default;
public static implicit operator ImplicitObject(int? _) => default;

public static implicit operator ImplicitObject(decimal value) => default;
public static implicit operator ImplicitObject(decimal _) => default;

public static implicit operator ImplicitObject(decimal? value) => default;
public static implicit operator ImplicitObject(decimal? _) => default;

public static implicit operator ImplicitObject(float value) => default;
public static implicit operator ImplicitObject(float _) => default;

public static implicit operator ImplicitObject(float? value) => default;
public static implicit operator ImplicitObject(float? _) => default;

public static bool operator <(ImplicitObject l, ImplicitObject r) => default;

public static bool operator >(ImplicitObject l, ImplicitObject r) => default;

public static bool operator <=(ImplicitObject l, ImplicitObject r) => default;

public static bool operator >=(ImplicitObject l, ImplicitObject r) => default;

public static bool operator ==(ImplicitObject l, ImplicitObject r) => default;

public static bool operator !=(ImplicitObject l, ImplicitObject r) => default;

public bool Equals(ImplicitObject other)
{
return default;
}

public override bool Equals(object obj)
{
return default;
}

public override int GetHashCode()
{
return default;
}
}
}
39 changes: 32 additions & 7 deletions test/RulesEngine.UnitTest/EmptyArrayTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,32 @@ private async Task EmptyArray_ReturnsExepectedResults()
WorkflowName = "Workflow",
Rules = [
new() {
RuleName = "empty array",
Expression = "not things.Any(a == 3)",
RuleExpressionType = RuleExpressionType.LambdaExpression
RuleName = "equal string",
Expression = "not things.Any(a == \"widget\")"
},
new() {
RuleName = "equal integer",
Expression = "not things.Any(a == 3)"
},
new() {
RuleName = "not equal integer",
Expression = "not things.Any(a != 3)"
},
new() {
RuleName = "greater than integer",
Expression = "not things.Any(a > 3)"
},
new() {
RuleName = "less than integer",
Expression = "not things.Any(a < 3)"
},
new() {
RuleName = "greater than equal to integer",
Expression = "not things.Any(a >= 3)"
},
new() {
RuleName = "less than equal to integer",
Expression = "not things.Any(a <= 3)"
}
]
}
Expand All @@ -50,12 +73,14 @@ private async Task EmptyArray_ReturnsExepectedResults()
CancellationTokenSource cancellationTokenSource = new();
List<RuleResultTree> results = await rulesEngine.ExecuteAllRulesAsync("Workflow", cancellationTokenSource.Token, target);

Assert.Single(results);
Assert.True(results.TrueForAll(r => r.IsSuccess));

var result = results[0];
foreach (var result in results)
{
Assert.Equal(result.ExceptionMessage, string.Empty);
Assert.True(result.IsSuccess);
}

Assert.Equal(result.ExceptionMessage, string.Empty);
Assert.True(result.IsSuccess);

}

Expand Down
8 changes: 4 additions & 4 deletions test/RulesEngine.UnitTest/NestedRulesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public async Task NestedRulesShouldFollowExecutionMode(NestedRuleExecutionMode m
Assert.All(andResults,
c => {
Assert.Equal(c.IsSuccess, c.ChildResults.Last().IsSuccess);
Assert.Single(c.ChildResults.Where(d => c.IsSuccess == d.IsSuccess));
Assert.Single(c.ChildResults, d => c.IsSuccess == d.IsSuccess);
Assert.True(c.ChildResults.SkipLast(1).All(d => d.IsSuccess == true));
});

Assert.All(orResults,
c => {
Assert.Equal(c.IsSuccess, c.ChildResults.Last().IsSuccess);
Assert.Single(c.ChildResults.Where(d => c.IsSuccess == d.IsSuccess));
Assert.Single(c.ChildResults, d => c.IsSuccess == d.IsSuccess);
Assert.True(c.ChildResults.SkipLast(1).All(d => d.IsSuccess == false));
});
}
Expand Down Expand Up @@ -240,14 +240,14 @@ public async Task NestedRulesShouldFollowExecutionMode(NestedRuleExecutionMode m
Assert.All(andResults,
c => {
Assert.Equal(c.IsSuccess, c.ChildResults.Last().IsSuccess);
Assert.Single(c.ChildResults.Where(d => c.IsSuccess == d.IsSuccess));
Assert.Single(c.ChildResults, d => c.IsSuccess == d.IsSuccess);
Assert.True(c.ChildResults.SkipLast(1).All(d => d.IsSuccess == true));
});

Assert.All(orResults,
c => {
Assert.Equal(c.IsSuccess, c.ChildResults.Last().IsSuccess);
Assert.Single(c.ChildResults.Where(d => c.IsSuccess == d.IsSuccess));
Assert.Single(c.ChildResults, d => c.IsSuccess == d.IsSuccess);
Assert.True(c.ChildResults.SkipLast(1).All(d => d.IsSuccess == false));
});
}
Expand Down