Perl x Open Food Facts Hackathon: Paris, France - May 24-25 Learn more

class TestCase::Module::Immutable::FloatList {
use Immutable::FloatList;
use Fn;
use Array;
# Fields
static method fields : int () {
{
my $list = Immutable::FloatList->new([(float)1, 2, 3]);
# length
my $length = $list->length;
unless ($length == 3) {
return 0;
}
}
return 1;
}
# Class methods
static method new : int () {
# new with array
{
my $list = Immutable::FloatList->new([(float)3, 5, Fn->FLOAT_MAX()]);
unless ($list->get(0) == 3) {
return 0;
}
unless ($list->get(1) == 5) {
return 0;
}
unless ($list->get(2) == Fn->FLOAT_MAX()) {
return 0;
}
my $length = $list->length;
unless ($length == 3) {
return 0;
}
}
# new with undef
{
my $list = Immutable::FloatList->new((float[])undef);
unless ($list->length == 0) {
return 0;
}
}
# new without argument
{
my $list = Immutable::FloatList->new;
unless ($list->length == 0) {
return 0;
}
}
# extra
{
{
my $list = Immutable::FloatList->new([(float)3]);
unless ($list->get(0) == 3) {
return 0;
}
}
{
my $list = Immutable::FloatList->new([(float)3, 4]);
unless ($list->get(0) == 3 && $list->get(1) == 4) {
return 0;
}
}
}
return 1;
}
static method new_len : int () {
{
my $list = Immutable::FloatList->new_len(32);
unless ($list->length == 32) {
return 0;
}
}
{
my $list = Immutable::FloatList->new_len(0);
unless ($list->length == 0) {
return 0;
}
}
{
eval { Immutable::FloatList->new_len(-1); };
unless (Fn->contains($@, "\$length must be greater than or equal to 0")) {
return 0;
}
}
return 1;
}
# Instance methods
static method get : int () {
{
my $list = Immutable::FloatList->new([(float)3, 5, Fn->FLOAT_MAX()]);
unless ($list->get(0) == 3) {
return 0;
}
unless ($list->get(0) isa float) {
return 0;
}
unless ($list->get(1) == 5) {
return 0;
}
unless ($list->get(2) == Fn->FLOAT_MAX()) {
return 0;
}
my $length = $list->length;
unless ($length == 3) {
return 0;
}
eval { $list->get(-1); };
unless (Fn->contains($@, "\$index must be greater than or equal to 0")) {
return 0;
}
eval { $list->get(3); };
unless (Fn->contains($@, "\$index must be less than the length of \$list")) {
return 0;
}
$@ = undef;
}
return 1;
}
static method to_array : int () {
{
my $list = Immutable::FloatList->new([(float)3, 5, Fn->FLOAT_MAX()]);
my $array = $list->to_array;
unless ($array isa float[]) {
return 0;
}
unless ($array->[0] == 3) {
return 0;
}
unless ($array->[1] == 5) {
return 0;
}
unless ($array->[2] == Fn->FLOAT_MAX()) {
return 0;
}
my $length = @$array;
unless ($length == 3) {
return 0;
}
}
return 1;
}
}