<commit_before>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import XCTest
@testable import WatsonDeveloperCloud

class NaturalLanguageClassifierTests: XCTestCase {
    
    // MARK: - Parameters and constants
    
    // the NaturalLanguageClassifier service
    var service: NaturalLanguageClassifier!
    
    // a classifier that is already trained with the given weather data
    let trainedClassifierID = "A3FCCBx16-nlc-248"
    let trainedClassifierName = "iOS SDK Test Classifier"
    let availableStatus = NaturalLanguageClassifier.Status.Available
    
    // the classifier that will be created then deleted during tests
    var temporaryClassifierID: String!
    
    // timeout for asynchronous completion handlers
    let timeout: NSTimeInterval = 30.0
    
    // MARK: - Helper functions
    
    // Load credentials and instantiate NLC service
    override func setUp() {
        super.setUp()
        
        // identify credentials file
        let bundle = NSBundle(forClass: self.dynamicType)
        guard let url = bundle.pathForResource("Credentials", ofType: "plist") else {
            XCTFail("Unable to locate credentials file.")
            return
        }
        
        // load credentials from file
        let dict = NSDictionary(contentsOfFile: url)
        guard let credentials = dict as? Dictionary<String, String> else {
            XCTFail("Unable to read credentials file.")
            return
        }
        
        // read NLC username
        guard let username = credentials["NaturalLanguageClassifierUsername"] else {
            XCTFail("Unable to read Dialog username.")
            return
        }
        
        // read NLC password
        guard let password = credentials["NaturalLanguageClassifierPassword"] else {
            XCTFail("Unable to read Dialog password.")
            return
        }
        
        // instantiate the service
        if service == nil {
            service = NaturalLanguageClassifier(username: username, password: password)
        }
    }
    
    override func tearDown() {
        super.tearDown()
    }
    
    // Wait for an expectation to be fulfilled
    func waitForExpectation() {
        waitForExpectationsWithTimeout(timeout) { error in
            XCTAssertNil(error, "Timeout.")
        }
    }
    
    // MARK: - Positive test: create, list, lookup, then delete
    
    func testCreateListLookupDelete() {
        createClassifier()
        verifyListOfClassifiers()<commit_msg>Fix name of service in NaturalLanguageClassifierTests error messages<commit_after>/**
 * Copyright IBM Corporation 2015
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

import XCTest
@testable import WatsonDeveloperCloud

class NaturalLanguageClassifierTests: XCTestCase {
    
    // MARK: - Parameters and constants
    
    // the NaturalLanguageClassifier service
    var service: NaturalLanguageClassifier!
    
    // a classifier that is already trained with the given weather data
    let trainedClassifierID = "A3FCCBx16-nlc-248"
    let trainedClassifierName = "iOS SDK Test Classifier"
    let availableStatus = NaturalLanguageClassifier.Status.Available
    
    // the classifier that will be created then deleted during tests
    var temporaryClassifierID: String!
    
    // timeout for asynchronous completion handlers
    let timeout: NSTimeInterval = 30.0
    
    // MARK: - Helper functions
    
    // Load credentials and instantiate NLC service
    override func setUp() {
        super.setUp()
        
        // identify credentials file
        let bundle = NSBundle(forClass: self.dynamicType)
        guard let url = bundle.pathForResource("Credentials", ofType: "plist") else {
            XCTFail("Unable to locate credentials file.")
            return
        }
        
        // load credentials from file
        let dict = NSDictionary(contentsOfFile: url)
        guard let credentials = dict as? Dictionary<String, String> else {
            XCTFail("Unable to read credentials file.")
            return
        }
        
        // read NLC username
        guard let username = credentials["NaturalLanguageClassifierUsername"] else {
            XCTFail("Unable to read NaturalLanguageClassifier username.")
            return
        }
        
        // read NLC password
        guard let password = credentials["NaturalLanguageClassifierPassword"] else {
            XCTFail("Unable to read NaturalLanguageClassifier password.")
            return
        }
        
        // instantiate the service
        if service == nil {
            service = NaturalLanguageClassifier(username: username, password: password)
        }
    }
    
    override func tearDown() {
        super.tearDown()
    }
    
    // Wait for an expectation to be fulfilled
    func waitForExpectation() {
        waitForExpectationsWithTimeout(timeout) { error in
            XCTAssertNil(error, "Timeout.")
        }
    }
    
    // MARK: - Positive test: create, list, lookup, then delete
    
    func testCreateListLookupDelete() {
        createClassifier()
        verifyListOfClassifiers()
{'fraction_non_alphanumeric': 0.06855295068714633, 'fraction_numerical': 0.00549717057396928, 'mean_word_length': 2.425249169435216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6991904', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1477, 'n_words': 546}