package PS::MOPS::DC::Test::Unit::Detections;

## @class PS::MOPS::DC::Test::Unit::Detections
#
# @par DESCRIPTION
# Unit tests for PS::MOPS::DC::Detection module. This module serves as an
# interface to the lower-level testing code. The functions in this module
# correspond to the tests called by the testing system. All tests are intended
# to return 1 for success or 0 for failure.

use strict;
use warnings;
our $VERSION = sprintf "%d", q$Revision: $ =~ /(\d+)/g;

use PS::MOPS::DC::Test::Detections;
use PS::MOPS::DC::Test::Unit::Globals qw($g_TEST_INSTANCE
                                         $g_NUM_TEST_DETECTIONS
                                         $g_FIELDS
                                         $g_DETECTIONS);

sub make_test_detections__simple
{
    $g_DETECTIONS=PS::MOPS::DC::Test::Detections->new(instance=>$g_TEST_INSTANCE,
                                                      num_detections=>$g_NUM_TEST_DETECTIONS);
    return 1 if($g_DETECTIONS); # @todo Add test for correct Detections object.
    return 0;
}

sub test_addToField
{
    my $success=0;
    for(my $i=0;$i<$g_NUM_TEST_DETECTIONS;$i++){
        # Add all to one field for now.
        $success=$g_DETECTIONS->test_addToField(index=>$i,
                                                field=>$g_FIELDS->getField(index=>3));
    }
    return $success;
}

sub test_modcd_retrieve
{
    my $success=1;
    my $result;
    # Retrieve all detections created.
    for(my $i=0;$i<$g_NUM_TEST_DETECTIONS;$i++){
        # Get detections from field field_id.
        $result=$g_DETECTIONS->test_modcd_retrieve(index=>$i);
        if(!$result){$success=0};
    }
    return $success;
}

sub test_modcd_retrieve__by_field
{
    my $success=1;
    my $result;
    # Retrieve all detections created.
    for(my $i=0;$i<$g_NUM_TEST_DETECTIONS;$i++){
        # Get detections from field having field ID field_id.
        $result=$g_DETECTIONS->test_modcd_retrieve__by_field(field_id => $g_FIELDS -> getField(index=>3)->{fieldId} );
        if(!$result){$success=0};
    }
    return $success;
}

sub test_modcd_delete
{
    my $success=1;
    my $result;

    for(my $i=0;$i<$g_NUM_TEST_DETECTIONS;$i++){
        $result=$g_DETECTIONS->test_modcd_delete(detection_id => $g_DETECTIONS->getDetection(index=>$i)->{detId} );

        if(!$result) {$success=0};
    }

    # Double check that the table is empty.
    if(!($g_DETECTIONS->getTable()->isEmpty())) {$success=0;}

    return $success;
}

sub test_modcd_classifyDetections__clean
{
    return($g_DETECTIONS->test_modcd_classifyDetections__clean()==1);
}

sub test_modcd_classifyDetections__bad
{
    return($g_DETECTIONS->test_modcd_classifyDetections__bad()==1);
}

sub test_modcd_classifyDetections__mixed
{
    return($g_DETECTIONS->test_modcd_classifyDetections__mixed()==1);
}

sub test_modcd_classifyDetections__nonsynth
{
    return($g_DETECTIONS->test_modcd_classifyDetections__nonsynth()==1);
}

1;
