<commit_before>import XCTest
@testable import Fluent

class MemoryTests: XCTestCase {
    static var allTests : [(String, (MemoryTests) -> () throws -> Void)] {
        return [
            ("testSave", testSave)
        ]
    }

    func makeTestModels() -> (MemoryDriver, Database) {
        let driver = MemoryDriver()
        let database = Database(driver)

        return (driver, database)
    }
    
    func testSave() throws {
        let (driver, database) = makeTestModels()

        var user = User(id: nil, name: "Vapor", email: "<EMAIL>")
        let query = Query<User>(database)
        try query.save(&user)
        XCTAssertEqual(user.id?.int, 1)
        XCTAssertEqual(driver.store["users"]?.data.count, 1)
    }

    func testFetch() throws {
        let (driver, database) = makeTestModels()

        var new = User(id: nil, name: "Vapor", email: "<EMAIL>")
        let store = Query<User>(database)
        try store.save(&new)

        let fetched = try Query<User>(database).filter("name", "Vapor").first()
        XCTAssertEqual(new.id, fetched?.id)
        XCTAssertEqual(driver.store["users"]?.data.count, 1)
    }

    func testDelete() throws {
        let (driver, database) = makeTestModels()

        for _ in 0 ..< 100 {
            var new = User(id: nil, name: "Vapor", email: "<EMAIL>")
            let store = Query<User>(database)
            try store.save(&new)
        }

        XCTAssertEqual(driver.store["users"]?.data.count, 100)
        try Query<User>(database).filter("id", .greaterThan, 50).delete()
        XCTAssertEqual(driver.store["users"]?.data.count, 50)
    }

    func testModify() throws {
        let (_, database) = makeTestModels()

        for _ in 0 ..< 100 {
            var new = User(id: nil, name: "Vapor", email: "<EMAIL>")
            try Query<User>(database).save(&new)
        }

        let results = try Query<User>(database).filter("name", "Vapor").all()
        XCTAssertEqual(results.count, 100)
        
        try Query<User>(database).modify(Node.object(["name": "updated", "email": "updated"]))

        let resultsTwo = try Query<User>(database).filter("name", "Vapor").all()
        XCTAssertEqual(resultsTwo.count, 0)

        let resultsThree = try Query<User>(database).filter("name", "updated").all()
        XCTAssertEqual(resultsThree.count, 100)
    }

    func testSort() throws {
        let (_, database) = makeTestModels()
        let fruits = ["Apple", "Orange", "Strawberry", "Mango"]

        for _ in 0 ..< 100 {
            let fruit = fruits.random
            var new = User(id: nil, name: fruit, email: <EMAIL>")
            try Query<User>(database).save(&new)
        }

        let sorted = try Query<User>(database).sort("name", .ascending).all()
        let unsorted = try Query<User>(database).all()
        XCTAssertNotEqual(sorted, unsorted)
        XCTAssertEqual(sorted, unsorted.sorted(by: { u1, u2 in
            return u1.name < u2.name
        }))
    }
}<commit_msg>Added unit test for count in the MemoryDriver<commit_after>import XCTest
@testable import Fluent

class MemoryTests: XCTestCase {
    static var allTests : [(String, (MemoryTests) -> () throws -> Void)] {
        return [
            ("testSave", testSave)
        ]
    }

    func makeTestModels() -> (MemoryDriver, Database) {
        let driver = MemoryDriver()
        let database = Database(driver)

        return (driver, database)
    }
    
    func testSave() throws {
        let (driver, database) = makeTestModels()

        var user = User(id: nil, name: "Vapor", email: "<EMAIL>")
        let query = Query<User>(database)
        try query.save(&user)
        XCTAssertEqual(user.id?.int, 1)
        XCTAssertEqual(driver.store["users"]?.data.count, 1)
    }

    func testFetch() throws {
        let (driver, database) = makeTestModels()

        var new = User(id: nil, name: "Vapor", email: "<EMAIL>")
        let store = Query<User>(database)
        try store.save(&new)

        let fetched = try Query<User>(database).filter("name", "Vapor").first()
        XCTAssertEqual(new.id, fetched?.id)
        XCTAssertEqual(driver.store["users"]?.data.count, 1)
    }

    func testDelete() throws {
        let (driver, database) = makeTestModels()

        for _ in 0 ..< 100 {
            var new = User(id: nil, name: "Vapor", email: "<EMAIL>")
            let store = Query<User>(database)
            try store.save(&new)
        }

        XCTAssertEqual(driver.store["users"]?.data.count, 100)
        try Query<User>(database).filter("id", .greaterThan, 50).delete()
        XCTAssertEqual(driver.store["users"]?.data.count, 50)
    }

    func testModify() throws {
        let (_, database) = makeTestModels()

        for _ in 0 ..< 100 {
            var new = User(id: nil, name: "Vapor", email: "<EMAIL>")
            try Query<User>(database).save(&new)
        }

        let results = try Query<User>(database).filter("name", "Vapor").all()
        XCTAssertEqual(results.count, 100)
        
        try Query<User>(database).modify(Node.object(["name": "updated", "email": "updated"]))

        let resultsTwo = try Query<User>(database).filter("name", "Vapor").all()
        XCTAssertEqual(resultsTwo.count, 0)

        let resultsThree = try Query<User>(database).filter("name", "updated").all()
        XCTAssertEqual(resultsThree.count, 100)
    }

    func testSort() throws {
        let (_, database) = makeTestModels()
        let fruits = ["Apple", "Orange", "Strawberry", "Mango"]

        for _ in 0 ..< 100 {
            let fruit = fruits.random
            var new = User(id: nil, name: fruit, email: <EMAIL>")
            try Query<User>(database).save(&new)
        }

        let sorted = try Query<User>(database).sort("name", .ascending).all()
        let unsorted = try Query<User>(database).all()
        XCTAssertNotEqual(sorted, unsorted)
        XCTAssertEqual(sorted, unsorted.sorted(by: { u1, u2 in
            return u1.name < u2.name
        }))
    }
    
    func testCount() throws {
        let (driver, database) = makeTestModels()
        
        var new1 = User(id: nil, name: "Vapor", email: "<EMAIL>")
        var new2 = User(id: nil, name: "Vapor", email: "<EMAIL>")
        let store = Query<User>(database)
        try store.save(&new1)
        try store.save(&new2)

        let count1 = try Query<User>(database).filter("name", "Vapor").count()
        XCTAssertEqual(count1, 2)
        
        let count2 = try Query<User>(database).filter("email", "<EMAIL>").count()
        XCTAssertEqual(count2, 1)
        
        let count3 = try Query<User>(database).filter("name", "Test").count()
        XCTAssertEqual(count3, 0)
    }
}
{'fraction_non_alphanumeric': 0.15014925373134327, 'fraction_numerical': 0.011791044776119404, 'mean_word_length': 2.403250380904012, 'pattern_counts': {'":': 4, '<': 54, '<?xml version=': 0, '>': 52, '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': '6796543', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2011, 'n_words': 478}