-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Generator.Equals can't handle IEnumerable<T> when it should (#54)
- Loading branch information
1 parent
a7fa97d
commit a63fe59
Showing
5 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Generator.Equals.SnapshotTests/Classes/EnumerableEquality.Net60.Diagnostics.verified.txt
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 @@ | ||
[] |
1 change: 1 addition & 0 deletions
1
...r.Equals.SnapshotTests/Classes/EnumerableEquality.NetFramework48.Diagnostics.verified.txt
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 @@ | ||
[] |
13 changes: 13 additions & 0 deletions
13
Generator.Equals.Tests/Classes/EnumerableEquality.Sample.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,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Generator.Equals.Tests.Classes | ||
{ | ||
public partial class EnumerableEquality | ||
{ | ||
[Equatable] | ||
public partial class Sample | ||
{ | ||
[UnorderedEquality] public IEnumerable<int>? Properties { get; set; } | ||
} | ||
} | ||
} |
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,47 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Generator.Equals.Tests.Classes | ||
{ | ||
public partial class EnumerableEquality | ||
{ | ||
public class EqualsTests : EqualityTestCase | ||
{ | ||
public override object Factory1() | ||
{ | ||
var randomSort = new Random(); | ||
|
||
// This should generate objects with the same contents, but different orders, thus proving | ||
// that dictionary equality is being used instead of the normal sequence equality. | ||
return new Sample | ||
{ | ||
Properties = Enumerable | ||
.Range(1, 1000) | ||
.OrderBy(_ => randomSort.NextDouble()) | ||
.ToList() | ||
}; | ||
} | ||
|
||
public override bool EqualsOperator(object value1, object value2) => (Sample) value1 == (Sample) value2; | ||
public override bool NotEqualsOperator(object value1, object value2) => (Sample) value1 != (Sample) value2; | ||
} | ||
|
||
public class NotEqualsTest : EqualityTestCase | ||
{ | ||
public override bool Expected => false; | ||
|
||
public override object Factory1() => new Sample | ||
{ | ||
Properties = Enumerable.Range(1, 1000).ToList() | ||
}; | ||
|
||
public override object Factory2() => new Sample | ||
{ | ||
Properties = Enumerable.Range(1, 1001).ToList() | ||
}; | ||
|
||
public override bool EqualsOperator(object value1, object value2) => (Sample) value1 == (Sample) value2; | ||
public override bool NotEqualsOperator(object value1, object value2) => (Sample) value1 != (Sample) value2; | ||
} | ||
} | ||
} |
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