Skip to content

Commit

Permalink
Fix Infallible CombineLatest arity helpers (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
hallee committed May 12, 2023
1 parent 565cc5f commit 9dcaa4b
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 7 deletions.
14 changes: 7 additions & 7 deletions RxSwift/Traits/Infallible/Infallible+CombineLatest+arity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down Expand Up @@ -67,7 +67,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down Expand Up @@ -105,7 +105,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down Expand Up @@ -143,7 +143,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down Expand Up @@ -181,7 +181,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down Expand Up @@ -219,7 +219,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down Expand Up @@ -257,7 +257,7 @@ extension Infallible {
}
}

extension InfallibleType {
extension InfallibleType where Element == Any {
/**
Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element.
Expand Down
1 change: 1 addition & 0 deletions Sources/AllTestz/Infallible+CombineLatestTests+arity.swift
19 changes: 19 additions & 0 deletions Sources/AllTestz/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ final class HistoricalSchedulerTest_ : HistoricalSchedulerTest, RxTestCase {
] }
}

final class InfallibleCombineLatestTest_ : InfallibleCombineLatestTest, RxTestCase {
#if os(macOS)
required override init() {
super.init()
}
#endif

static var allTests: [(String, (InfallibleCombineLatestTest_) -> () -> Void)] { return [
("testCombineLatest_Arity", InfallibleCombineLatestTest.testCombineLatest_Arity),
("testCombineLatest_3_Arity", InfallibleCombineLatestTest.testCombineLatest_3_Arity),
("testCombineLatest_4_Arity", InfallibleCombineLatestTest.testCombineLatest_4_Arity),
("testCombineLatest_5_Arity", InfallibleCombineLatestTest.testCombineLatest_5_Arity),
("testCombineLatest_6_Arity", InfallibleCombineLatestTest.testCombineLatest_6_Arity),
("testCombineLatest_7_Arity", InfallibleCombineLatestTest.testCombineLatest_7_Arity),
("testCombineLatest_8_Arity", InfallibleCombineLatestTest.testCombineLatest_8_Arity),
] }
}

final class InfallibleTest_ : InfallibleTest, RxTestCase {
#if os(macOS)
required override init() {
Expand Down Expand Up @@ -2217,6 +2235,7 @@ func XCTMain(_ tests: [() -> Void]) {
testCase(DriverTest_.allTests),
testCase(EventTests_.allTests),
testCase(HistoricalSchedulerTest_.allTests),
testCase(InfallibleCombineLatestTest_.allTests),
testCase(InfallibleTest_.allTests),
testCase(MainSchedulerTest_.allTests),
testCase(MaybeTest_.allTests),
Expand Down
246 changes: 246 additions & 0 deletions Tests/RxSwiftTests/Infallible+CombineLatestTests+arity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
//
// Infallible+CombineLatestTests+arity.swift
// Tests
//
// Created by Hal Lee on 5/11/23.
// Copyright © 2023 Krunoslav Zaher. All rights reserved.
//

import XCTest
import RxSwift
import RxTest

class InfallibleCombineLatestTest: RxTest {

func testCombineLatest_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream)
.map { $0 + $1 }
}

XCTAssertEqual(observer.events, [
.next(1, 2),
])
}

func testCombineLatest_3_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let thirdStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream, thirdStream)
.map { $0 + $1 + $2 }
}

XCTAssertEqual(observer.events, [
.next(1, 3),
])
}

func testCombineLatest_4_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let thirdStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fourthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream, thirdStream, fourthStream)
.map { (a: Int, b: Int, c: Int, d: Int) -> Int in a + b + c + d }
}

XCTAssertEqual(observer.events, [
.next(1, 4),
])
}

func testCombineLatest_5_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let thirdStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fourthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fifthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream)
.map { (a: Int, b: Int, c: Int, d: Int, e: Int) -> Int in a + b + c + d + e }
}

XCTAssertEqual(observer.events, [
.next(1, 5),
])
}

func testCombineLatest_6_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let thirdStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fourthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fifthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let sixthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream, sixthStream)
.map { (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) -> Int in a + b + c + d + e + f }
}

XCTAssertEqual(observer.events, [
.next(1, 6),
])
}

func testCombineLatest_7_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let thirdStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fourthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fifthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let sixthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let seventhStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream, sixthStream, seventhStream)
.map { (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int) -> Int in a + b + c + d + e + f + g }
}

XCTAssertEqual(observer.events, [
.next(1, 7),
])
}

func testCombineLatest_8_Arity() {
let scheduler = TestScheduler(initialClock: 0)
let firstStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let secondStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let thirdStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fourthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let fifthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let sixthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let seventhStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let eighthStream = scheduler.createColdObservable([
.next(1, 1)
]).asInfallible(onErrorFallbackTo: .never())

let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) {
return Infallible
.combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream, sixthStream, seventhStream, eighthStream)
.map { (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int) -> Int in a + b + c + d + e + f + g + h }
}

XCTAssertEqual(observer.events, [
.next(1, 8),
])
}

}

0 comments on commit 9dcaa4b

Please sign in to comment.