#!/bin/env perl

# This is translation of t/1.t from PS::MOPS::Lib.

use strict;
use Benchmark ':hireswallclock';

# Define variables for benchmarking.
our $g_start;
our $g_end;
our $g_diff;

# Testing environment.
use Test::More tests => 4; # Perl testing framework.
use PS::MOPS::DC::Orbit;
use PS::MOPS::Test::Instance;
use PS::MOPS::Lib qw(:all);

# Make the PS-MOPS Instance available through $g_inst and
# the Test Instance available through $g_test_inst.
#our $g_test_inst=PS::MOPS::Test::Instance->new();
#our $g_inst=$g_test_inst->getPSMOPSInstance();

sub test_dang1 {
    mopslib_dang(1, 5) == -4
}

sub test_dang2 {
    mopslib_dang(1, 5) == -4
    and mopslib_dang(5, 1) == 4
    and mopslib_dang(-3, -5) == 2
    and mopslib_dang(355, 10) == -15
    and mopslib_dang(10, 355) == 15
    and mopslib_dang(355, -10) == 5
    and mopslib_dang(-10, 355) == -5
    and mopslib_dang(359, -2) == 1
}

sub test_dang3 {
    mopslib_dang(-3, -5) == 2
    and mopslib_dang(355 + 360, 10) == -15
    and mopslib_dang(355 + 720, 10) == -15
    and mopslib_dang(10 - 360, 355) == 15
    and mopslib_dang(10 - 720, 355) == 15
    and mopslib_dang(355 + 360, -10 - 720) == 5
    and mopslib_dang(720, -360) == 0
}


sub test_dang4 {
    my ($a1, $a2) = (720, -360);
    mopslib_dang($a1, $a2) == 0 and $a1 == 720 and $a2 == -360;
}


# Run the tests.
my $test_module_name = 'PS-MOPS-Lib';

foreach my $subtest_def (
    ['test_dang1', 'basic'],
    ['test_dang2', '0-360 crossings'],
    ['test_dang3', 'large angles'],
    ['test_dang4', q{don't modify args}],
)
{
    my ($fn, $msg) = @{$subtest_def};
    $g_start = new Benchmark;
    ok(eval $fn, $msg);
    $g_end = new Benchmark;
    print "time: ${test_module_name}->${fn}: " . timestr(timediff($g_end, $g_start), 'all') . "\n";
}
