<commit_before>//
// Created by <NAME> on 3/25/17.
//

import Foundation
import XCTest
@testable import SwiftDiscord

public class TestDiscordGuild : XCTestCase {
    func testCreatingGuildSetsId() {
        let guild = DiscordGuild(guildObject: testGuild, client: nil)

        XCTAssertEqual(guild.id, 100, "init should set id")
    }

    func testCreatingGuildSetsName() {
        let guild = DiscordGuild(guildObject: testGuild, client: nil)

        XCTAssertEqual(guild.name, "Test Guild", "init should set name")
    }

    func testCreatingGuildSetsDefaultMessageNotifications() {
        let guild = DiscordGuild(guildObject: testGuild, client: nil)

        XCTAssertEqual(guild.defaultMessageNotifications, 0, "init should set default message notifications")
    }

    func testCreatingGuildSetsEmbedEnabled() {
        tGuild["embed_enabled"] = true

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertTrue(guild.embedEnabled, "init should set embed enabled")
    }

    func testCreatingGuildSetsEmbedChannel() {
        tGuild["embed_channel_id"] = "200"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.embedChannelId, 200, "init should set the embed channel id")
    }

    func testCreatingGuildSetsIcon() {
        tGuild["icon"] = "someicon"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.icon, "someicon", "init should set icon")
    }

    func testCreatingGuildSetsLarge() {
        tGuild["large"] = true

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertTrue(guild.large, "init should set large")
    }

    func testCreatingGuildSetsMemberCount() {
        tGuild["member_count"] = 20000

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.memberCount, 20000, "init should set member count")
    }

    func testCreatingGuildSetsMFALevel() {
        tGuild["mfa_level"] = 1

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.mfaLevel, 1, "init should set MFA level")
    }

    func testCreatingGuildSetsOwnerId() {
        tGuild["owner_id"] = "601"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.ownerId, 601, "init should set owner id")
    }

    func testCreatingGuildSetsRegion() {
        tGuild["region"] = "us-east"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.region, "us-east", "init should set region")
    }

    func testCreatingGuildSetsSplash() {
        tGuild["splash"] = "somesplash"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.splash, "somesplash", "init should set splash")
    }

    func testCreatingGuildSetsVerificationLevel() {
        tGuild["verification_level"] = 1

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.verificationLevel, 1, "init should set verification level")
    }

    func testCreatingGuildSetsUnavailable() {
        tGuild["unavailable"] = true

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertTrue(guild.unavailable, "init should set unavailable")
    }

    func testGuildCorrectlyGetsRolesForMember() {
        var tMember = testMember
        var role2 = testRole

        role2["id"] = "401"
        role2["name"] = "<PASSWORD>"
        tMember["roles"] = [testRole["id"] as! String, role2["id"] as! String]

        let guild = DiscordGuild(guildObject: ["id": "guildid",
                                               "roles": [testRole, role2]
                                              ], client: nil)
        let member = DiscordGuildMember(guildMemberObject: tMember, guildId: guild.id, guild: guild)

        XCTAssertEqual(guild.roles.count, 2, "guild should have two roles")

        let roles = guild.roles(for: member)

        XCTAssertEqual(roles.count, 2, "guild should find two roles for member")
        XCTAssertNotNil(roles.first(where: { $0.id == Snowflake(testRole["id"] as! String)! }), "roles should find testrole")
        XCTAssertNotNil(roles.first(where: { $0.id == Snowflake(role2["id"] as! String)! }), "roles should find role2")
    }

    func testCreatingGuildWithALargeNumberOfMembersIsFast() {
        tGuild["members"] = createGuildMemberObjects(n: 100_000)

        var guild: DiscordGuild!

        measure {
            guild = DiscordGuild(guildObject: self.tGuild, client: nil)
        }

        XCTAssertEqual(guild.members.count, 100_000, "init should create 100_000 members")
        XCTAssertEqual(guild.members[5000]?.user.id, 5000, "init should create members correctly")
    }

    func testCreatingGuildWithALargeNumberOfPresencesIsFast() {
        tGuild["presences"] = createPresenceObjects(n: 100_000)

        var guild: DiscordGuild!

        measure {
            guild = DiscordGuild(guildObject: self.tGuild, client: nil)
        }

        XCTAssertEqual(guild.presences.count, 100_000, "init should create 100_000 presences")
        XCTAssertEqual(guild.presences[5000]?.user.id, 5000, "init should create presences correctly")
    }

    var tGuild: [String: Any]!

    public static var allTests: [(String, (TestDiscordGuild) -> () -> ())] {
        return [
            ("testCreatingGuildSetsId", testCreatingGuildSetsId),
            ("testCreatingGuildSetsName", testCreatingGuildSetsName),
            ("testCreatingGuildSetsDefaultMessageNotifications", testCreatingGuildSetsDefaultMessageNotifications),
            ("testCreatingGuildSetsEmbedEnabled", testCreatingGuildSetsEmbedEnabled),
            ("testCreatingGuildSetsEmbedChannel", testCreatingGuildSetsEmbedChannel),
            ("testCreatingGuildSetsIcon", testCreatingGuildSetsIcon),
            ("testCreatingGuildSetsLarge", testCreatingGuildSetsLarge),
            ("testCreatingGuildSetsMemberCount", testCreatingGuildSetsMemberCount),
            ("testCreatingGuildSetsMFALevel", testCreatingGuildSetsMFALevel),
            ("testCreatingGuildSetsOwnerId", testCreatingGuildSetsOwnerId),
            ("testCreatingGuildSetsRegion", testCreatingGuildSetsRegion),
            ("testCreatingGuildSetsSplash", testCreatingGuildSetsSplash),
            ("testCreatingGuildSetsVerificationLevel", testCreatingGuildSetsVerificationLevel),
            ("testCreatingGuildSetsUnavailable", testCreatingGuildSetsUnavailable),
            ("testGuildCorrectlyGetsRolesForMember", testGuildCorrectlyGetsRolesForMember),
            ("testCreatingGuildWithALargeNumberOfMembersIsFast", testCreatingGuildWithALargeNumberOfMembersIsFast),
            ("testCreatingGuildWithALargeNumberOfPresencesIsFast", testCreatingGuildWithALargeNumberOfPresencesIsFast),
        ]
    }

    public override func setUp() {
        tGuild = testGuild
    }
}<commit_msg>Rename performance tests to reflect what they actually do<commit_after>//
// Created by <NAME> on 3/25/17.
//

