<commit_before>import Foundation
import Alamofire
@testable import Aldo

public class MockAldo: Aldo {
    
    public class func getHostAddress() -> String {
        return Aldo.hostAddress
    }
    
    public class func getPort() -> Int {
        return Aldo.port
    }
    
    override public class func request(command: String, method: HTTPMethod, parameters: Parameters, callback: Callback? = nil) {
        var response: Dictionary<String, Any> = [:]
        var components = command.components(separatedBy: "/")
        
        switch command {
        case Regex(pattern: RequestURI.REQUEST_AUTH_TOKEN.regex()):
            response["deviceID"] = AldoTests.deviceId
            response["token"] = AldoTests.authToken
            break
        case Regex(pattern: RequestURI.SESSION_CREATE.regex()):
            var tokens: Dictionary<String, String> = [:]
            tokens["moderator"] = AldoTests.moderatorToken
            tokens["user"] = AldoTests.userToken
            
            var session: Dictionary<String, Any> = createSessionResponse()
            session["tokens"] = tokens
            
            response["playerID"] = AldoTests.playerId
            response["session"] = session
            response["role"] = Player.Role.ADMIN.rawValue
            response["score"] = 0
            response["username"] = components[3]
            break
        case Regex(pattern: RequestURI.SESSION_JOIN.regex()):
            let isUserJoin = (components[3] == AldoTests.userToken)
            
            response = createPlayerResponse()
            response["role"] = isUserJoin ? Player.Role.USER.rawValue : Player.Role.MODERATOR.rawValue
            response["username"] = components[5]
            break
        case Regex(pattern: RequestURI.SESSION_INFO.regex()):
            var tokens: Dictionary<String, String> = [:]
            
            if Aldo.getPlayer()!.isAdmin() {
                tokens["moderator"] = AldoTests.moderatorToken
                tokens["user"] = AldoTests.userToken
            }
            
            response = createSessionResponse()
            response["tokens"] = tokens
            break
        case Regex(pattern: RequestURI.SESSION_PLAYERS.regex()):
            var players = [Dictionary<String, Any>]()
            var player: Dictionary<String, Any> = [:]
            player["playerID"] = AldoTests.playerId
            player["username"] = AldoTests.username
            player["score"] = 0
            
            players.append(player)
            response["players"] = players
            break
        case Regex(pattern: RequestURI.SESSION_STATE_PLAY.regex()):
            response = createSessionResponse()
            break
        case Regex(pattern: RequestURI.SESSION_STATE_PAUSE.regex()):
            response = createSessionResponse()
            response["status"] = Session.Status.PAUSED.rawValue
            break
        case Regex(pattern: RequestURI.SESSION_DELETE.regex()):
            response = createSessionResponse()
            response["status"] = 0
            break
        case Regex(pattern: RequestURI.PLAYER_ALL.regex()):
            var players = [Dictionary<String, Any>]()
            
            players.append(createPlayerResponse())
            response["players"] = players
            break
        case Regex(pattern: RequestURI.PLAYER_INFO.regex()):
            response = createPlayerResponse()
            break
        case Regex(pattern: RequestURI.PLAYER_USERNAME_UPDATE.regex()):
            response = createPlayerResponse()
            response["username"] = components[3]
            break
        default:
            break
        }
        AldoMainCallback(callback: callback).onResponse(request: command, responseCode: 200, response: response as NSDictionary)
    }
    
    public static func createSessionResponse() -> Dictionary<String, Any> {
        var response: Dictionary<String, Any> = [:]
        response["sessionID"] = AldoTests.sessionId
        response["adminID"] = AldoTests.playerId
        response["status"] = Session.Status.PLAYING.rawValue
        response["created"] = AldoTests.creationDate
        return response
    }
    
    public static func createPlayerResponse() -> Dictionary<String, Any> {
        var response: Dictionary<String, Any> = [:]
        response["playerID"] = AldoTests.playerId
        response["session"] = createSessionResponse()
        response["role"] = Player.Role.USER.rawValue
        response["score"] = 0
        response["username"] = AldoTests.username
        return response
    }
    
}
<commit_msg>Refactor the MockAldo class.<commit_after>import Foundation
import Alamofire
@testable import Aldo

public class MockAldo: Aldo {
    
    public class func getHostAddress() -> String {
        return Aldo.hostAddress
    }
    
