function digraph_arc_test ( )

%*****************************************************************************80
%
%% digraph_arc_test() tests digraph_arc().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 April 2026
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../digraph_arc' );

  timestamp ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_arc_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test digraph_arc(), which implements digraph algorithms\n' );
  fprintf ( 1, '  using an arc list representation.\n' );

  digraph_adj_to_arc_test ( );
  digraph_arc_degree_test ( );
  digraph_arc_is_eulerian_test ( );
  digraph_arc_to_adj_test ( );
  digraph_arc_to_star_test ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_arc_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../digraph_arc' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 November 2022
%
%  Author:
%
%    John Burkardt
%
  t = now ( );
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end
function digraph_adj_to_arc_test ( )

%*****************************************************************************80
%
%% digraph_adj_to_arc_test() tests digraph_adj_to_arc();
%
%    1->---2-->---3
%    |     |      |
%    A     V      V
%    |     |      |
%    6--<--5--<---4
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 April 2026
%
%  Author:
%
%    John Burkardt
%
  node_num = 6;
  edge_num = 6;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_adj_to_arc_test():\n' );
  fprintf ( 1, '  digraph_adj_to_arc() converts a digraph in\n' );
  fprintf ( 1, '  adjacency form to arc list form;\n' );

  A = zeros ( node_num, node_num );

  A(1,2) = 1;
  A(2,3) = 1;
  A(3,4) = 1;
  A(4,5) = 1;
  A(5,6) = 1;
  A(6,2) = 1;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph adjacency matrix:\n' );
  disp ( A );

  L = digraph_adj_to_arc ( A );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph edge list:\n' );
  disp ( L )

  return
end
function digraph_arc_degree_test ( )

%*****************************************************************************80
%
%% digraph_arc_degree_test() tests digraph_arc_degree().
%
%  5--2--10--1--3--6
%         |  |  | /
%         8  |  9
%         |  |
%         4--7
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 April 2026
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_arc_degree_test():\n' );
  fprintf ( 1, '  digraph_arc_degree() computes the degree of the nodes;\n' );

  L = [ ...
    1, 1,  1, 2,  2, 3, 3, 4, 4, 6,  8; ...
    3, 7, 10, 5, 10, 6, 9, 7, 8, 9, 10 ]';

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph arc list:\n' );
  disp (  L );

  [ indegree, outdegree ] = digraph_arc_degree ( L );

  D = [ indegree; outdegree ]';
  fprintf ( 1, '  The in- and out- degrees:\n' );
  disp ( D );

  return
end
function digraph_arc_is_eulerian_test ( )

%*****************************************************************************80
%
%% digraph_arc_is_eulerian_test() tests digraph_arc_is_eulerian().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 April 2026
%
%  Author:
%
%    John Burkardt
%
  L = [ ...
    1, 3, 1, 5, 2, 4, 2, 4, 3, 5; ...
    2, 1, 4, 1, 3, 2, 5, 3, 5, 4 ]';

  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_arc_is_eulerian_test()\n' );
  fprintf ( 1, '  digraph_arc_is_eulerian() checks if a digraph\n' );
  fprintf ( 1, '  has (at least one) Euler circuit.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph arc list:\n' );
  disp ( L );

  answer = digraph_arc_is_eulerian ( L );

  if ( answer == 0 )
    fprintf ( 1, '  The digraph is NOT eulerian.\n' );
  elseif ( answer == 1 )
    fprintf ( 1, '  The digraph has an eulerian path,\n' );
    fprintf ( 1, '  but not an eulerian circuit.\n' );
  elseif ( answer == 2 )
    fprintf ( 1, '  The digraph has an eulerian circuit.\n' );
  end

  return
end
function digraph_arc_to_adj_test ( )

%*****************************************************************************80
%
%% digraph_arc_to_adj_test() tests digraph_arc_to_adj().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 April 2026
%
%  Author:
%
%    John Burkardt
%
  edge_num = 16;
  node_num = 20;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_arc_to_adj_test():\n' );
  fprintf ( 1, '  digraph_arc_to_adj() converts an arclist\n' );
  fprintf ( 1, '  digraph to an adjacency digraph.\n' );

  L = digraph_arc_example_cycler ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph arc list\n:' );
  disp ( L );

  A = digraph_arc_to_adj ( L );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph adjacency matrix:\n' );
  disp ( A );

  return
end
function digraph_arc_to_star_test ( )

%*****************************************************************************80
%
%% digraph_arc_to_star_test() tests digraph_arc_to_star().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 April 2026
%
%  Author:
%
%    John Burkardt
%
  edge_num = 16;
  node_num = 20;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'digraph_arc_to_star_test():\n' );
  fprintf ( 1, '  digraph_arc_to_star() converts an arclist\n' );
  fprintf ( 1, '  digraph to a forward star representation.\n' );

  L = digraph_arc_example_cycler ( );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph arc list:\n' );
  disp ( L );

  [ arcfir, fwdarc ] = digraph_arc_to_star ( L );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  The digraph forward star representation:\n' );
  fprintf ( 1, '  arcfir():\n' );
  disp ( arcfir );
  fprintf ( 1, '  fwdarc():\n' );
  disp ( fwdarc );

  return
end
