Skip to content

Commit

Permalink
digraph: allow rationals as 2nd arg of RandomDigraph
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Jan 11, 2019
1 parent 4443b58 commit 1f8685a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions gap/digraph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ DeclareOperation("AsDigraph", [IsTransformation, IsInt]);
DeclareOperation("DigraphCopy", [IsDigraph]);

DeclareOperation("RandomDigraph", [IsPosInt]);
DeclareOperation("RandomDigraph", [IsPosInt, IsRat]);
DeclareOperation("RandomDigraph", [IsPosInt, IsFloat]);
DeclareOperation("RandomMultiDigraph", [IsPosInt]);
DeclareOperation("RandomMultiDigraph", [IsPosInt, IsPosInt]);
Expand Down
6 changes: 6 additions & 0 deletions gap/digraph.gi
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,12 @@ function(n)
return RandomDigraph(n, Float(Random([0 .. 10000])) / 10000);
end);

InstallMethod(RandomDigraph, "for a pos int and a rational",
[IsPosInt, IsRat],
function(n, p)
return RandomDigraph(n, Float(p));
end);

InstallMethod(RandomDigraph, "for a pos int and a float",
[IsPosInt, IsFloat],
function(n, p)
Expand Down
4 changes: 2 additions & 2 deletions tst/standard/digraph.tst
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,14 @@ gap> RandomDigraph("a");
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `RandomDigraph' on 1 arguments
gap> RandomDigraph(4, 0);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `RandomDigraph' on 2 arguments
<digraph with 4 vertices, 0 edges>
gap> RandomDigraph(10, 1.01);
Error, Digraphs: RandomDigraph: usage,
the second argument <p> must be a float between 0 and 1,
gap> RandomDigraph(10, -0.01);
Error, Digraphs: RandomDigraph: usage,
the second argument <p> must be a float between 0 and 1,
gap> RandomDigraph(10, 1 / 10);;
# RandomMultiDigraph
gap> DigraphNrVertices(RandomMultiDigraph(100));
Expand Down

0 comments on commit 1f8685a

Please sign in to comment.