<commit_before>import XCTest
@testable import gattaca

class TFDatabaseUsersItemLocation:XCTestCase
{
    private var user:FDatabaseUsersItem?
    private let kUserId:String = "lorem ipsum"
    private let kCountryId:String = "banana republic"
    
    override func setUp()
    {
        super.setUp()
        
        let users:FDatabaseUsers = FDatabaseUsers()
        user = FDatabaseUsersItem(
            users:users)
    }
    
    //MARK: internal
    
    func testUserIsCreated()
    {
        XCTAssertNotNil(
            user,
            "failed creating user")
    }
    
    func testInitNoIdentifier()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        XCTAssertNil(
            location,
            "if user has no id there should be no location")
    }
    
    func testInitIdentifier()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        user.identifier = kUserId
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        XCTAssertNotNil(
            location,
            "failed creating location")
        
        XCTAssertNotNil(
            location?.parent,
            "parent should not be nil")
    }
    
    func testIdentifier()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        user.identifier = kUserId
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        XCTAssertEqual(
            location?.identifier,
            FDatabaseUsersItem.kKeyLocation,
            "identifier doesn't match user property")
    }
    
    func testJson()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        user.identifier = kUserId
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        let json:Any? = location?.json
        
        XCTAssertNotNil(
            json,
            "failed creating json")
        
        let jsonMap:[String:Any]? = json as? [String:Any]
        
        XCTAssertNotNil(
            jsonMap,
            "json is not a dictionary")
        
        let jsonCountry:String? = jsonMap?[
            FDatabaseUsersItemLocation.kKeyCountry] as? String
        
        XCTAssertNotNil(
            jsonCountry,
            "json doesn't contain country")
        
        XCTAssertEqual(
            jsonCountry,
            kCountryId,
            "json country does not match")
    }
}<commit_msg>Test for init with json<commit_after>import XCTest
@testable import gattaca

class TFDatabaseUsersItemLocation:XCTestCase
{
    private var user:FDatabaseUsersItem?
    private let kUserId:String = "lorem ipsum"
    private let kCountryId:String = "banana republic"
    
    override func setUp()
    {
        super.setUp()
        
        let users:FDatabaseUsers = FDatabaseUsers()
        user = FDatabaseUsersItem(
            users:users)
    }
    
    //MARK: private
    
    private func factoryInitJson() -> Any
    {
        let json:[String:Any] = [
            FDatabaseUsersItemLocation.kKeyCountry:kCountryId]
        
        return json
    }
    
    //MARK: internal
    
    func testUserIsCreated()
    {
        XCTAssertNotNil(
            user,
            "failed creating user")
    }
    
    func testInitNoIdentifier()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        XCTAssertNil(
            location,
            "if user has no id there should be no location")
    }
    
    func testInitIdentifier()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        user.identifier = kUserId
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        XCTAssertNotNil(
            location,
            "failed creating location")
        
        XCTAssertNotNil(
            location?.parent,
            "parent should not be nil")
    }
    
    func testIdentifier()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        user.identifier = kUserId
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        XCTAssertEqual(
            location?.identifier,
            FDatabaseUsersItem.kKeyLocation,
            "identifier doesn't match user property")
    }
    
    func testJson()
    {
        guard
            
            let user:FDatabaseUsersItem = self.user
            
        else
        {
            return
        }
        
        user.identifier = kUserId
        
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            user:user,
            country:kCountryId)
        
        let json:Any? = location?.json
        
        XCTAssertNotNil(
            json,
            "failed creating json")
        
        let jsonMap:[String:Any]? = json as? [String:Any]
        
        XCTAssertNotNil(
            jsonMap,
            "json is not a dictionary")
        
        let jsonCountry:String? = jsonMap?[
            FDatabaseUsersItemLocation.kKeyCountry] as? String
        
        XCTAssertNotNil(
            jsonCountry,
            "json doesn't contain country")
        
        XCTAssertEqual(
            jsonCountry,
            kCountryId,
            "json country does not match")
    }
    
    func testInitJson()
    {
        let json:Any = factoryInitJson()
        let location:FDatabaseUsersItemLocation? = FDatabaseUsersItemLocation(
            json:json)
        
        XCTAssertNotNil(
            location,
            "failed init with json")
    }
}
{'fraction_non_alphanumeric': 0.061009509875640085, 'fraction_numerical': 0.0, 'mean_word_length': 1.3118025025363544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 2, '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': '6541409', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1768, 'n_words': 368}