<commit_before>use lib 't';
use strict;

BEGIN { $| = 1;
	use Test ;
	plan tests => 12
}

use MultiTestDB;
use Bio::EnsEMBL::MiscSet;
use TestUtils qw(debug test_getter_setter);

our $verbose = 0; #set to 1 to turn on debug printouts


my $multi_db = MultiTestDB->new;
my $db = $multi_db->get_DBAdaptor('core');


#
# Test constructor
#

my $msa = $db->get_MiscSetAdaptor();


ok($msa && ref($msa) && $msa->isa('Bio::EnsEMBL::DBSQL::MiscSetAdaptor'));


#
# Test fetch_all
#

ok(@{$msa->fetch_all()} == 4);

#
# Test fetch_by_dbID
#

my $ms = $msa->fetch_by_dbID(1);

ok($ms->dbID(1));
ok($ms->code() eq 'ntctgs');
ok($ms->name() eq 'NT contigs');
ok($ms->description eq '');
ok($ms->longest_feature == 7e7);

#
# Test fetch_by_code
#

$ms = $msa->fetch_by_code('cloneset');
ok($ms->dbID() == 4);
ok($ms->code() eq 'cloneset');
ok($ms->name() eq '1Mb cloneset');
ok($ms->description eq '');
ok($ms->longest_feature == 6e6);<commit_msg>added tests related to storing of MiscSets<commit_after>use lib 't';
use strict;

BEGIN { $| = 1;
	use Test ;
	plan tests => 21
}

use MultiTestDB;
use Bio::EnsEMBL::MiscSet;
use TestUtils qw(debug test_getter_setter);

our $verbose = 0; #set to 1 to turn on debug printouts


my $multi_db = MultiTestDB->new;
my $db = $multi_db->get_DBAdaptor('core');


#
# Test constructor
#

my $msa = $db->get_MiscSetAdaptor();


ok($msa && ref($msa) && $msa->isa('Bio::EnsEMBL::DBSQL::MiscSetAdaptor'));


#
# Test fetch_all
#

ok(@{$msa->fetch_all()} == 4);

#
# Test fetch_by_dbID
#

my $ms = $msa->fetch_by_dbID(1);

ok($ms->dbID(1));
ok($ms->code() eq 'ntctgs');
ok($ms->name() eq 'NT contigs');
ok($ms->description eq '');
ok($ms->longest_feature == 7e7);

#
# Test fetch_by_code
#

$ms = $msa->fetch_by_code('cloneset');
ok($ms->dbID() == 4);
ok($ms->code() eq 'cloneset');
ok($ms->name() eq '1Mb cloneset');
ok($ms->description eq '');
ok($ms->longest_feature == 6e6);


#
# Test store method
#

$multi_db->hide('core', 'misc_set');

my $misc_set = Bio::EnsEMBL::MiscSet->new
  (-CODE => 'code',
   -NAME => 'name',
   -DESCRIPTION => 'description',
   -LONGEST_FEATURE => 1000);


$msa->store($misc_set);

ok($misc_set->dbID());
ok($misc_set->adaptor() == $msa);

my $count = $db->db_handle->selectall_arrayref
  ("SELECT COUNT(*) FROM misc_set WHERE code = 'code'")->[0]->[0];

ok($count == 1);

# flush and reload cache...
$msa->fetch_all();

$misc_set = $msa->fetch_by_code('code');
ok($misc_set->code() eq 'code');
ok($misc_set->name() eq 'name');
ok($misc_set->description eq 'description');
ok($misc_set->longest_feature == 1000);


# try to store a misc_set with the same code
my $misc_set = Bio::EnsEMBL::MiscSet->new
  (-code => 'code',
   -name => 'name',
   -description => 'description',
   -longest_feature => 'longest_feature');

$msa->store($misc_set);

ok($misc_set->dbID && $misc_set->adaptor);

$count = $db->db_handle->selectall_arrayref
  ("SELECT COUNT(*) FROM misc_set WHERE code = 'code'")->[0]->[0];
ok($count == 1);

$multi_db->restore('core', 'misc_set');
{'fraction_non_alphanumeric': 0.22369731164951875, 'fraction_numerical': 0.013939595087952207, 'mean_word_length': 5.052208835341365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4196912', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1244, 'n_words': 257}