<commit_before>/**
* Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program located at the root of the software packnumeric
* in a file called LICENSE.  If not, see <http://www.gnu.org/licenses/>.
*/

import XCTest
import GraphKit

class GKBondTests : XCTestCase, GKGraphDelegate {

    var u1InsertExpectation: XCTestExpectation?
    var u2InsertExpectation: XCTestExpectation?
    var friendInsertExpectation: XCTestExpectation?
	var friendDeleteExpectation: XCTestExpectation?
    var closeInsertExpectation: XCTestExpectation?
    var closeDeleteExpectation: XCTestExpectation?
    var closeSearchExpectation: XCTestExpectation?
    var permissionInsertExpectation: XCTestExpectation?
    var permissionUpdateExpectation: XCTestExpectation?
    var permissionDeleteExpectation: XCTestExpectation?
    var permissionSearchExpectation: XCTestExpectation?
    var yearInsertExpectation: XCTestExpectation?
    var yearUpdateExpectation: XCTestExpectation?
    var yearDeleteExpectation: XCTestExpectation?
    var yearSearchExpectation: XCTestExpectation?

    override func setUp() {
        super.setUp()
    }

    override func tearDown() {
        super.tearDown()
    }

    func testAll() {
        // Create a Graph instance.
        let graph: GKGraph = GKGraph()

        // Set the XCTest Class as the delegate.
        graph.delegate = self

        // Let's watch the changes in the Graph for the following Bond values.
        graph.watch(Bond: "Friend")
        graph.watch(BondGroup: "Close")
        graph.watch(BondProperty: "permission")
        graph.watch(BondProperty: "year")

        // Let's watch the User Entity values to test reverse Bond indices.
        graph.watch(Entity: "User")

        // Let's create two User Entity Objects.
        let u1: GKEntity = GKEntity(type: "User")
        u1["name"] = "Eve"

        let u2: GKEntity = GKEntity(type: "User")
        u2["name"] = "Daniel"

        // Create a Friend Bond.
        let friend: GKBond = GKBond(type: "Friend")
        friend["permission"] = "edit"
        friend["year"] = 1998
        friend.addGroup("Close")

        // Set the relationship between the users.
        friend.subject = u1
        friend.object = u2

        // Set an Expectation for the insert watcher.
        u1InsertExpectation = expectationWithDescription("User 1: Insert did not pass.")
        u2InsertExpectation = expectationWithDescription("User 2: Insert did not pass.")
        friendInsertExpectation = expectationWithDescription("Friend: Insert did not pass.")
        closeInsertExpectation = expectationWithDescription("Close: Insert did not pass.")
        closeSearchExpectation = expectationWithDescription("Close: Search did not pass.")
        permissionInsertExpectation = expectationWithDescription("Permission: Insert did not pass.")
        permissionSearchExpectation = expectationWithDescription("Permission: Search did not pass.")
        yearInsertExpectation = expectationWithDescription("Age: Insert did not pass.")
        yearSearchExpectation = expectationWithDescription("Age: Search did not pass.")

        // Save the Graph, which will execute the delegate handlers.
        graph.save() { (success: Bool, error: NSError?) in
            XCTAssertTrue(success, "Cannot save the Graph: \(error)")
        }

        // Wait for the delegates to be executed.
        waitForExpectationsWithTimeout(5, handler: nil)

        friend["permission"] = "read"
        friend["year"] = 2001

        // Set an Expectation for the update watcher.
        permissionUpdateExpectation = expectationWithDescription("Permission: Update did not pass.")
        permissionSearchExpectation = expectationWithDescription("Permission: Search did not pass.")
        yearUpdateExpectation = expectationWithDescription("Age: Update did not pass.")
        yearSearchExpectation = expectationWithDescription("Age: Search did not pass.")

        // Save the Graph, which will execute the delegate handlers.
        graph.save() { (success: Bool, error: NSError?) in
            XCTAssertTrue(success, "Cannot save the Graph: \(error)")
        }

        // Wait for the delegates to be executed.
        waitForExpectationsWithTimeout(5, handler: nil)

        friend.delete()
        u1.delete();
        u2.delete();

        // Set an Expectation for the delete watcher.
        friendDeleteExpectation = expectationWithDescription("Friend: Delete did not pass.")
        closeDeleteExpectation = expectationWithDescription("Close: Delete did not pass.")
        closeSearchExpectation = expectationWithDescription("Close: Search did not pass.")
        permissionDeleteExpectation = expectationWithDescription("Permission: Delete did not pass.")
        permissionSearchExpectation = expectationWithDescription("Permission: Search did not pass.")
        yearDeleteExpectation = expectationWithDescription("Age: Delete did not pass.")
        yearSearchExpectation = expectationWithDescription("Age: Search did not pass.")

        // Save the Graph, which will execute the delegate handlers.
        graph.save() { (success: Bool, error: NSError?) in
            XCTAssertTrue(success, "Cannot save the Graph: \(error)")<commit_msg>master: updated Bond tests to reflect latest changes in Graph<commit_after>/**
* Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program located at the root of the software packnumeric
* in a file called LICENSE.  If not, see <http://www.gnu.org/licenses/>.
*/

import XCTest
import GraphKit

class GKBondTests : XCTestCase, GKGraphDelegate {

    var u1InsertExpectation: XCTestExpectation?
    var u2InsertExpectation: XCTestExpectation?
    var friendInsertExpectation: XCTestExpectation?
	var friendDeleteExpectation: XCTestExpectation?
    var closeInsertExpectation: XCTestExpectation?
    var closeDeleteExpectation: XCTestExpectation?
    var closeSearchExpectation: XCTestExpectation?
    var permissionInsertExpectation: XCTestExpectation?
    var permissionUpdateExpectation: XCTestExpectation?
    var permissionDeleteExpectation: XCTestExpectation?
    var permissionSearchExpectation: XCTestExpectation?
    var yearInsertExpectation: XCTestExpectation?
    var yearUpdateExpectation: XCTestExpectation?
    var yearDeleteExpectation: XCTestExpectation?
    var yearSearchExpectation: XCTestExpectation?

    override func setUp() {
        super.setUp()
    }

    override func tearDown() {
        super.tearDown()
    }

    func testAll() {
        // Create a Graph instance.
        let graph: GKGraph = GKGraph()

        // Set the XCTest Class as the delegate.
        graph.delegate = self

        // Let's watch the changes in the Graph for the following Bond values.
        graph.watch(Bond: "Friend")
        graph.watch(BondGroup: "Close")
        graph.watch(BondProperty: "permission")
        graph.watch(BondProperty: "year")

        // Let's watch the User Entity values to test reverse Bond indices.
        graph.watch(Entity: "User")

        // Let's create two User Entity Objects.
        let u1: GKEntity = GKEntity(type: "User")
        u1["name"] = "Eve"

        let u2: GKEntity = GKEntity(type: "User")
        u2["name"] = "Daniel"

        // Create a Friend Bond.
        let friend: GKBond = GKBond(type: "Friend")
        friend["permission"] = "edit"
        friend["year"] = 1998
        friend.addGroup("Close")

        // Set the relationship between the users.
        friend.subject = u1
        friend.object = u2

        // Set an Expectation for the insert watcher.
        u1InsertExpectation = expectationWithDescription("User 1: Insert did not pass.")
        u2InsertExpectation = expectationWithDescription("User 2: Insert did not pass.")
        friendInsertExpectation = expectationWithDescription("Friend: Insert did not pass.")
        closeInsertExpectation = expectationWithDescription("Close: Insert did not pass.")
        closeSearchExpectation = expectationWithDescription("Close: Search did not pass.")
        permissionInsertExpectation = expectationWithDescription("Permission: Insert did not pass.")
        permissionSearchExpectation = expectationWithDescription("Permission: Search did not pass.")
        yearInsertExpectation = expectationWithDescription("Age: Insert did not pass.")
        yearSearchExpectation = expectationWithDescription("Age: Search did not pass.")

        // Save the Graph, which will execute the delegate handlers.
        graph.save() { (success: Bool, error: NSError?) in
            XCTAssertTrue(success, "Cannot save the Graph: \(error)")
        }

        // Wait for the delegates to be executed.
        waitForExpectationsWithTimeout(5, handler: nil)

        friend["permission"] = "read"
        friend["year"] = 2001

        // Set an Expectation for the update watcher.
        permissionUpdateExpectation = expectationWithDescription("Permission: Update did not pass.")
        permissionSearchExpectation = expectationWithDescription("Permission: Search did not pass.")
        yearUpdateExpectation = expectationWithDescription("Age: Update did not pass.")
        yearSearchExpectation = expectationWithDescription("Age: Search did not pass.")

        // Save the Graph, which will execute the delegate handlers.
        graph.save() { (success: Bool, error: NSError?) in
            XCTAssertTrue(success, "Cannot save the Graph: \(error)")
        }

        // Wait for the delegates to be executed.
        waitForExpectationsWithTimeout(5, handler: nil)

        u1.delete();
        u2.delete();

        // Set an Expectation for the delete watcher.
        friendDeleteExpectation = expectationWithDescription("Friend: Delete did not pass.")
        closeDeleteExpectation = expectationWithDescription("Close: Delete did not pass.")
        closeSearchExpectation = expectationWithDescription("Close: Search did not pass.")
        permissionDeleteExpectation = expectationWithDescription("Permission: Delete did not pass.")
        permissionSearchExpectation = expectationWithDescription("Permission: Search did not pass.")
        yearDeleteExpectation = expectationWithDescription("Age: Delete did not pass.")
        yearSearchExpectation = expectationWithDescription("Age: Search did not pass.")

        // Save the Graph, which will execute the delegate handlers.
        graph.save() { (success: Bool, error: NSError?) in
            XCTAssertTrue(success, "Cannot save the Graph: \(error)")
{'fraction_non_alphanumeric': 0.08151803948264125, 'fraction_numerical': 0.004935330156569094, 'mean_word_length': 3.3177810433504775, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1675825', 'n_tokens_mistral': 3001, 'n_tokens_neox': 2884, 'n_words': 1045}