<commit_before>var assert = chai.assert;

var users = {
    'a': {approvals: ['v', 'w'], disapprovals: []},
    'b': {approvals: [], disapprovals: []},
    'm': {approvals: ['n'], disapprovals: ['y']},
    'n': {approvals: [], disapprovals: ['x']},
    'v': {approvals: ['x'], disapprovals: []},
    'w': {approvals: ['b'], disapprovals: []},
    'x': {approvals: ['y'], disapprovals: ['b']},
    'y': {approvals: ['z'], disapprovals: []},
    'z': {approvals: ['b'], disapprovals: []},
};

var getApprovalsFor = function(userId) {
    return Promise.resolve(users[userId].approvals);
};

var getDisapprovalsFor = function(userId) {
    return Promise.resolve(users[userId].disapprovals);
};

var server = {getApprovalsFor, getDisapprovalsFor};

describe('EtherCredUser', function() {
    describe('getCredFor', function() {
        describe('using gravityAlgorithm', function() {
            it('should calculate cred correctly when there are multiple valid paths', function() {

                var userAAddress = 'a', userBAddress = 'b';
                var userA;
                return EtherCredClient.getUser(userAAddress, gravityAlgorithm, server).then(function(user) {
                    userA = user;
                    var actualCred = userA.getCredFor(userBAddress);
                    var expectedCred = (1 / 2) + (1 / 16) - (1 / 4);

                    assert.equal(actualCred, expectedCred);
                });
            });
        });
    });
});<commit_msg>Adds some tests for EtherCredUser<commit_after>var assert = chai.assert;

var users;

var getApprovalsFor = function(userId) {
    return Promise.resolve(users[userId].approvals);
};

var getDisapprovalsFor = function(userId) {
    return Promise.resolve(users[userId].disapprovals);
};

var approve = function(requesterId, targetId) {
    users[requesterId].approvals[targetId] = true;
    return Promise.resolve();
}

var unapprove = function(requesterId, targetId) {
    delete users[requesterId].approvals[targetId];
    return Promise.resolve();
}

var disapprove = function(requesterId, targetId) {
    users[requesterId].disapprovals[targetId] = true;
    return Promise.resolve();
}

var undisapprove = function(requesterId, targetId) {
    delete users[requesterId].disapprovals[targetId];
    return Promise.resolve();
}

var server = {getApprovalsFor, getDisapprovalsFor, approve, unapprove, disapprove, undisapprove};

describe('EtherCredUser', function() {
    describe('getCredFor', function() {
        describe('using gravityAlgorithm', function() {
            it('should calculate cred correctly when there are multiple valid paths', function() {
                users = {
                    'a': {approvals: ['v', 'w'], disapprovals: []},
                    'b': {approvals: [], disapprovals: []},
                    'm': {approvals: ['n'], disapprovals: ['y']},
                    'n': {approvals: [], disapprovals: ['x']},
                    'v': {approvals: ['x'], disapprovals: []},
                    'w': {approvals: ['b'], disapprovals: []},
                    'x': {approvals: ['y'], disapprovals: ['b']},
                    'y': {approvals: ['z'], disapprovals: []},
                    'z': {approvals: ['b'], disapprovals: []},
                };

                var userAAddress = 'a', userBAddress = 'b';
                var userA;
                return EtherCredClient.getUser(userAAddress, gravityAlgorithm, server).then(function(user) {
                    userA = user;
                    var actualCred = userA.getCredFor(userBAddress);
                    var expectedCred = (1 / 2) + (1 / 16) - (1 / 4);

                    assert.equal(actualCred, expectedCred);
                });
            });
        });
    });

    describe('approve', function() {
        it('should add the target user to the requester\'s approval list', function() {
            users = {
                'a': {approvals: {}, disapprovals: {}},
                'b': {approvals: {}, disapprovals: {}}
            };

            var userAAddress = 'a', userBAddress = 'b';
            var userA;
            return EtherCredClient.getUser(userAAddress, gravityAlgorithm, server).then(function(user) {
                userA = user;
                return userA.approve(userBAddress).then(function() {
                    var isActuallyApproved = users[userAAddress].approvals[userBAddress];
                    assert.equal(isActuallyApproved, true);
                });
            });
        });
    });

    describe('unapprove', function() {
        it('should remove the target user from the requester\'s approval list', function() {
            users = {
                'a': {approvals: {'b': true}, disapprovals: {}},
                'b': {approvals: {}, disapprovals: {}}
            };

            var userAAddress = 'a', userBAddress = 'b';
            var userA;
            return EtherCredClient.getUser(userAAddress, gravityAlgorithm, server).then(function(user) {
                userA = user;
                return userA.unapprove(userBAddress).then(function() {
                    var isActuallyApproved = users[userAAddress].approvals[userBAddress];
                    assert.notEqual(isActuallyApproved, true);
                });
            });
        });
    });

    describe('disapprove', function() {
        it('should add the target user to the requester\'s disapproval list', function() {
            users = {
                'a': {approvals: {}, disapprovals: {}},
                'b': {approvals: {}, disapprovals: {}}
            };

            var userAAddress = 'a', userBAddress = 'b';
            var userA;
            return EtherCredClient.getUser(userAAddress, gravityAlgorithm, server).then(function(user) {
                userA = user;
                return userA.disapprove(userBAddress).then(function() {
                    var isActuallyDisapproved = users[userAAddress].disapprovals[userBAddress];
                    assert.equal(isActuallyDisapproved, true);
                });
            });
        });
    });

    describe('undisapprove', function() {
        it('should remove the target user from the requester\'s disapproval list', function() {
            users = {
                'a': {approvals: {}, disapprovals: {'b': true}},
                'b': {approvals: {}, disapprovals: {}}
            };

            var userAAddress = 'a', userBAddress = 'b';
            var userA;
            return EtherCredClient.getUser(userAAddress, gravityAlgorithm, server).then(function(user) {
                userA = user;
                return userA.undisapprove(userBAddress).then(function() {
                    var isActuallyDisapproved = users[userAAddress].disapprovals[userBAddress];
                    assert.notEqual(isActuallyDisapproved, true);
                });
            });
        });
    });
});
{'fraction_non_alphanumeric': 0.14588474379445493, 'fraction_numerical': 0.0020322252866889243, 'mean_word_length': 2.1261343012704175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4999366', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1857, 'n_words': 407}