<commit_before>#!/usr/bin/perl
use Test::More tests => 19;

use DateTime;

use strict;
use warnings;

BEGIN { use_ok($_) for qw(Booking Agenda Resource) };

# Make a DateTime object with some defaults
sub datetime {
    my ($year, $month, $day, $hour, $minute) = @_;

    return DateTime->new(
        year   => $year   || '2008',
        month  => $month  || '4',
        day    => $day    || '14',
        hour   => $hour   || '0',
        minute => $minute || '0',
    );
}

# 17:00 - 18:59
my $b1 = Booking->new(datetime(2008, 4, 14, 17),
                      datetime(2008,4,14,18,59));
# 19:00 - 19:59
my $b2 = Booking->new(datetime(2008,4,14,19),
                      datetime(2008,4,14,19,59));
# 15:00 - 17:59
my $b3 = Booking->new(datetime(2008,4,14,15),
                      datetime(2008,4,14,17,59));
# 15:00 - 17:00
my $b4 = Booking->new(datetime(2008,4,14,15),
                      datetime(2008,4,14,17));
# 16:00 - 16:29
my $b5 = Booking->new(datetime(2008,4,14,16),
                      datetime(2008,4,14,16,29));

#to_xml booking test
ok($b1->to_xml() eq "<booking> <from>2008-04-14T17:00:00</from> <to>2008-04-14T18:59:00</to> </booking>", 'to_xml booking'); 	

# Booking Equality Tests
ok( $b1 != $b2, 'b1 != b2' );

# Booking Interlacing Tests
ok( !$b1->intersects($b2), 'b1 does not interlace b2' );
ok(  $b1->intersects($b3), 'b1 interlaces b3' );
ok(  $b1->intersects($b4), 'b1 interlaces b4' );
ok(  $b4->intersects($b5), 'b4 interlaces b5' );
ok(  $b5->intersects($b4), 'b5 interlaces b4' );

# Agenda Append Tests
my $ag = Agenda->new();

$ag->append($b1);
ok( $ag->contains($b1), 'b1 in ag' );

$ag->append($b2);
ok( $ag->size == 2 && $ag->contains($b2), 'b2 also in ag' );

$ag->append($b3);
ok( $ag->size == 2 && !$ag->contains($b3), 'b3 not in ag' );

$ag->append($b4);
ok( $ag->size == 2 && !$ag->contains($b4), 'b4 not in ag' );

# Agenda Remove Tests
ok( $ag->size == 2, 'ag has 2 slots' );

$ag->remove($b1);
ok( $ag->size == 1, 'ag has 1 slot' );

$ag->remove($b2);
ok( $ag->size == 0, 'ag has no slots' );

$ag->remove($b4);
ok( $ag->size == 0, 'remove non-existing b4 from ag' );

# Resource creation Tests
my $r = Resource->from_xml(
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <resource>
            <id>25</id>
            <description>aula chachipilongui</description>
            <granularitat>reserves diaries</granularitat><commit_msg>afegit test to_xml agenda<commit_after>#!/usr/bin/perl
use Test::More tests => 20;

use DateTime;

use strict;
use warnings;

BEGIN { use_ok($_) for qw(Booking Agenda Resource) };

# Make a DateTime object with some defaults
sub datetime {
    my ($year, $month, $day, $hour, $minute) = @_;

    return DateTime->new(
        year   => $year   || '2008',
        month  => $month  || '4',
        day    => $day    || '14',
        hour   => $hour   || '0',
        minute => $minute || '0',
    );
}

# 17:00 - 18:59
my $b1 = Booking->new(datetime(2008, 4, 14, 17),
                      datetime(2008,4,14,18,59));
# 19:00 - 19:59
my $b2 = Booking->new(datetime(2008,4,14,19),
                      datetime(2008,4,14,19,59));
# 15:00 - 17:59
my $b3 = Booking->new(datetime(2008,4,14,15),
                      datetime(2008,4,14,17,59));
# 15:00 - 17:00
my $b4 = Booking->new(datetime(2008,4,14,15),
                      datetime(2008,4,14,17));
# 16:00 - 16:29
my $b5 = Booking->new(datetime(2008,4,14,16),
                      datetime(2008,4,14,16,29));

#to_xml booking test
ok($b1->to_xml() eq "<booking> <from>2008-04-14T17:00:00</from> <to>2008-04-14T18:59:00</to> </booking>", 'to_xml booking'); 	

# Booking Equality Tests
ok( $b1 != $b2, 'b1 != b2' );

# Booking Interlacing Tests
ok( !$b1->intersects($b2), 'b1 does not interlace b2' );
ok(  $b1->intersects($b3), 'b1 interlaces b3' );
ok(  $b1->intersects($b4), 'b1 interlaces b4' );
ok(  $b4->intersects($b5), 'b4 interlaces b5' );
ok(  $b5->intersects($b4), 'b5 interlaces b4' );

# Agenda Append Tests
my $ag = Agenda->new();

$ag->append($b1);
ok( $ag->contains($b1), 'b1 in ag' );

#to_xml agenda test
ok($ag->to_xml() eq "<agenda><booking> <from>2008-04-14T17:00:00</from> <to>2008-04-14T18:59:00</to> </booking></agenda>", 'to_xml agenda');#


$ag->append($b2);
ok( $ag->size == 2 && $ag->contains($b2), 'b2 also in ag' );

$ag->append($b3);
ok( $ag->size == 2 && !$ag->contains($b3), 'b3 not in ag' );

$ag->append($b4);
ok( $ag->size == 2 && !$ag->contains($b4), 'b4 not in ag' );

# Agenda Remove Tests
ok( $ag->size == 2, 'ag has 2 slots' );

$ag->remove($b1);
ok( $ag->size == 1, 'ag has 1 slot' );

$ag->remove($b2);
ok( $ag->size == 0, 'ag has no slots' );

$ag->remove($b4);
ok( $ag->size == 0, 'remove non-existing b4 from ag' );

# Resource creation Tests
my $r = Resource->from_xml(
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
        <resource>
            <id>25</id>
            <description><NAME></description>
            <granularitat>reserves diaries</granularitat>
{'fraction_non_alphanumeric': 0.22076876635137854, 'fraction_numerical': 0.10102636345341115, 'mean_word_length': 3.0704340704340702, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 2, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6218606', 'n_tokens_mistral': 2266, 'n_tokens_neox': 1977, 'n_words': 452}