<commit_before>//
//  Observable+EnumeratedTests.swift
//  Tests
//
//  Created by <NAME> on 8/6/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
import RxSwift
import RxTest

class ObservableEnumeratedTest : RxTest {
}

extension ObservableEnumeratedTest {

    func test_Infinite() {
        let scheduler = TestScheduler(initialClock: 0)

        let xs = scheduler.createHotObservable([
            next(210, "a"),
            next(220, "b"),
            next(280, "c")
            ])

        let res = scheduler.start {
            xs.enumerated()
        }

        XCTAssertArraysEqual(res.events, [
            next(210, (index: 0, element: "a")),
            next(220, (index: 1, element: "b")),
            next(280, (index: 2, element: "c"))
        ] as [Recorded<Event<(index: Int, element: String)>>], compareRecordedEvents)

        XCTAssertEqual(xs.subscriptions, [
            Subscription(200, 1000)
            ])
    }

    func test_Completed() {
        let scheduler = TestScheduler(initialClock: 0)

        let xs = scheduler.createHotObservable([
            next(210, "a"),
            next(220, "b"),
            next(280, "c"),
            completed(300)
            ])

        let res = scheduler.start {
            xs.enumerated()
        }

        XCTAssertArraysEqual(res.events, [
            next(210, (0, "a")),
            next(220, (1, "b")),
            next(280, (2, "c")),
            completed(300)
        ] as [Recorded<Event<(index: Int, element: String)>>], compareRecordedEvents)

        XCTAssertEqual(xs.subscriptions, [
            Subscription(200, 300)
            ])
    }

    func test_Error() {
        let scheduler = TestScheduler(initialClock: 0)

        let xs = scheduler.createHotObservable([
            next(210, "a"),
            next(220, "b"),
            next(280, "c"),
            error(300, testError)
            ])

        let res = scheduler.start {
            xs.enumerated()
        }

        XCTAssertArraysEqual(res.events, [
            next(210, (0, "a")),
            next(220, (1, "b")),
            next(280, (2, "c")),
            error(300, testError)
            ] as [Recorded<Event<(index: Int, element: String)>>], compareRecordedEvents)

        XCTAssertEqual(xs.subscriptions, [
            Subscription(200, 300)
            ])
    }

    #if TRACE_RESOURCES
        func testEnumeratedReleasesResourcesOnComplete() {
        _ = Observable<Int>.just(1).enumerated().subscribe()<commit_msg>Xcode 8.2 fixes.<commit_after>//
//  Observable+EnumeratedTests.swift
//  Tests
//
//  Created by <NAME> on 8/6/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
import RxSwift
import RxTest

class ObservableEnumeratedTest : RxTest {
}

extension ObservableEnumeratedTest {

    func test_Infinite() {
        let scheduler = TestScheduler(initialClock: 0)

        let xs = scheduler.createHotObservable([
            next(210, "a"),
            next(220, "b"),
            next(280, "c")
            ])

        let res = scheduler.start {
            xs.enumerated()
        }

        XCTAssertArraysEqual(res.events, [
            next(210, (index: 0, element: "a")),
            next(220, (index: 1, element: "b")),
            next(280, (index: 2, element: "c"))
        ] as [Recorded<Event<(index: Int, element: String)>>], compareRecordedEvents)

        XCTAssertEqual(xs.subscriptions, [
            Subscription(200, 1000)
            ])
    }

    func test_Completed() {
        let scheduler = TestScheduler(initialClock: 0)

        let xs = scheduler.createHotObservable([
            next(210, "a"),
            next(220, "b"),
            next(280, "c"),
            completed(300)
            ])

        let res = scheduler.start {
            xs.enumerated()
        }

        XCTAssertArraysEqual(res.events, [
            next(210, (index: 0, element: "a")),
            next(220, (index: 1, element: "b")),
            next(280, (index: 2, element: "c")),
            completed(300)
        ] as [Recorded<Event<(index: Int, element: String)>>], compareRecordedEvents)

        XCTAssertEqual(xs.subscriptions, [
            Subscription(200, 300)
            ])
    }

    func test_Error() {
        let scheduler = TestScheduler(initialClock: 0)

        let xs = scheduler.createHotObservable([
            next(210, "a"),
            next(220, "b"),
            next(280, "c"),
            error(300, testError)
            ])

        let res = scheduler.start {
            xs.enumerated()
        }

        XCTAssertArraysEqual(res.events, [
            next(210, (index: 0, element: "a")),
            next(220, (index: 1, element: "b")),
            next(280, (index: 2, element: "c")),
            error(300, testError)
            ] as [Recorded<Event<(index: Int, element: String)>>], compareRecordedEvents)

        XCTAssertEqual(xs.subscriptions, [
            Subscription(200, 300)
            ])
    }

    #if TRACE_RESOURCES
        func testEnumeratedReleasesResourcesOnComplete() {
        _ = Observable<Int>.just(1).enumerated().subscribe()
{'fraction_non_alphanumeric': 0.13603586045605146, 'fraction_numerical': 0.041707269538101735, 'mean_word_length': 1.855870895937674, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3429075', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1547, 'n_words': 327}