@@ -135,4 +135,48 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
135135 XCTFail ( " Not expecting failure " )
136136 }
137137 }
138+
139+ func testCountWithPredicate( ) async throws {
140+ let result : Result < [ [ String : Int ] ] , CoreDataRepositoryError > = try await repository ( )
141+ . count ( predicate: NSComparisonPredicate (
142+ leftExpression: NSExpression ( forKeyPath: \RepoMovie . title) ,
143+ rightExpression: NSExpression ( forConstantValue: " A " ) ,
144+ modifier: . direct,
145+ type: . notEqualTo
146+ ) , entityDesc: RepoMovie . entity ( ) )
147+ switch result {
148+ case let . success( values) :
149+ let firstValue = try XCTUnwrap ( values. first? . values. first)
150+ XCTAssertEqual ( firstValue, 4 , " Result value (count) should equal number of movies not titled 'A'. " )
151+ case . failure:
152+ XCTFail ( " Not expecting failure " )
153+ }
154+ }
155+
156+ func testSumWithPredicate( ) async throws {
157+ let result : Result < [ [ String : Decimal ] ] , CoreDataRepositoryError > = try await repository ( ) . sum (
158+ predicate: NSComparisonPredicate (
159+ leftExpression: NSExpression ( forKeyPath: \RepoMovie . title) ,
160+ rightExpression: NSExpression ( forConstantValue: " A " ) ,
161+ modifier: . direct,
162+ type: . notEqualTo
163+ ) ,
164+ entityDesc: RepoMovie . entity ( ) ,
165+ attributeDesc: XCTUnwrap (
166+ RepoMovie . entity ( ) . attributesByName. values
167+ . first ( where: { $0. name == " boxOffice " } )
168+ )
169+ )
170+ switch result {
171+ case let . success( values) :
172+ let firstValue = try XCTUnwrap ( values. first? . values. first)
173+ XCTAssertEqual (
174+ firstValue,
175+ 140 ,
176+ " Result value should equal sum of movies box office that are not titled 'A'. "
177+ )
178+ case . failure:
179+ XCTFail ( " Not expecting failure " )
180+ }
181+ }
138182}
0 commit comments