-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Add]
IEquatable
to WitnessRule (#3573)
* Add `IEquatable` to WitnessRule * Added `null` check to `Equals(other)` * Added `AggressiveInlining` and compacked `Equals` * Fixed `==` and `!-` * Update src/Neo/Network/P2P/Payloads/WitnessRule.cs --------- Co-authored-by: Shargon <[email protected]>
- Loading branch information
1 parent
cf2b559
commit e6fa071
Showing
2 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/Neo.UnitTests/Network/P2P/Payloads/UT_WitnessRule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// UT_WitnessRule.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.P2P.Payloads.Conditions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Neo.UnitTests.Network.P2P.Payloads | ||
{ | ||
[TestClass] | ||
public class UT_WitnessRule | ||
{ | ||
[TestMethod] | ||
public void Test_IEquatable() | ||
{ | ||
var expected = new WitnessRule | ||
{ | ||
Action = WitnessRuleAction.Allow, | ||
Condition = new BooleanCondition | ||
{ | ||
Expression = true, | ||
} | ||
}; | ||
|
||
var actual = new WitnessRule | ||
{ | ||
Action = WitnessRuleAction.Allow, | ||
Condition = new BooleanCondition | ||
{ | ||
Expression = true, | ||
} | ||
}; | ||
|
||
var notEqual = new WitnessRule | ||
{ | ||
Action = WitnessRuleAction.Deny, | ||
Condition = new BooleanCondition | ||
{ | ||
Expression = false, | ||
} | ||
}; | ||
|
||
Assert.IsTrue(expected.Equals(expected)); | ||
|
||
Assert.AreEqual(expected, actual); | ||
Assert.IsTrue(expected == actual); | ||
Assert.IsTrue(expected.Equals(actual)); | ||
|
||
Assert.AreNotEqual(expected, notEqual); | ||
Assert.IsTrue(expected != notEqual); | ||
Assert.IsFalse(expected.Equals(notEqual)); | ||
|
||
Assert.IsFalse(expected == null); | ||
Assert.IsFalse(null == expected); | ||
Assert.AreNotEqual(expected, null); | ||
Assert.IsFalse(expected.Equals(null)); | ||
} | ||
} | ||
} |