From 82bd4dd9a6d4059d741869be564f3f2a47c3ce2c Mon Sep 17 00:00:00 2001 From: Wilf Wilson Date: Sat, 5 Oct 2019 22:49:41 +0200 Subject: [PATCH] oper: reinstate 3-arg DigraphAddVertices --- doc/oper.xml | 2 ++ gap/oper.gd | 2 ++ gap/oper.gi | 13 +++++++++++++ tst/standard/oper.tst | 12 ++++++++++++ 4 files changed, 29 insertions(+) diff --git a/doc/oper.xml b/doc/oper.xml index b77ebcc74..35f20f02b 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -304,6 +304,8 @@ true Label="for a digraph and an integer"/> + A digraph. For a non-negative integer m, this operation returns a digraph diff --git a/gap/oper.gd b/gap/oper.gd index ab7815597..2e2623b82 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -13,6 +13,8 @@ DeclareOperation("DigraphAddVertex", [IsDigraph]); DeclareOperation("DigraphAddVertex", [IsDigraph, IsObject]); DeclareOperation("DigraphAddVertices", [IsDigraph, IsInt]); DeclareOperation("DigraphAddVertices", [IsDigraph, IsList]); +# 3-arg version of DigraphAddVertices is included for backwards compatibility. +DeclareOperation("DigraphAddVertices", [IsDigraph, IsInt, IsList]); DeclareOperation("DigraphRemoveVertex", [IsDigraph, IsPosInt]); DeclareOperation("DigraphRemoveVertices", [IsDigraph, IsList]); diff --git a/gap/oper.gi b/gap/oper.gi index 5d5019178..114668ec8 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -81,6 +81,19 @@ InstallMethod(DigraphAddVertices, "for an immutable digraph and an integer", [IsImmutableDigraph, IsInt], {D, m} -> MakeImmutable(DigraphAddVertices(DigraphMutableCopy(D), m))); +# Included for backwards compatibility, even though the 2nd arg is redundant. +# See https://github.com/gap-packages/Digraphs/issues/264 +# This is deliberately kept undocumented. +InstallMethod(DigraphAddVertices, "for a digraph, an integer, and a list", +[IsDigraph, IsInt, IsList], +function(D, m, labels) + if m <> Length(labels) then + ErrorNoReturn("the list (3rd argument) must have length ", + "(2nd argument),"); + fi; + return DigraphAddVertices(D, labels); +end); + InstallMethod(DigraphRemoveVertex, "for a mutable digraph by out-neighbours and positive integer", [IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt], diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index bb3796162..986ecfc7c 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -630,6 +630,18 @@ false gap> gr2 = gr3; true +# DigraphAddVertices (redundant three-argument version) +gap> D := Digraph([[1]]); + +gap> DigraphVertexLabels(D); +[ 1 ] +gap> DigraphAddVertices(D, 2, [fail]); +Error, the list (3rd argument) must have length (2nd argument), +gap> D := DigraphAddVertices(D, 2, [fail, true]); + +gap> DigraphVertexLabels(D); +[ 1, fail, true ] + # DigraphAddVertex gap> gr := CompleteDigraph(1);