diff --git a/CI/azure-pipelines.yml b/CI/azure-pipelines.yml
index ad878878c..bd7f3304b 100644
--- a/CI/azure-pipelines.yml
+++ b/CI/azure-pipelines.yml
@@ -71,7 +71,7 @@ jobs:
- task: PublishPipelineArtifact@1
inputs:
- path: xFunc.Maths/bin/Release/netstandard2.1
+ path: xFunc.Maths/bin/Release/net6.0
artifact: xFunc.Maths
- task: PublishPipelineArtifact@1
diff --git a/xFunc.DotnetTool/xFunc.DotnetTool.csproj b/xFunc.DotnetTool/xFunc.DotnetTool.csproj
index 309bfead9..4365e6ee5 100644
--- a/xFunc.DotnetTool/xFunc.DotnetTool.csproj
+++ b/xFunc.DotnetTool/xFunc.DotnetTool.csproj
@@ -7,7 +7,7 @@
true
xFunc
xFunc.DotnetTool
- 4.1.0
+ 4.2.0
xFunc.Maths
Dmytro Kyshchenko
@@ -15,8 +15,8 @@
https://github.com/sys27/xFunc
xFunc.png
Math Expression Expressions Parser MathParser Differentiation Simplification
- 4.1.0
- 4.1.0
+ 4.2.0
+ 4.2.0
https://github.com/sys27/xFunc
GitHub
MIT
diff --git a/xFunc.Maths/Expressions/Units/AngleUnits/AngleUnit.cs b/xFunc.Maths/Expressions/Units/AngleUnits/AngleUnit.cs
index d160d1e24..96868d206 100644
--- a/xFunc.Maths/Expressions/Units/AngleUnits/AngleUnit.cs
+++ b/xFunc.Maths/Expressions/Units/AngleUnits/AngleUnit.cs
@@ -50,12 +50,28 @@ private AngleUnit(double factor, params string[] unitNames)
=> !left.Equals(right);
///
- public bool Equals(AngleUnit other)
- => Factor.Equals(other.Factor) && UnitNames.SequenceEqual(other.UnitNames);
+ public bool Equals(AngleUnit? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return Factor.Equals(other.Factor) && UnitNames.Equals(other.UnitNames);
+ }
///
public override bool Equals(object? obj)
- => obj is AngleUnit other && Equals(other);
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+ if (ReferenceEquals(this, obj))
+ return true;
+ if (obj.GetType() != GetType())
+ return false;
+
+ return Equals((AngleUnit)obj);
+ }
///
[ExcludeFromCodeCoverage]
@@ -116,7 +132,7 @@ static void AddUnits(IDictionary dictionary, AngleUnit unit)
/// When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
/// true if area units contain an unit with the specified ; otherwise, false.
/// is null.
- public static bool FromName(string name, out AngleUnit unit)
+ public static bool FromName(string name, [NotNullWhen(true)] out AngleUnit? unit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
diff --git a/xFunc.Maths/Expressions/Units/AreaUnits/AreaUnit.cs b/xFunc.Maths/Expressions/Units/AreaUnits/AreaUnit.cs
index 1ac583eae..1eb044ddd 100644
--- a/xFunc.Maths/Expressions/Units/AreaUnits/AreaUnit.cs
+++ b/xFunc.Maths/Expressions/Units/AreaUnits/AreaUnit.cs
@@ -85,12 +85,31 @@ private AreaUnit(double factor, string unitName)
=> !left.Equals(right);
///
- public bool Equals(AreaUnit other)
- => Factor.Equals(other.Factor) && UnitName == other.UnitName;
+ public bool Equals(AreaUnit? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return Factor.Equals(other.Factor) && UnitName == other.UnitName;
+ }
///
public override bool Equals(object? obj)
- => obj is AreaUnit other && Equals(other);
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+
+ if (ReferenceEquals(this, obj))
+ return true;
+
+ if (obj.GetType() != GetType())
+ return false;
+
+ return Equals((AreaUnit)obj);
+ }
///
[ExcludeFromCodeCoverage]
@@ -173,7 +192,7 @@ private static IDictionary GetUnits()
/// When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
/// true if area units contain an unit with the specified ; otherwise, false.
/// is null.
- public static bool FromName(string name, out AreaUnit unit)
+ public static bool FromName(string name, [NotNullWhen(true)] out AreaUnit? unit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
diff --git a/xFunc.Maths/Expressions/Units/AreaUnits/AreaValue.cs b/xFunc.Maths/Expressions/Units/AreaUnits/AreaValue.cs
index 19aff6af0..39a861d07 100644
--- a/xFunc.Maths/Expressions/Units/AreaUnits/AreaValue.cs
+++ b/xFunc.Maths/Expressions/Units/AreaUnits/AreaValue.cs
@@ -204,7 +204,7 @@ public int CompareTo(AreaValue other)
}
///
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
=> obj switch
{
null => 1,
diff --git a/xFunc.Maths/Expressions/Units/LengthUnits/LengthValue.cs b/xFunc.Maths/Expressions/Units/LengthUnits/LengthValue.cs
index 5ea6c2180..fd1304451 100644
--- a/xFunc.Maths/Expressions/Units/LengthUnits/LengthValue.cs
+++ b/xFunc.Maths/Expressions/Units/LengthUnits/LengthValue.cs
@@ -316,7 +316,7 @@ public int CompareTo(LengthValue other)
}
///
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
=> obj switch
{
null => 1,
diff --git a/xFunc.Maths/Expressions/Units/MassUnits/MassValue.cs b/xFunc.Maths/Expressions/Units/MassUnits/MassValue.cs
index 947e35b12..1942e8b28 100644
--- a/xFunc.Maths/Expressions/Units/MassUnits/MassValue.cs
+++ b/xFunc.Maths/Expressions/Units/MassUnits/MassValue.cs
@@ -140,7 +140,7 @@ public int CompareTo(MassValue other)
}
///
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
=> obj switch
{
null => 1,
diff --git a/xFunc.Maths/Expressions/Units/PowerUnits/PowerValue.cs b/xFunc.Maths/Expressions/Units/PowerUnits/PowerValue.cs
index 7f6e9d8c6..4e7987eea 100644
--- a/xFunc.Maths/Expressions/Units/PowerUnits/PowerValue.cs
+++ b/xFunc.Maths/Expressions/Units/PowerUnits/PowerValue.cs
@@ -92,7 +92,7 @@ public int CompareTo(PowerValue other)
}
///
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
=> obj switch
{
null => 1,
diff --git a/xFunc.Maths/Expressions/Units/TimeUnits/TimeValue.cs b/xFunc.Maths/Expressions/Units/TimeUnits/TimeValue.cs
index 44dd4b1ba..b9eb65e72 100644
--- a/xFunc.Maths/Expressions/Units/TimeUnits/TimeValue.cs
+++ b/xFunc.Maths/Expressions/Units/TimeUnits/TimeValue.cs
@@ -188,7 +188,7 @@ public int CompareTo(TimeValue other)
}
///
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
=> obj switch
{
null => 1,
diff --git a/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeUnit.cs b/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeUnit.cs
index 27b0aed1f..0052a9306 100644
--- a/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeUnit.cs
+++ b/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeUnit.cs
@@ -70,12 +70,31 @@ private VolumeUnit(double factor, string unitName)
=> !left.Equals(right);
///
- public bool Equals(VolumeUnit other)
- => Factor.Equals(other.Factor) && UnitName == other.UnitName;
+ public bool Equals(VolumeUnit? other)
+ {
+ if (ReferenceEquals(null, other))
+ return false;
+
+ if (ReferenceEquals(this, other))
+ return true;
+
+ return Factor.Equals(other.Factor) && UnitName == other.UnitName;
+ }
///
public override bool Equals(object? obj)
- => obj is VolumeUnit other && Equals(other);
+ {
+ if (ReferenceEquals(null, obj))
+ return false;
+
+ if (ReferenceEquals(this, obj))
+ return true;
+
+ if (obj.GetType() != GetType())
+ return false;
+
+ return Equals((VolumeUnit)obj);
+ }
///
[ExcludeFromCodeCoverage]
@@ -129,7 +148,7 @@ private static IDictionary GetUnits()
/// When this method returns, the value associated with the specified name, if the unit is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.
/// true if volume units contain an unit with the specified ; otherwise, false.
/// is null.
- public static bool FromName(string name, out VolumeUnit unit)
+ public static bool FromName(string name, [NotNullWhen(true)] out VolumeUnit? unit)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException(nameof(name));
diff --git a/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeValue.cs b/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeValue.cs
index 0e752b2f0..a4dc825d2 100644
--- a/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeValue.cs
+++ b/xFunc.Maths/Expressions/Units/VolumeUnits/VolumeValue.cs
@@ -156,7 +156,7 @@ public int CompareTo(VolumeValue other)
}
///
- public int CompareTo(object obj)
+ public int CompareTo(object? obj)
=> obj switch
{
null => 1,
diff --git a/xFunc.Maths/Parser.ExpressionFactory.cs b/xFunc.Maths/Parser.ExpressionFactory.cs
index a1a4b3f41..66dd25056 100644
--- a/xFunc.Maths/Parser.ExpressionFactory.cs
+++ b/xFunc.Maths/Parser.ExpressionFactory.cs
@@ -15,7 +15,7 @@ public partial class Parser
{
private IExpression CreateFunction(in Token token, ImmutableArray arguments)
{
- Debug.Assert(token.IsId(), "Token should be Id.");
+ Debug.Assert(token.Is(Id), "Token should be Id.");
Debug.Assert(!string.IsNullOrWhiteSpace(token.StringValue), "Id is empty.");
return token.StringValue.ToLowerInvariant() switch
diff --git a/xFunc.Maths/Results/ExpressionResult.cs b/xFunc.Maths/Results/ExpressionResult.cs
index 7e2c249fb..8c7f44ebb 100644
--- a/xFunc.Maths/Results/ExpressionResult.cs
+++ b/xFunc.Maths/Results/ExpressionResult.cs
@@ -16,7 +16,7 @@ public ExpressionResult(IExpression exp)
=> Result = exp ?? throw new ArgumentNullException(nameof(exp));
///
- public override string ToString() => Result.ToString();
+ public override string ToString() => Result.ToString()!;
///
public IExpression Result { get; }
diff --git a/xFunc.Maths/Tokenization/Token.cs b/xFunc.Maths/Tokenization/Token.cs
index d074b2070..2766be38a 100644
--- a/xFunc.Maths/Tokenization/Token.cs
+++ b/xFunc.Maths/Tokenization/Token.cs
@@ -77,10 +77,10 @@ public static Token Create(TokenKind kind)
[ExcludeFromCodeCoverage]
public override string ToString()
{
- if (IsId() || Is(TokenKind.String))
+ if (Is(TokenKind.Id) || Is(TokenKind.String))
return $"String: {StringValue}";
- if (IsNumber())
+ if (Is(TokenKind.Number))
return $"Number: {NumberValue}";
return $"Kind: {Kind}";
@@ -161,24 +161,6 @@ public override string ToString()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool IsNotEmpty() => !Is(TokenKind.Empty);
- ///
- /// Determines whether the current token is Id token.
- ///
- ///
- /// true if the current token is Id token; otherwise, false.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool IsId() => Is(TokenKind.Id);
-
- ///
- /// Determines whether the current token is Number token.
- ///
- ///
- /// true if the current token is Number token; otherwise, false.
- ///
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public bool IsNumber() => Is(TokenKind.Number);
-
///
/// Gets a token kind.
///
diff --git a/xFunc.Maths/xFunc.Maths.csproj b/xFunc.Maths/xFunc.Maths.csproj
index 4f58d3970..e9e074846 100644
--- a/xFunc.Maths/xFunc.Maths.csproj
+++ b/xFunc.Maths/xFunc.Maths.csproj
@@ -1,11 +1,11 @@
- netstandard2.1
+ net6.0
latest
xFunc.Maths
xFunc.Maths
- 4.1.0
+ 4.2.0
xFunc.Maths
Dmytro Kyshchenko
@@ -15,8 +15,8 @@
xFunc.png
Math Expression Expressions Parser MathParser Differentiation Simplification
en
- 4.1.0
- 4.1.0
+ 4.2.0
+ 4.2.0
https://github.com/sys27/xFunc
GitHub
https://github.com/sys27/xFunc/wiki/ChangeLog
diff --git a/xFunc.Tests/Expressions/Matrices/CrossProductTests.cs b/xFunc.Tests/Expressions/Matrices/CrossProductTests.cs
index f3aef5d67..afd81b9ad 100644
--- a/xFunc.Tests/Expressions/Matrices/CrossProductTests.cs
+++ b/xFunc.Tests/Expressions/Matrices/CrossProductTests.cs
@@ -18,6 +18,28 @@ public void ExecuteTest()
Assert.Equal(expected, result);
}
+ [Fact]
+ public void ExecuteLeftLessThenThreeTest()
+ {
+ var exp = new CrossProduct(
+ new Vector(new[] { Number.One, Number.Two, }),
+ new Vector(new[] { new Number(4), new Number(5), new Number(6) })
+ );
+
+ Assert.Throws(() => exp.Execute());
+ }
+
+ [Fact]
+ public void ExecuteRightLessThenThreeTest()
+ {
+ var exp = new CrossProduct(
+ new Vector(new[] { Number.One, Number.Two, new Number(3) }),
+ new Vector(new[] { new Number(4), new Number(5), })
+ );
+
+ Assert.Throws(() => exp.Execute());
+ }
+
[Fact]
public void ExecuteTypeExceptionTest()
=> TestNotSupported(new CrossProduct(Number.One, Number.Two));
diff --git a/xFunc.Tests/Expressions/MulTest.cs b/xFunc.Tests/Expressions/MulTest.cs
index 0c0eb468e..d5bcb1a40 100644
--- a/xFunc.Tests/Expressions/MulTest.cs
+++ b/xFunc.Tests/Expressions/MulTest.cs
@@ -71,6 +71,22 @@ public void ExecuteDotProductTest()
Assert.Equal(expected, exp.Execute());
}
+ [Fact]
+ public void ExecuteDotProductErrorTest()
+ {
+ var vector1 = new Vector(new IExpression[]
+ {
+ Number.One, Number.Two,
+ });
+ var vector2 = new Vector(new IExpression[]
+ {
+ new Number(4), new Number(5), new Number(6)
+ });
+ var exp = new Mul(vector1, vector2);
+
+ Assert.Throws(() => exp.Execute());
+ }
+
[Fact]
public void ExecuteMulComplexByBool()
{
diff --git a/xFunc.Tests/Expressions/Units/AngleUnits/AngleUnitTest.cs b/xFunc.Tests/Expressions/Units/AngleUnits/AngleUnitTest.cs
index b074bf4b4..266aa07e9 100644
--- a/xFunc.Tests/Expressions/Units/AngleUnits/AngleUnitTest.cs
+++ b/xFunc.Tests/Expressions/Units/AngleUnits/AngleUnitTest.cs
@@ -2,6 +2,14 @@ namespace xFunc.Tests.Expressions.Units.AngleUnits;
public class AngleUnitTest
{
+ [Fact]
+ public void EqualsNullTest()
+ {
+ var a = AngleUnit.Degree;
+
+ Assert.False(a.Equals(null));
+ }
+
[Fact]
public void EqualsTest()
{
@@ -20,6 +28,14 @@ public void NotEqualsTest()
Assert.False(a.Equals(b));
}
+ [Fact]
+ public void ObjectEqualsNullTest()
+ {
+ var a = AngleUnit.Degree;
+
+ Assert.False(a.Equals(null as object));
+ }
+
[Fact]
public void ObjectEqualsTest()
{
diff --git a/xFunc.Tests/Expressions/Units/AreaUnits/AreaUnitTest.cs b/xFunc.Tests/Expressions/Units/AreaUnits/AreaUnitTest.cs
index 1886e1942..8ea30272e 100644
--- a/xFunc.Tests/Expressions/Units/AreaUnits/AreaUnitTest.cs
+++ b/xFunc.Tests/Expressions/Units/AreaUnits/AreaUnitTest.cs
@@ -5,6 +5,14 @@ namespace xFunc.Tests.Expressions.Units.AreaUnits;
public class AreaUnitTest
{
+ [Fact]
+ public void EqualsNullTest()
+ {
+ var a = AreaUnit.Meter;
+
+ Assert.False(a.Equals(null));
+ }
+
[Fact]
public void EqualsTest()
{
@@ -23,6 +31,14 @@ public void NotEqualsTest()
Assert.False(a.Equals(b));
}
+ [Fact]
+ public void ObjectEqualsNullTest()
+ {
+ var a = AreaUnit.Meter;
+
+ Assert.False(a.Equals(null as object));
+ }
+
[Fact]
public void ObjectEqualsTest()
{
diff --git a/xFunc.Tests/Expressions/Units/VolumeUnits/VolumeUnitTest.cs b/xFunc.Tests/Expressions/Units/VolumeUnits/VolumeUnitTest.cs
index 5fc2f68a2..5bb4da71b 100644
--- a/xFunc.Tests/Expressions/Units/VolumeUnits/VolumeUnitTest.cs
+++ b/xFunc.Tests/Expressions/Units/VolumeUnits/VolumeUnitTest.cs
@@ -5,6 +5,14 @@ namespace xFunc.Tests.Expressions.Units.VolumeUnits;
public class VolumeUnitTest
{
+ [Fact]
+ public void EqualsNullTest()
+ {
+ var a = VolumeUnit.Meter;
+
+ Assert.False(a.Equals(null));
+ }
+
[Fact]
public void EqualsTest()
{
@@ -23,6 +31,14 @@ public void NotEqualsTest()
Assert.False(a.Equals(b));
}
+ [Fact]
+ public void ObjectEqualsNullTest()
+ {
+ var a = VolumeUnit.Meter;
+
+ Assert.False(a.Equals(null as object));
+ }
+
[Fact]
public void ObjectEqualsTest()
{
diff --git a/xFunc.sln b/xFunc.sln
index c5e13b984..a433c001a 100644
--- a/xFunc.sln
+++ b/xFunc.sln
@@ -19,6 +19,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.stylecop.json = .stylecop.json
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
+ version.json = version.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CI", "CI", "{7D6A31E3-42CF-49E7-A0D2-657A460388BC}"