<commit_before>var test = require('tap').test;
var findComminuities = require('../');
var dot = require('ngraph.fromdot');

test('it finds communities', function(t) {
  var g = dot([
    'graph {',
    // first cluster:
    '{a b c d} -- {a b c d};',
    // second cluster
    '{e f g h} -- {e f g h};',
    // and a bridge between two:
    'a -- e',
    '}'
  ].join(' '));

  var results = findComminuities(g);

  // let's get communities of node `a`:
  var communitesOfA = results.nodes.a;
  // Since the graph is constructed this way, we anticipate only one community
  // for node a:
  t.equals(communitesOfA.length, 1, 'Only one community for node a');

  var mainCommunityOfA = communitesOfA[0];
  // now that we have main community of `a` we can confirm that `b`, `c` and `d`
  // are also there:
  t.ok(mainCommunityOfA.probability > 0.5, 'node `a` is certainly here');
  var allNodesInFirstCommunity = results.communities[mainCommunityOfA.name];
  t.equals(allNodesInFirstCommunity.length, 4, 'Four neighbours with a');
  t.ok(allNodesInFirstCommunity.indexOf('a') >= 0, 'neighbour is here');
  t.ok(allNodesInFirstCommunity.indexOf('b') >= 0, 'neighbour is here');
  t.ok(allNodesInFirstCommunity.indexOf('c') >= 0, 'neighbour is here');
  t.ok(allNodesInFirstCommunity.indexOf('d') >= 0, 'neighbour is here');

  // And do the same for communities of `e`
  var communitesOfE = results.nodes.e;
  // Since the graph is constructed this way, we anticipate only one community
  // for node a:
  t.equals(communitesOfE.length, 1, 'Only one community for node e');

  var mainCommunityOfE = communitesOfE[0];
  // now that we have main community of `a` we can confirm that `b`, `c` and `d`
  // are also there:
  t.ok(mainCommunityOfE.probability > 0.5, 'node `e` is certainly here');
  var allNodesInSecondCommunity = results.communities[mainCommunityOfA.name];
  t.equals(allNodesInSecondCommunity.length, 4, 'Four neighbours with e');
  t.ok(allNodesInSecondCommunity.indexOf('a') >= 0, 'neighbour is here');
  t.ok(allNodesInSecondCommunity.indexOf('b') >= 0, 'neighbour is here');
  t.ok(allNodesInSecondCommunity.indexOf('c') >= 0, 'neighbour is here');
  t.ok(allNodesInSecondCommunity.indexOf('d') >= 0, 'neighbour is here');

  t.end();
});<commit_msg>Updated second community check<commit_after>var test = require('tap').test;
var findComminuities = require('../');
var dot = require('ngraph.fromdot');

test('it finds communities', function(t) {
  var g = dot([
    'graph {',
    // first cluster:
    '{a b c d} -- {a b c d};',
    // second cluster
    '{e f g h} -- {e f g h};',
    // and a bridge between two:
    'a -- e',
    '}'
  ].join(' '));

  var results = findComminuities(g);

  // let's get communities of node `a`:
  var communitesOfA = results.nodes.a;
  // Since the graph is constructed this way, we anticipate only one community
  // for node a:
  t.equals(communitesOfA.length, 1, 'Only one community for node a');

  var mainCommunityOfA = communitesOfA[0];
  // now that we have main community of `a` we can confirm that `b`, `c` and `d`
  // are also there:
  t.ok(mainCommunityOfA.probability > 0.5, 'node `a` is certainly here');
  var allNodesInFirstCommunity = results.communities[mainCommunityOfA.name];
  t.equals(allNodesInFirstCommunity.length, 4, 'Four neighbours with a');
  t.ok(allNodesInFirstCommunity.indexOf('a') >= 0, 'neighbour is here');
  t.ok(allNodesInFirstCommunity.indexOf('b') >= 0, 'neighbour is here');
  t.ok(allNodesInFirstCommunity.indexOf('c') >= 0, 'neighbour is here');
  t.ok(allNodesInFirstCommunity.indexOf('d') >= 0, 'neighbour is here');

  // And do the same for communities of `e`
  var communitesOfE = results.nodes.e;
  // Since the graph is constructed this way, we anticipate only one community
  // for node a:
  t.equals(communitesOfE.length, 1, 'Only one community for node e');

  var mainCommunityOfE = communitesOfE[0];
  // now that we have main community of `a` we can confirm that `b`, `c` and `d`
  // are also there:
  t.ok(mainCommunityOfE.probability > 0.5, 'node `e` is certainly here');
  var allNodesInSecondCommunity = results.communities[mainCommunityOfE.name];
  t.equals(allNodesInSecondCommunity.length, 4, 'Four neighbours with e');
  t.ok(allNodesInSecondCommunity.indexOf('e') >= 0, 'neighbour is here');
  t.ok(allNodesInSecondCommunity.indexOf('f') >= 0, 'neighbour is here');
  t.ok(allNodesInSecondCommunity.indexOf('g') >= 0, 'neighbour is here');
  t.ok(allNodesInSecondCommunity.indexOf('h') >= 0, 'neighbour is here');

  t.end();
});
{'fraction_non_alphanumeric': 0.15154842960685264, 'fraction_numerical': 0.007906874588183616, 'mean_word_length': 3.9716157205240177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4574233', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1501, 'n_words': 465}