class TestCase::Remainder {
use Fn;
#
# Spec tests
#
static method remainder_byte_byte : int () {
my $total = (byte)7 % (byte)3;
unless ($total == 1) {
return 0;
}
unless ($total isa int) {
return 0;
}
return 1;
}
static method remainder_short_short : int () {
my $total = (short)10 % (short)2;
unless ($total == 0) {
return 0;
}
unless ($total isa int) {
return 0;
}
return 1;
}
static method remainder_int_byte : int () {
my $total = 12 % (byte)5;
unless ($total == 2) {
return 0;
}
unless ($total isa int) {
return 0;
}
return 1;
}
static method remainder_int_short : int () {
my $total = 7 % (short)3;
unless ($total == 1) {
return 0;
}
unless ($total isa int) {
return 0;
}
return 1;
}
static method remainder_byte_int : int () {
my $total = (byte)-5 % 3;
unless ($total == -2) {
return 0;
}
unless ($total isa int) {
return 0;
}
return 1;
}
static method remainder_short_int : int () {
my $total = (short)5 % -3;
unless ($total == 2) {
return 0;
}
unless ($total isa int) {
return 0;
}
return 1;
}
static method remainder_int_int : int () {
my $total1 = 1000000000 % 2;
unless ($total1 == 0) {
return 0;
}
unless ($total1 isa int) {
return 0;
}
return 1;
}
static method remainder_long_long : int () {
my $total1 = 100000000001L % 2L;
unless ($total1 == 1) {
return 0;
}
unless ($total1 isa long) {
return 0;
}
return 1;
}
static method remainder_unsigned_int : int () {
{
my $x = Fn->UINT32_MAX;
# 0 = -1 % 3
my $ret_rem = $x % 3;
# 1431655765 = 4,294,967,295 remui 3
my $ret_remui = $x remui 3;
unless ($ret_remui isa int) {
return 0;
}
unless ($ret_rem == -1) {
return 0;
}
unless ($ret_remui == 0) {
return 0;
}
}
return 1;
}
static method remainder_unsigned_long : int () {
{
my $x = Fn->UINT64_MAX;
# 0 = -1 % 3
my $ret_rem = $x % 3L;
# 6,148,914,691,236,517,205 = 18,446,744,073,709,551,615 remul 3
my $ret_remul = $x remul 3L;
unless ($ret_remul isa long) {
return 0;
}
unless ($ret_rem == -1) {
return 0;
}
unless ($ret_remul == 0) {
return 0;
}
}
return 1;
}
#
# Optional tests
#
static method remainder : int () {
my $num1 = (byte)((byte)5 % (byte)3);
my $num2 = (byte)((byte)-3 % (byte)5);
my $num3 = (short)((int)(short)5 % (int)(short)3);
my $num4 = (short)((int)(short)-3 % (int)(short)5);
my $num5 = 5 % 3;
my $num6 = -3 % 5;
my $num7 = 5L % 3L;
my $num8 = -3L % 5L;
if ($num1 == 2) {
if ($num2 == -3) {
if ($num3 == 2) {
if ($num4 == -3) {
if ($num5 == 2) {
if ($num6 == -3) {
if ($num7 == 2L) {
if ($num8 == -3L) {
return 1;
}
}
}
}
}
}
}
}
return 0;
}
}