Unified · Split
| @@ -103,10 +103,14 @@ func (g *sliceGen[E, K]) value(t *T) []E { · 102 unmodified lines | |||
| 103 | return sl | 103 | return sl |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | // MapOf creates a map[K]V generator. MapOf(key, val) is equivalent to MapOfN(key, val, -1, -1). | ||
| 106 | func MapOf[K comparable, V any](key *Generator[K], val *Generator[V]) *Generator[map[K]V] { | 107 | func MapOf[K comparable, V any](key *Generator[K], val *Generator[V]) *Generator[map[K]V] { |
| 107 | return MapOfN(key, val, -1, -1) | 108 | return MapOfN(key, val, -1, -1) |
| 108 | } | 109 | } |
| 109 | 110 | ||
| 111 | // MapOfN creates a map[K]V generator. If minLen >= 0, generated maps have minimum length of minLen. | ||
| 112 | // If maxLen >= 0, generated maps have maximum length of maxLen. MapOfN panics if maxLen >= 0 | ||
| 113 | // and minLen > maxLen. | ||
| 110 | func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen int, maxLen int) *Generator[map[K]V] { | 114 | func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen int, maxLen int) *Generator[map[K]V] { |
| 111 | assertValidRange(minLen, maxLen) | 115 | assertValidRange(minLen, maxLen) |
| 112 | 116 | ||
| @@ -118,10 +122,15 @@ func MapOfN[K comparable, V any](key *Generator[K], val *Generator[V], minLen in · 5 unmodified lines | |||
| 118 | }) | 122 | }) |
| 119 | } | 123 | } |
| 120 | 124 | ||
| 125 | // MapOfValues creates a map[K]V generator, where keys are generated by applying keyFn to values. | ||
| 126 | // MapOfValues(val, keyFn) is equivalent to MapOfNValues(val, -1, -1, keyFn). | ||
| 121 | func MapOfValues[K comparable, V any](val *Generator[V], keyFn func(V) K) *Generator[map[K]V] { | 127 | func MapOfValues[K comparable, V any](val *Generator[V], keyFn func(V) K) *Generator[map[K]V] { |
| 122 | return MapOfNValues(val, -1, -1, keyFn) | 128 | return MapOfNValues(val, -1, -1, keyFn) |
| 123 | } | 129 | } |
| 124 | 130 | ||
| 131 | // MapOfNValues creates a map[K]V generator, where keys are generated by applying keyFn to values. | ||
| 132 | // If minLen >= 0, generated maps have minimum length of minLen. If maxLen >= 0, generated maps | ||
| 133 | // have maximum length of maxLen. MapOfNValues panics if maxLen >= 0 and minLen > maxLen. | ||
| 125 | func MapOfNValues[K comparable, V any](val *Generator[V], minLen int, maxLen int, keyFn func(V) K) *Generator[map[K]V] { | 134 | func MapOfNValues[K comparable, V any](val *Generator[V], minLen int, maxLen int, keyFn func(V) K) *Generator[map[K]V] { |
| 126 | assertValidRange(minLen, maxLen) | 135 | assertValidRange(minLen, maxLen) |
| 127 | 136 | ||