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

## @class PS::MOPS::DC::Test::Unit::Tracklets
#
# @par DESCRIPTION
# Unit tests for PS::MOPS::DC::Tracklet 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::Tracklets;
use PS::MOPS::DC::Test::Unit::Globals qw($g_TEST_INSTANCE
                                         $g_NUM_TEST_TRACKLETS
                                         $g_NUM_TEST_DETECTIONS
                                         $g_TRACKLETS
                                         $g_DETECTIONS);

sub test_insert
{
    return($g_TRACKLETS->insertTracklets()==1);
}

sub make_test_tracklets__simple
{
    $g_TRACKLETS=PS::MOPS::DC::Test::Tracklets->new(instance=>$g_TEST_INSTANCE,
                                                    num_tracklets=>$g_NUM_TEST_TRACKLETS);
    return 1 if($g_TRACKLETS); # @todo Add test for correct Tracklets object.
    return 0;
}

# @todo Rename this function.
sub make_test_tracklets
{
    my $success=1;
    # Make detection array for Tracklets.
    my @detections=();

    # Get detections from test Detections object.
    for(my $i=0;$i<$g_NUM_TEST_DETECTIONS;$i++){
        push(@detections,$g_DETECTIONS->getDetection(index=>$i));
    }
    $g_TRACKLETS->setDetections(detections=>\@detections);
    $g_TRACKLETS->makeTestTracklets();
    return $success;
}

sub test_modct_retrieve__trackletId
{
    return($g_TRACKLETS->retrieveTracklets_TrackletID()==1);
}

sub test_modct_retrieve__detectionId
{
    return($g_TRACKLETS->retrieveTracklets_DetectionID(detection_id=>1,
                                                       tracklet_id=>1)
           ==1);
}

sub test_modct_retrieve__derivedobjectId
{
    return($g_TRACKLETS->retrieveTracklets_DerivedObjectID(derivedobjectId=>'')==1);
}

sub test_modct_selectTracklets__MJD
{
    return($g_TRACKLETS->selectTracklets_MJD(mjd=>54000)==1);
}

sub test_modct_selectTracklets__MJD1
{
    return($g_TRACKLETS->selectTracklets_MJD1(mjd1=>54000)==1);
}

sub test_modct_selectTrackletIdsByFieldId
{
    my $result=$g_TRACKLETS->selectTrackletIdsByFieldId(field_id=>4);
    my $cnt=0;
    if($result){
        $cnt=scalar(@{$result});
    }
    return ($cnt==$g_NUM_TEST_DETECTIONS);
}

sub test_modct_selectDetracklets__MJD
{
    return($g_TRACKLETS->selectDetracklets_MJD(mjd=>54000)==$g_NUM_TEST_DETECTIONS);
}

sub test_modct_selectDetracklets__MJD1
{
    return($g_TRACKLETS->selectDetracklets_MJD1(mjd1=>54000)==$g_NUM_TEST_DETECTIONS);
}

# All test detections are currently used to form the single test tracklet.
sub test_modct_selectDetracklets__fieldId
{
    return($g_TRACKLETS->selectDetracklets_fieldId(field_id=>4)==$g_NUM_TEST_DETECTIONS);
}

sub test_modct_selectDetracklets__trackletId
{
    return($g_TRACKLETS->selectDetracklets_trackletId(tracklet_id=>1)==$g_NUM_TEST_DETECTIONS);
}

sub test_modct_selectDetracklets__target_field_id
{
    return($g_TRACKLETS->selectDetracklets_target_field_id(target_field_id=>4)==$g_NUM_TEST_DETECTIONS);
}

sub test_modct_getLastFieldId
{
    return($g_TRACKLETS->getLastFieldId()==4);
}

sub test_status__update
{
    return($g_TRACKLETS->updateStatus()==1);
}

1;
