<commit_before>//
//  ListenableTests.swift
//  ListenableTests
//
//  Created by <NAME> on 10/01/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
@testable import Listenable

class ListenableTests: XCTestCase {
    
    // Mark: Constants
    
    let maxListenerCount: UInt32 = 25
    
    // MARK: Properties
    
    var listenableObject: TestListenableObject!
    var currentTestListeners: [TestListener]?
    
    // MARK: Lifecycle
    
    override func setUp() {
        super.setUp()
        
        self.listenableObject = TestListenableObject()
    }
    
    // MARK: Tests
    
    func testAddListener() {
        let initialListenerCount = self.listenableObject.listenerCount
        self.addTestListeners(count: 1, toListenableObject: self.listenableObject)
        
        XCTAssert(self.listenableObject.listenerCount == initialListenerCount + 1,
                  "Listener was not added successfully")
    }
    
    func testAddMultipleListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
        self.addTestListeners(count: proposedListenerCount,
                              toListenableObject: self.listenableObject)
        
        XCTAssert(self.listenableObject.listenerCount == proposedListenerCount,
                  "Multiple listeners were not added successfully")
    }
    
    func testRemoveListener() {
        let listeners = self.addTestListeners(count: 1,
                                              toListenableObject: self.listenableObject)
        let addedCount = self.listenableObject.listenerCount
        
        if let listener = listeners.first {
            self.listenableObject.remove(listener: listener)
        }
        
        XCTAssert((self.listenableObject.listenerCount == addedCount - 1) && addedCount != 0,
                  "Listener was not removed successfully")
    }
    
    func testRemoveListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
        let listeners = self.addTestListeners(count: proposedListenerCount,
                                              toListenableObject: self.listenableObject)
        let addedCount = self.listenableObject.listenerCount
        
        self.listenableObject.remove(listeners: listeners)
        
        XCTAssert((self.listenableObject.listenerCount == (proposedListenerCount - listeners.count)) && addedCount != 0,
                  "Multiple listeners were not removed successfully")
    }
    
    func testRemoveAllListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
        self.addTestListeners(count: proposedListenerCount,
                              toListenableObject: self.listenableObject)
        let addedCount = self.listenableObject.listenerCount

        self.listenableObject.removeAllListeners()
        
        XCTAssert((addedCount != 0) && self.listenableObject.listenerCount == 0,
                  "All listeners were not removed successfully")
    }
    
    func testEnumerateAllListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)<commit_msg>Add additional tests<commit_after>//
//  ListenableTests.swift
//  ListenableTests
//
//  Created by <NAME> on 10/01/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import XCTest
@testable import Listenable

class ListenableTests: XCTestCase {
    
    // Mark: Constants
    
    let maxListenerCount: UInt32 = 25
    
    // MARK: Properties
    
    var listenableObject: TestListenableObject!
    var currentTestListeners: [TestListener]?
    
    // MARK: Lifecycle
    
    override func setUp() {
        super.setUp()
        
        self.listenableObject = TestListenableObject()
    }
    
    // MARK: Tests
    
    func testAddListener() {
        let initialListenerCount = self.listenableObject.listenerCount
        self.addTestListeners(count: 1, toListenableObject: self.listenableObject)
        
        XCTAssert(self.listenableObject.listenerCount == initialListenerCount + 1,
                  "Listener was not added successfully")
    }
    
    func testAddMultipleListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
        self.addTestListeners(count: proposedListenerCount,
                              toListenableObject: self.listenableObject)
        
        XCTAssert(self.listenableObject.listenerCount == proposedListenerCount,
                  "Multiple listeners were not added successfully")
    }
    
    func testAddExistingListenerFail() {
        let listener = self.addTestListeners(count: 1, toListenableObject: self.listenableObject).first!
        let successfulAdd = self.listenableObject.add(listener: listener)
        
        XCTAssert(successfulAdd == false, "Duplicate listener was able to be added")
    }
    
    func testRemoveListener() {
        let listeners = self.addTestListeners(count: 1,
                                              toListenableObject: self.listenableObject)
        let addedCount = self.listenableObject.listenerCount
        
        if let listener = listeners.first {
            self.listenableObject.remove(listener: listener)
        }
        
        XCTAssert((self.listenableObject.listenerCount == addedCount - 1) && addedCount != 0,
                  "Listener was not removed successfully")
    }
    
    func testRemoveListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
        let listeners = self.addTestListeners(count: proposedListenerCount,
                                              toListenableObject: self.listenableObject)
        let addedCount = self.listenableObject.listenerCount
        
        self.listenableObject.remove(listeners: listeners)
        
        XCTAssert((self.listenableObject.listenerCount == (proposedListenerCount - listeners.count)) && addedCount != 0,
                  "Multiple listeners were not removed successfully")
    }
    
    func testRemoveNonExistentListenerFail() {
        let listener = self.addTestListeners(count: 1,
                                              toListenableObject: self.listenableObject).first!
        self.listenableObject.remove(listener: listener)
        
        // attempt to remove again
        let removeResult = self.listenableObject.remove(listener: listener)
        
        XCTAssert(removeResult == false, "Non existent listener was attempted to be removed")
    }
    
    func testRemoveAllListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
        self.addTestListeners(count: proposedListenerCount,
                              toListenableObject: self.listenableObject)
        let addedCount = self.listenableObject.listenerCount

        self.listenableObject.removeAllListeners()
        
        XCTAssert((addedCount != 0) && self.listenableObject.listenerCount == 0,
                  "All listeners were not removed successfully")
    }
    
    func testEnumerateAllListeners() {
        let proposedListenerCount = Int(arc4random_uniform(maxListenerCount) + 1)
{'fraction_non_alphanumeric': 0.07632636099182712, 'fraction_numerical': 0.009142540518077296, 'mean_word_length': 2.3395004625346902, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4032290', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1790, 'n_words': 384}