### ----------------------------------------------------
### -- Graph
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/06-weak-connectivity.rakutest
### ----------------------------------------------------
use v6.d;
use Test;


#use lib <. lib>;

use Graph;
use Graph::Path;
use Graph::Petersen;

## 1
my $g1 = Graph.new([
    %('from' => '1', 'to' => '2', 'weight' => 1),
    %('from' => '2', 'to' => '3', 'weight' => 1),
    %('from' => '3', 'to' => '1', 'weight' => 1)], :directed);

is $g1.is-weakly-connected, True;

## 2
my $g2 = Graph.new(<1 2 3 4>,
        [
            %('from' => '1', 'to' => '2', 'weight' => 1),
            %('from' => '1', 'to' => '3', 'weight' => 1),
            %('from' => '2', 'to' => '3', 'weight' => 1)
        ], :directed);

is $g2.is-weakly-connected, False;

## 3
my $g3 = Graph.new([
    %('from' => '1', 'to' => '2', 'weight' => 1),
    %('from' => '1', 'to' => '3', 'weight' => 1),
    %('from' => '2', 'to' => '3', 'weight' => 1)
]);

is $g3.is-weakly-connected, True;

## 4
my $g4 = Graph.new([
    %('from' => '1', 'to' => '2', 'weight' => 1),
    %('from' => '2', 'to' => '3', 'weight' => 1),
    %('from' => '3', 'to' => '1', 'weight' => 1),
    %('from' => '3', 'to' => '4', 'weight' => 1)
], :directed);

is $g4.is-weakly-connected, True;

## 5
my $g5 = Graph.new([
    %('from' => '1', 'to' => '2', 'weight' => 1),
    %('from' => '1', 'to' => '3', 'weight' => 1),
    %('from' => '1', 'to' => '4', 'weight' => 1)
]);

is $g5.is-weakly-connected, True;

## 6
is Graph::Path.new((^10)».Str).is-weakly-connected, True;

## 7
is Graph::Petersen.new.is-weakly-connected, True;


## 8
my $g8 = Graph.new([
    %('from' => '1', 'to' => '2', 'weight' => 1),
    %('from' => '2', 'to' => '3', 'weight' => 1),
    %('from' => '3', 'to' => '1', 'weight' => 1),
    %('from' => '3', 'to' => '4', 'weight' => 1),
    %('from' => '3', 'to' => '5', 'weight' => 1),
    %('from' => '4', 'to' => '5', 'weight' => 1)
], :directed);

#say $g8.wl;
#say "res: ", $g8.weakly-connected-components;
isa-ok $g8.weakly-connected-components, Positional;

## 9
my $g9 = Graph.new((1..9)>>.Str,
        [
            %('from' => '2', 'to' => '6', 'weight' => 1), %('from' => '3', 'to' => '7', 'weight' => 1),
            %('from' => '3', 'to' => '10', 'weight' => 1), %('from' => '4', 'to' => '7', 'weight' => 1),
            %('from' => '4', 'to' => '8', 'weight' => 1), %('from' => '4', 'to' => '10', 'weight' => 1),
            %('from' => '5', 'to' => '6', 'weight' => 1), %('from' => '9', 'to' => '10', 'weight' => 1)]);
#say $g9.wl;
is-deeply $g9.weakly-connected-components>>.elems, (6, 3, 1);

done-testing;


