elm-community / graph

Functional Graph Library in Elm.

Home Page:http://package.elm-lang.org/packages/elm-community/graph/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent handling of edges involving non-existent nodes

DavidDTA opened this issue · comments

Consider the following program:

module Main exposing (..)

import Html exposing (Html, text)
import Graph

x : Int
x = 0
y : Int
y = 0

graph : Graph.Graph () ()
graph =
    Graph.fromNodesAndEdges
        [{id = 0, label = ()}]
        [{from = x, to = y, label = ()}]

main : Html a
main =
    text (Graph.toString graph)

It produces the following output, which is expected:
Graph.fromNodesAndEdges [{ id = 0, label = () }] [{ to = 0, from = 0, label = () }]

However, changing the values of x and y to 0 and 1 gives:
Graph.fromNodesAndEdges [{ id = 0, label = () }] [{ to = 1, from = 0, label = () }]
while changing the values of x and y to 1 and 0 gives:
Graph.fromNodesAndEdges [{ id = 0, label = () }] []

The documentation does not describe what should happen if a node id for a non-existent node is provided for an edge, so this is not a bug in the strictest sense, but the fact that these last two scenarios provide different results strikes me as odd. I would expect that both would produce the last output.

That's indeed surprising. I'd also expect the edge set for the first case to be empty.

Published as v3.0.1.

Not that the library code changed, but I fixed and updated the test suite and bumped to v3.0.2 in order to make CI green again.