This repository was archived by the owner on Nov 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDefaultGeneratorsTests.cs
More file actions
105 lines (84 loc) · 3.63 KB
/
DefaultGeneratorsTests.cs
File metadata and controls
105 lines (84 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using static Hedgehog.Linq.Property;
using Xunit;
namespace Hedgehog.Linq.Tests;
public sealed class DefaultGeneratorsTests
{
private readonly AutoGenConfig _config = GenX.defaults.WithCollectionRange(Range.FromValue(5));
[Fact]
public void ShouldGenerateImmutableSet() =>
ForAll(GenX.autoWith<ImmutableHashSet<int>>(_config)).Select(x => x.Count > 0).Check();
[Fact]
public void ShouldGenerateIImmutableSet() =>
ForAll(GenX.autoWith<IImmutableSet<int>>(_config)).Select(x => x.Count > 0).Check();
[Fact]
public void ShouldGenerateImmutableSortedSet() =>
ForAll(GenX.autoWith<ImmutableSortedSet<int>>(_config)).Select(x => x.Count > 0).Check();
[Fact]
public void ShouldGenerateImmutableList() =>
ForAll(GenX.autoWith<ImmutableList<int>>(_config)).Select(x => x.Count == 5).Check();
[Fact]
public void ShouldGenerateIImmutableList() =>
ForAll(GenX.autoWith<IImmutableList<int>>(_config)).Select(x => x.Count == 5).Check();
[Fact]
public void ShouldGenerateImmutableArray() =>
ForAll(GenX.autoWith<ImmutableArray<int>>(_config)).Select(x => x.Length == 5).Check();
[Fact]
public void ShouldGenerateDictionary() =>
ForAll(GenX.autoWith<Dictionary<int, string>>(_config)).Select(x => x.Count > 0).Check();
[Fact]
public void ShouldGenerateIDictionary() =>
ForAll(GenX.autoWith<IDictionary<int, string>>(_config)).Select(x => x.Count > 0).Check();
[Fact]
public void ShouldGenerateIReadOnlyDictionary() =>
ForAll(GenX.autoWith<IReadOnlyDictionary<int, string>>(_config)).Select(x => x.Count > 0).Check();
[Fact]
public void ShouldGenerateList() =>
ForAll(GenX.autoWith<List<int>>(_config)).Select(x => x.Count == 5).Check();
[Fact]
public void ShouldGenerateIList() =>
ForAll(GenX.autoWith<IList<int>>(_config)).Select(x => x.Count == 5).Check();
[Fact]
public void ShouldGenerateIReadOnlyList() =>
ForAll(GenX.autoWith<IReadOnlyList<int>>(_config)).Select(x => x.Count == 5).Check();
[Fact]
public void ShouldGenerateIEnumerable() =>
ForAll(GenX.autoWith<IEnumerable<int>>(_config)).Select(x => x.Count() == 5).Check();
[Fact]
public void StressTest() =>
ForAll(GenX.autoWith<List<List<List<int>>>>(_config))
.Select(x => x.Count == 5 && x.All(inner => inner.Count == 5 && inner.All(innerMost => innerMost.Count == 5)))
.Check();
[Fact]
public void ShouldGenerateRecursiveTreeWithImmutableList()
{
// Tree node with ImmutableList of children - tests recursive generation with generic types
var config = GenX.defaults
.WithCollectionRange(Range.FromValue(2))
.WithRecursionDepth(1);
ForAll(GenX.autoWith<TreeNode<int>>(config))
.Select(tree =>
{
// At depth 1, should have children
// At depth 2, children's children should be empty (recursion limit)
return tree.Children.Count == 2 &&
tree.Children.All(child => child.Children.Count == 0);
})
.Check();
}
}
// Recursive data structure for testing
public record TreeNode<T>
{
public T Value { get; init; }
public List<TreeNode<T>> Children { get; init; } = [];
public override string ToString()
{
if (Children.Count == 0)
return $"Node({Value})";
var childrenStr = string.Join(", ", Children.Select(c => c.ToString()));
return $"Node({Value}, [{childrenStr}])";
}
}