File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // GenTests+Frequency.swift
3
+ // PropertyBased
4
+ //
5
+ // Created by Lennard Sprong on 08/07/2025.
6
+ //
7
+
8
+ #if compiler(>=6.2)
9
+ import Testing
10
+ @testable import PropertyBased
11
+
12
+ @Suite struct GenFrequencyTests {
13
+ enum Choice : Hashable {
14
+ case first
15
+ case second( Int )
16
+ case third( String )
17
+ }
18
+
19
+ let gen = Gen . oneOf (
20
+ Gen . always ( Choice . first) ,
21
+ Gen . int ( ) . map ( Choice . second) ,
22
+ Gen . lowercaseLetter. string ( of: 8 ) . map ( Choice . third) ,
23
+ )
24
+
25
+ @Test func testGenerateEnum( ) async {
26
+ await testGen ( gen)
27
+
28
+ await confirmation ( expectedCount: 1 ... ) { confirm1 in
29
+ await confirmation ( expectedCount: 1 ... ) { confirm2 in
30
+ await confirmation ( expectedCount: 1 ... ) { confirm3 in
31
+ await propertyCheck ( count: 200 , input: gen) { item in
32
+ switch item {
33
+ case . first:
34
+ confirm1 ( )
35
+ case . second:
36
+ confirm2 ( )
37
+ case . third:
38
+ confirm3 ( )
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+
46
+ @Test func testShrinkChoice( ) async throws {
47
+ let value = ( index: 1 , value: 500 )
48
+ let results = Array ( gen. _shrinker ( value) )
49
+ try #require( results. count > 1 )
50
+ #expect( results. first? . value as? Int == 0 )
51
+ #expect( !results. contains { $0. value as? Int == 500 } )
52
+ }
53
+ }
54
+ #endif // compiler(>=6.2)
You can’t perform that action at this time.
0 commit comments