Skip to content

Commit

Permalink
Optimize unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcean committed Nov 13, 2024
1 parent 3e5f90c commit 3962c6f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Text.Json" Version="6.0.10" />
<PackageReference Include="System.Text.Json" Version="6.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Core/Maths/Boolean/Operations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public static bool Calculate(CriteriaBooleanOperator op, IEnumerable<bool> input
/// </summary>
/// <param name="op">The operation.</param>
/// <param name="col">The collection to calculate each other in the unary boolean operation.</param>
/// <returns>A boolean sequence after calculating.</returns>
/// <returns>A boolean sequence after calculating; or null, if the input is null, or the invalid to calculate.</returns>
/// <exception cref="NotSupportedException">op is not valid.</exception>
public static bool? Calculate(SequenceBooleanOperator op, IEnumerable<bool> col)
{
Expand Down
16 changes: 3 additions & 13 deletions Core/Text/Json/ArrayNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2168,21 +2168,15 @@ protected override BaseJsonValueNode TryGetValueOrNull(string key)
/// <param name="key">The property key.</param>
/// <returns>The value.</returns>
public BaseJsonValueNode TryGetValue(ReadOnlySpan<char> key)
{
if (key == null) return null;
return TryGetValue(key.ToString());
}
=> TryGetValue(key.ToString());

/// <summary>
/// Tries to get the value of the specific property.
/// </summary>
/// <param name="key">The property key.</param>
/// <returns>The value.</returns>
protected override BaseJsonValueNode TryGetValueOrNull(ReadOnlySpan<char> key)
{
if (key == null) return null;
return TryGetValueOrNull(key.ToString());
}
=> TryGetValueOrNull(key.ToString());

/// <summary>
/// Removes the element at the specific index.
Expand Down Expand Up @@ -4929,11 +4923,7 @@ public bool TryGetValue(string key, out BaseJsonValueNode result)
/// <param name="result">The result.</param>
/// <returns>true if the kind is the one expected; otherwise, false.</returns>
public bool TryGetValue(ReadOnlySpan<char> key, out BaseJsonValueNode result)
{
if (key != null) return TryGetValue(key.ToString(), out result);
result = default;
return false;
}
=> TryGetValue(key.ToString(), out result);

/// <summary>
/// Gets all property keys.
Expand Down
40 changes: 7 additions & 33 deletions Core/Text/Json/ObjectNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,7 @@ public bool ContainsKey(string key)
/// <returns>true if it contains the property key; otherwise, false.</returns>
/// <exception cref="ArgumentNullException">key was null, empty or consists only of white-space characters.</exception>
public bool ContainsKey(ReadOnlySpan<char> key)
{
if (key == null) throw new ArgumentNullException(nameof(key), "key should not be null.");
return ContainsKey(key.ToString());
}
=> ContainsKey(key.ToString());

/// <summary>
/// Determines whether it contains the property only with the specific key.
Expand Down Expand Up @@ -758,10 +755,7 @@ public string GetRawText(string key)
/// <exception cref="ArgumentOutOfRangeException">The property does not exist.</exception>
/// <exception cref="InvalidOperationException">The value kind is not the expected one.</exception>
public string GetRawText(ReadOnlySpan<char> key)
{
if (key == null) throw new ArgumentNullException(nameof(key), "key should not be null.");
return GetRawText(key.ToString());
}
=> GetRawText(key.ToString());

/// <summary>
/// Gets the value kind of the specific property.
Expand Down Expand Up @@ -847,10 +841,7 @@ public JsonValueKind GetValueKind(string key, out object result)
/// <exception cref="ArgumentNullException">The property key should not be null, empty, or consists only of white-space characters.</exception>
/// <exception cref="ArgumentOutOfRangeException">The property does not exist.</exception>
public JsonValueKind GetValueKind(ReadOnlySpan<char> key, bool strictMode = false)
{
if (key == null) throw new ArgumentNullException(nameof(key), "key should not be null.");
return GetValueKind(key.ToString(), strictMode);
}
=> GetValueKind(key.ToString(), strictMode);

/// <summary>
/// Gets the value of the specific property.
Expand Down Expand Up @@ -1370,10 +1361,7 @@ public BaseJsonValueNode GetValue(string key, string subKey, params string[] key
/// <exception cref="ArgumentNullException">The property key should not be null, empty, or consists only of white-space characters.</exception>
/// <exception cref="ArgumentOutOfRangeException">The property does not exist.</exception>
public BaseJsonValueNode GetValue(ReadOnlySpan<char> key)
{
if (key == null) throw new ArgumentNullException(nameof(key), "key should not be null.");
return GetValue(key.ToString());
}
=> GetValue(key.ToString());

/// <summary>
/// Gets the value of the specific property.
Expand Down Expand Up @@ -1451,10 +1439,7 @@ public T GetValue<T>(string key)
/// <exception cref="ArgumentOutOfRangeException">The property does not exist.</exception>
/// <exception cref="InvalidOperationException">The type is not supported to convert.</exception>
public T GetValue<T>(ReadOnlySpan<char> key)
{
if (key == null) throw new ArgumentNullException(nameof(key), "key should not be null.");
return (T)GetValue(typeof(T), key.ToString());
}
=> (T)GetValue(typeof(T), key.ToString());

/// <summary>
/// Gets the value of the specific property.
Expand Down Expand Up @@ -3209,15 +3194,7 @@ public bool TryGetValue(string key, out BaseJsonValueNode result)
/// <param name="result">The result.</param>
/// <returns>true if the kind is the one expected; otherwise, false.</returns>
public bool TryGetValue(ReadOnlySpan<char> key, out BaseJsonValueNode result)
{
if (key == null)
{
result = default;
return false;
}

return TryGetValue(key.ToString(), out result);
}
=> TryGetValue(key.ToString(), out result);

/// <summary>
/// Tries to get the value of the specific property.
Expand Down Expand Up @@ -3745,10 +3722,7 @@ public bool Remove(string key)
/// <returns>true if the element is successfully removed; otherwise, false. This method also returns false if key was not found.</returns>
/// <exception cref="ArgumentNullException">The property key should not be null, empty, or consists only of white-space characters.</exception>
public bool Remove(ReadOnlySpan<char> key)
{
if (key == null) throw new ArgumentNullException(nameof(key), "key was null.");
return RemoveProperty(key.ToString());
}
=> RemoveProperty(key.ToString());

/// <summary>
/// Removes all properties of the specific key.
Expand Down
46 changes: 46 additions & 0 deletions UnitTest/Maths/ArithmeticTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,51 @@ public void TestFormula()
Assert.IsTrue(c[1]);
Assert.IsFalse(c[2]);
Assert.IsFalse(c[3]);

var col = new List<bool>()
{
true, false, false, true, false, true, false, true, false
};
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.And, col, true));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Or, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Nand, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Nor, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.First, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Last, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Half, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Nhalf, col, false));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Most, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Least, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.MostOrFirst, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.MostOrLast, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.LeastOrFirst, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.LeastOrLast, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Positive, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Negative, col));
col.Add(true);
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.And, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Or, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Nand, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Nor, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.First, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Last, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Half, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Nhalf, col));
Assert.IsNull(BooleanOperations.Calculate(SequenceBooleanOperator.Most, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.Least, col, false));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.MostOrFirst, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.MostOrLast, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.LeastOrFirst, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.LeastOrLast, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Positive, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Negative, col));
col.Clear();
Assert.IsNull(BooleanOperations.Calculate(SequenceBooleanOperator.And, col));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Or, col, true));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.Half, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.First, col, false));
Assert.IsNull(BooleanOperations.Calculate(SequenceBooleanOperator.First, null));
Assert.IsTrue(BooleanOperations.Calculate(SequenceBooleanOperator.True, col));
Assert.IsFalse(BooleanOperations.Calculate(SequenceBooleanOperator.False, col));
}
}
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ variables:
buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
displayName: 'Use .NET SDK 9.0'
inputs:
version: 9.0.x
includePreviewVersions: true

- task: UseDotNet@2
displayName: 'Use .NET SDK 8.0'
inputs:
Expand Down

0 comments on commit 3962c6f

Please sign in to comment.