Skip to content

Commit 51ecfea

Browse files
author
Elviro Rocca
committed
Add tests for Product
1 parent 478fd17 commit 51ecfea

File tree

9 files changed

+46
-6
lines changed

9 files changed

+46
-6
lines changed

Sources/Abstract/Types/Algebraic/Product.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#endif
44

55
// sourcery: fixedTypesForPropertyBasedTests = "TestStructure,TestStructure"
6+
// sourcery: ignore = "Semiring"
67
public struct Product<A,B> {
78
public let first: A
89
public let second: B

Templates/Tests/CommutativeMonoidTests.stencil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class {{ protocolName }}Tests: XCTestCase {
2020
}
2121
{% endfor %}
2222

23-
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
23+
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:"Semiring" and not type.kind == "protocol" %}
2424

2525
func test{{ type.name }}() {
2626
{% if type.isGeneric or type.name == "Array" or type.name == "Optional" or type.name == "Set" %}
@@ -40,7 +40,7 @@ final class {{ protocolName }}Tests: XCTestCase {
4040
{% for type in types.implementing.CommutativeMonoid where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
4141
("test{{ type.name }}",test{{ type.name }}),
4242
{% endfor %}
43-
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
43+
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:"Semiring" and not type.kind == "protocol" %}
4444
("test{{ type.name }}",test{{ type.name }}),
4545
{% endfor %}
4646
]

Templates/Tests/MonoidTests.stencil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class {{ protocolName }}Tests: XCTestCase {
2020
}
2121
{% endfor %}
2222

23-
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
23+
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:"Semiring" and not type.kind == "protocol" %}
2424

2525
func test{{ type.name }}() {
2626
{% if type.isGeneric or type.name == "Array" or type.name == "Optional" or type.name == "Set" %}
@@ -47,7 +47,7 @@ final class {{ protocolName }}Tests: XCTestCase {
4747
{% for type in types.implementing.Monoid where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
4848
("test{{ type.name }}",test{{ type.name }}),
4949
{% endfor %}
50-
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
50+
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:"Semiring" and not type.kind == "protocol" %}
5151
("test{{ type.name }}",test{{ type.name }}),
5252
{% endfor %}
5353
]

Templates/Tests/SemigroupTests.stencil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class {{ protocolName }}Tests: XCTestCase {
2020
}
2121
{% endfor %}
2222

23-
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
23+
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:"Semiring" and not type.kind == "protocol" %}
2424

2525
func test{{ type.name }}() {
2626
{% if type.isGeneric or type.name == "Array" or type.name == "Optional" or type.name == "Set" %}
@@ -47,7 +47,7 @@ final class {{ protocolName }}Tests: XCTestCase {
4747
{% for type in types.implementing.Semigroup where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
4848
("test{{ type.name }}",test{{ type.name }}),
4949
{% endfor %}
50-
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:protocolName and not type.kind == "protocol" %}
50+
{% for type in types.implementing.Semiring where not type.annotations.ignore|contains:"Semiring" and not type.kind == "protocol" %}
5151
("test{{ type.name }}",test{{ type.name }}),
5252
{% endfor %}
5353
]

Tests/AbstractTests/BoundedSemilatticeTests.generated.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ final class BoundedSemilatticeTests: XCTestCase {
3232
}
3333
}
3434

35+
func testProduct() {
36+
property("Product is a BoundedSemilattice") <- forAll { (a: Product<TestStructure,TestStructure>, b: Product<TestStructure,TestStructure>) in
37+
Law<Product<TestStructure,TestStructure>>.isIdempotent(a,b)
38+
}
39+
}
40+
3541
func testSet() {
3642
property("Set is a BoundedSemilattice") <- forAll { (a: Set<Int>, b: Set<Int>) in
3743
Law<Set<Int>>.isIdempotent(a,b)
@@ -43,6 +49,7 @@ final class BoundedSemilatticeTests: XCTestCase {
4349
("testMax",testMax),
4450
("testMin",testMin),
4551
("testOr",testOr),
52+
("testProduct",testProduct),
4653
("testSet",testSet),
4754
]
4855
}

Tests/AbstractTests/CommutativeMonoidTests.generated.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ final class CommutativeMonoidTests: XCTestCase {
5050
}
5151
}
5252

53+
func testProduct() {
54+
property("Product is a CommutativeMonoid") <- forAll { (a: Product<TestStructure,TestStructure>, b: Product<TestStructure,TestStructure>) in
55+
Law<Product<TestStructure,TestStructure>>.isCommutative(a,b)
56+
}
57+
}
58+
5359
func testSet() {
5460
property("Set is a CommutativeMonoid") <- forAll { (a: Set<Int>, b: Set<Int>) in
5561
Law<Set<Int>>.isCommutative(a,b)
@@ -84,6 +90,7 @@ final class CommutativeMonoidTests: XCTestCase {
8490
("testMultiply",testMultiply),
8591
("testMultiset",testMultiset),
8692
("testOr",testOr),
93+
("testProduct",testProduct),
8794
("testSet",testSet),
8895
("testBool",testBool),
8996
("testSetM",testSetM),

Tests/AbstractTests/MonoidTests.generated.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ final class MonoidTests: XCTestCase {
7474
}
7575
}
7676

77+
func testProduct() {
78+
property("Product is a Monoid") <- forAll { (a: Product<TestStructure,TestStructure>) in
79+
Law<Product<TestStructure,TestStructure>>.isNeutralToEmpty(a)
80+
}
81+
}
82+
7783
func testSet() {
7884
property("Set is a Monoid") <- forAll { (a: Set<Int>) in
7985
Law<Set<Int>>.isNeutralToEmpty(a)
@@ -135,6 +141,7 @@ final class MonoidTests: XCTestCase {
135141
("testOptional",testOptional),
136142
("testOr",testOr),
137143
("testOrdering",testOrdering),
144+
("testProduct",testProduct),
138145
("testSet",testSet),
139146
("testString",testString),
140147
("testUpdate",testUpdate),

Tests/AbstractTests/SemigroupTests.generated.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ final class SemigroupTests: XCTestCase {
9292
}
9393
}
9494

95+
func testProduct() {
96+
property("Product is a Semigroup") <- forAll { (a: Product<TestStructure,TestStructure>, b: Product<TestStructure,TestStructure>, c: Product<TestStructure,TestStructure>) in
97+
Law<Product<TestStructure,TestStructure>>.isAssociative(a,b,c)
98+
}
99+
}
100+
95101
func testSet() {
96102
property("Set is a Semigroup") <- forAll { (a: Set<Int>, b: Set<Int>, c: Set<Int>) in
97103
Law<Set<Int>>.isAssociative(a,b,c)
@@ -156,6 +162,7 @@ final class SemigroupTests: XCTestCase {
156162
("testOptional",testOptional),
157163
("testOr",testOr),
158164
("testOrdering",testOrdering),
165+
("testProduct",testProduct),
159166
("testSet",testSet),
160167
("testString",testString),
161168
("testUpdate",testUpdate),

Tests/AbstractTests/Utility/CustomArbitraryTypes.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,14 @@ extension SetM: Arbitrary where A: Arbitrary {
170170
}
171171
}
172172
}
173+
174+
extension Product: Arbitrary where A: Arbitrary, B: Arbitrary {
175+
public static var arbitrary: Gen<Product<A, B>> {
176+
return Gen<Product<A, B>>.compose {
177+
Product($0.generate(),$0.generate())
178+
}
179+
}
180+
}
181+
182+
183+

0 commit comments

Comments
 (0)