<commit_before>var assert = require("../assert"),
    Digraph = require("../..").Digraph,
    floydWarshall = require("../..").alg.floydWarshall,
    allShortestPaths = require("./allShortestPaths-test");

describe("alg.floydWarshall", function() {
  allShortestPaths(floydWarshall);

  it("handles negative weights", function() {
    var g = new Digraph();
    g.addNode(1);
    g.addNode(2);
    g.addNode(3);
    g.addNode(4);
    g.addEdge(null, 1, 2, 1);
    g.addEdge(null, 1, 3, -2);
    g.addEdge(null, 2, 4, 3);
    g.addEdge(null, 3, 4, 3);

    function w(e) { return g.edge(e); }

    assert.deepEqual(floydWarshall(g, w), {
      1: {
        1: { distance: 0 },
        2: { distance: 1, predecessor: 1 },
        3: { distance: -2, predecessor: 1 },
        4: { distance: 1, predecessor: 3 }
      },
      2: {
        1: { distance: Number.POSITIVE_INFINITY },
        2: { distance: 0 },
        3: { distance: Number.POSITIVE_INFINITY },
        4: { distance: 3, predecessor: 2 }
      },
      3: {
        1: { distance: Number.POSITIVE_INFINITY },
        2: { distance: Number.POSITIVE_INFINITY },
        3: { distance: 0 },
        4: { distance: 3, predecessor: 3 }
      },
      4: {
        1: { distance: Number.POSITIVE_INFINITY },
        2: { distance: Number.POSITIVE_INFINITY },
        3: { distance: Number.POSITIVE_INFINITY },
        4: { distance: 0 }
      }
    });
  });

  it("does include negative weight self edges", function() {
    var g = new Digraph();
    g.addNode(1);
    g.addEdge(null, 1, 1, -1);

    function w(e) { return g.edge(e); }

    assert.deepEqual(alg(g), { 1: { 1: { distance: -2, predecessor: 1 } }});
  });
});<commit_msg>Fix new Floyd-Warshall test case<commit_after>var assert = require("../assert"),
    Digraph = require("../..").Digraph,
    floydWarshall = require("../..").alg.floydWarshall,
    allShortestPaths = require("./allShortestPaths-test");

describe("alg.floydWarshall", function() {
  allShortestPaths(floydWarshall);

  it("handles negative weights", function() {
    var g = new Digraph();
    g.addNode(1);
    g.addNode(2);
    g.addNode(3);
    g.addNode(4);
    g.addEdge(null, 1, 2, 1);
    g.addEdge(null, 1, 3, -2);
    g.addEdge(null, 2, 4, 3);
    g.addEdge(null, 3, 4, 3);

    function w(e) { return g.edge(e); }

    assert.deepEqual(floydWarshall(g, w), {
      1: {
        1: { distance: 0 },
        2: { distance: 1, predecessor: 1 },
        3: { distance: -2, predecessor: 1 },
        4: { distance: 1, predecessor: 3 }
      },
      2: {
        1: { distance: Number.POSITIVE_INFINITY },
        2: { distance: 0 },
        3: { distance: Number.POSITIVE_INFINITY },
        4: { distance: 3, predecessor: 2 }
      },
      3: {
        1: { distance: Number.POSITIVE_INFINITY },
        2: { distance: Number.POSITIVE_INFINITY },
        3: { distance: 0 },
        4: { distance: 3, predecessor: 3 }
      },
      4: {
        1: { distance: Number.POSITIVE_INFINITY },
        2: { distance: Number.POSITIVE_INFINITY },
        3: { distance: Number.POSITIVE_INFINITY },
        4: { distance: 0 }
      }
    });
  });

  it("does include negative weight self edges", function() {
    var g = new Digraph();
    g.addNode(1);
    g.addEdge(null, 1, 1, -1);

    function w(e) { return g.edge(e); }

    assert.deepEqual(floydWarshall(g, w), {
      1: {
        1: { distance: -2, predecessor: 1 }
      }
    });
  });
});
{'fraction_non_alphanumeric': 0.1741654571843251, 'fraction_numerical': 0.03367198838896952, 'mean_word_length': 2.2448210922787193, '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': '4867984', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1218, 'n_words': 275}