import Foundation
import XCTest
@testable import SwiftDiscord

public class TestDiscordGuild : XCTestCase {
    func testCreatingGuildSetsId() {
        let guild = DiscordGuild(guildObject: testGuild, client: nil)

        XCTAssertEqual(guild.id, 100, "init should set id")
    }

    func testCreatingGuildSetsName() {
        let guild = DiscordGuild(guildObject: testGuild, client: nil)

        XCTAssertEqual(guild.name, "Test Guild", "init should set name")
    }

    func testCreatingGuildSetsDefaultMessageNotifications() {
        let guild = DiscordGuild(guildObject: testGuild, client: nil)

        XCTAssertEqual(guild.defaultMessageNotifications, 0, "init should set default message notifications")
    }

    func testCreatingGuildSetsEmbedEnabled() {
        tGuild["embed_enabled"] = true

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertTrue(guild.embedEnabled, "init should set embed enabled")
    }

    func testCreatingGuildSetsEmbedChannel() {
        tGuild["embed_channel_id"] = "200"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.embedChannelId, 200, "init should set the embed channel id")
    }

    func testCreatingGuildSetsIcon() {
        tGuild["icon"] = "someicon"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.icon, "someicon", "init should set icon")
    }

    func testCreatingGuildSetsLarge() {
        tGuild["large"] = true

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertTrue(guild.large, "init should set large")
    }

    func testCreatingGuildSetsMemberCount() {
        tGuild["member_count"] = 20000

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.memberCount, 20000, "init should set member count")
    }

    func testCreatingGuildSetsMFALevel() {
        tGuild["mfa_level"] = 1

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.mfaLevel, 1, "init should set MFA level")
    }

    func testCreatingGuildSetsOwnerId() {
        tGuild["owner_id"] = "601"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.ownerId, 601, "init should set owner id")
    }

    func testCreatingGuildSetsRegion() {
        tGuild["region"] = "us-east"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.region, "us-east", "init should set region")
    }

    func testCreatingGuildSetsSplash() {
        tGuild["splash"] = "somesplash"

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.splash, "somesplash", "init should set splash")
    }

    func testCreatingGuildSetsVerificationLevel() {
        tGuild["verification_level"] = 1

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertEqual(guild.verificationLevel, 1, "init should set verification level")
    }

    func testCreatingGuildSetsUnavailable() {
        tGuild["unavailable"] = true

        let guild = DiscordGuild(guildObject: tGuild, client: nil)

        XCTAssertTrue(guild.unavailable, "init should set unavailable")
    }

    func testGuildCorrectlyGetsRolesForMember() {
        var tMember = testMember
        var role2 = testRole

        role2["id"] = "401"
        role2["name"] = "A new role"
        tMember["roles"] = [testRole["id"] as! String, role2["id"] as! String]

        let guild = DiscordGuild(guildObject: ["id": "guildid",
                                               "roles": [testRole, role2]
                                              ], client: nil)
        let member = DiscordGuildMember(guildMemberObject: tMember, guildId: guild.id, guild: guild)

        XCTAssertEqual(guild.roles.count, 2, "guild should have two roles")

        let roles = guild.roles(for: member)

        XCTAssertEqual(roles.count, 2, "guild should find two roles for member")
        XCTAssertNotNil(roles.first(where: { $0.id == Snowflake(testRole["id"] as! String)! }), "roles should find testrole")
        XCTAssertNotNil(roles.first(where: { $0.id == Snowflake(role2["id"] as! String)! }), "roles should find role2")
    }

    func testCreatingGuildWithALargeNumberOfMembersIsConsistent() {
        tGuild["members"] = createGuildMemberObjects(n: 100_000)

        var guild: DiscordGuild!

        measure {
            guild = DiscordGuild(guildObject: self.tGuild, client: nil)
        }

        XCTAssertEqual(guild.members.count, 100_000, "init should create 100_000 members")
        XCTAssertEqual(guild.members[5000]?.user.id, 5000, "init should create members correctly")
    }

    func testCreatingGuildWithALargeNumberOfPresencesIsConsistent() {
        tGuild["presences"] = createPresenceObjects(n: 100_000)

        var guild: DiscordGuild!

        measure {
            guild = DiscordGuild(guildObject: self.tGuild, client: nil)
        }

        XCTAssertEqual(guild.presences.count, 100_000, "init should create 100_000 presences")
        XCTAssertEqual(guild.presences[5000]?.user.id, 5000, "init should create presences correctly")
    }

    var tGuild: [String: Any]!

    public static var allTests: [(String, (TestDiscordGuild) -> () -> ())] {
        return [
            ("testCreatingGuildSetsId", testCreatingGuildSetsId),
            ("testCreatingGuildSetsName", testCreatingGuildSetsName),
            ("testCreatingGuildSetsDefaultMessageNotifications", testCreatingGuildSetsDefaultMessageNotifications),
            ("testCreatingGuildSetsEmbedEnabled", testCreatingGuildSetsEmbedEnabled),
            ("testCreatingGuildSetsEmbedChannel", testCreatingGuildSetsEmbedChannel),
            ("testCreatingGuildSetsIcon", testCreatingGuildSetsIcon),
            ("testCreatingGuildSetsLarge", testCreatingGuildSetsLarge),
            ("testCreatingGuildSetsMemberCount", testCreatingGuildSetsMemberCount),
            ("testCreatingGuildSetsMFALevel", testCreatingGuildSetsMFALevel),
            ("testCreatingGuildSetsOwnerId", testCreatingGuildSetsOwnerId),
            ("testCreatingGuildSetsRegion", testCreatingGuildSetsRegion),
            ("testCreatingGuildSetsSplash", testCreatingGuildSetsSplash),
            ("testCreatingGuildSetsVerificationLevel", testCreatingGuildSetsVerificationLevel),
            ("testCreatingGuildSetsUnavailable", testCreatingGuildSetsUnavailable),
            ("testGuildCorrectlyGetsRolesForMember", testGuildCorrectlyGetsRolesForMember),
            ("testCreatingGuildWithALargeNumberOfMembersIsConsistent", testCreatingGuildWithALargeNumberOfMembersIsConsistent),
            ("testCreatingGuildWithALargeNumberOfPresencesIsConsistent", testCreatingGuildWithALargeNumberOfPresencesIsConsistent),
        ]
    }

    public override func setUp() {
        tGuild = testGuild
    }
}
{'fraction_non_alphanumeric': 0.09701811956056498, 'fraction_numerical': 0.014410044228848623, 'mean_word_length': 3.2806106870229006, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6027301', 'n_tokens_mistral': 4533, 'n_tokens_neox': 4109, 'n_words': 860}