    public class func getPort() -> Int {
        return Aldo.port
    }
    
    override public class func request(uri: String, method: HTTPMethod, parameters: Parameters, callback: Callback? = nil) {
        var response: Dictionary<String, Any> = [:]
        var components = uri.components(separatedBy: "/")
        
        switch uri {
        case Regex(pattern: RequestURI.REQUEST_AUTH_TOKEN.regex()):
            response["deviceID"] = AldoTests.deviceId
            response["token"] = <PASSWORD>.authToken
            break
        case Regex(pattern: RequestURI.SESSION_CREATE.regex()):
            response = createPlayerResponse(role: Player.Role.ADMIN)
            response["username"] = components[3]
            break
        case Regex(pattern: RequestURI.SESSION_JOIN.regex()):
            let isUserJoin = (components[3] == AldoTests.userToken)
            
            response = createPlayerResponse()
            response["role"] = isUserJoin ? Player.Role.USER.rawValue : Player.Role.MODERATOR.rawValue
            response["username"] = components[5]
            break
        case Regex(pattern: RequestURI.SESSION_INFO.regex()):
            let player: Player = MockAldo.getPlayer()!
            response = createSessionResponse(role: player.getRole())
            break
        case Regex(pattern: RequestURI.SESSION_PLAYERS.regex()):
            var players = [Dictionary<String, Any>]()
            var player: Dictionary<String, Any> = [:]
            player["playerID"] = AldoTests.playerId
            player["username"] = AldoTests.username
            player["score"] = 0
            
            players.append(player)
            response["players"] = players
            break
        case Regex(pattern: RequestURI.SESSION_STATE_PLAY.regex()):
            response = createSessionResponse()
            break
        case Regex(pattern: RequestURI.SESSION_STATE_PAUSE.regex()):
            response = createSessionResponse()
            response["status"] = Session.Status.PAUSED.rawValue
            break
        case Regex(pattern: RequestURI.SESSION_DELETE.regex()):
            response = createSessionResponse()
            response["status"] = 0
            break
        case Regex(pattern: RequestURI.PLAYER_ALL.regex()):
            var players = [Dictionary<String, Any>]()
            
            players.append(createPlayerResponse())
            response["players"] = players
            break
        case Regex(pattern: RequestURI.PLAYER_INFO.regex()):
            response = createPlayerResponse()
            break
        case Regex(pattern: RequestURI.PLAYER_USERNAME_UPDATE.regex()):
            response = createPlayerResponse()
            response["username"] = components[3]
            break
        default:
            break
        }
        AldoMainCallback(callback: callback).onResponse(request: uri, responseCode: 200, response: response as NSDictionary)
    }
    
    
    /// Helper method to simulate the way the Aldo Framework
    /// returns information about a session.
    public static func createSessionResponse(role: Player.Role = Player.Role.USER) -> Dictionary<String, Any> {
        var response: Dictionary<String, Any> = [:]
        response["sessionID"] = AldoTests.sessionId
        response["adminID"] = AldoTests.playerId
        response["status"] = Session.Status.PLAYING.rawValue
        response["created"] = AldoTests.creationDate
        
        if role == Player.Role.ADMIN {
            response["tokens"] = createTokensResponse()
        }
        return response
    }
    
    /// Helper method to simulate the way the Aldo Framework
    /// returns information about the join tokens of a session.
    public static func createTokensResponse() -> Dictionary<String, Any> {
        var response: Dictionary<String, String> = [:]
        response["moderator"] = AldoTests.moderatorToken
        response["user"] = AldoTests.userToken
        return response
    }
    
    /// Helper method to simulate the way the Aldo Framework
    /// returns information about a player.
    public static func createPlayerResponse(role: Player.Role = Player.Role.USER) -> Dictionary<String, Any> {
        var response: Dictionary<String, Any> = [:]
        response["playerID"] = AldoTests.playerId
        response["session"] = createSessionResponse(role: role)
        response["role"] = role.rawValue
        response["score"] = 0
        response["username"] = AldoTests.username
        return response
    }
    
}

{'fraction_non_alphanumeric': 0.10318225650916105, 'fraction_numerical': 0.0022500803600128574, 'mean_word_length': 2.2286406087858874, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 34, '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': '2105959', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2339, 'n_words': 526}