142 lines
4.2 KiB
RPMSpec
142 lines
4.2 KiB
RPMSpec
#
|
|
# spec file for package perl-Set-CrossProduct
|
|
#
|
|
# Copyright (c) 2025 SUSE LLC
|
|
#
|
|
# All modifications and additions to the file contributed by third parties
|
|
# remain the property of their copyright owners, unless otherwise agreed
|
|
# upon. The license for this file, and modifications and additions to the
|
|
# file, is the same license as for the pristine package itself (unless the
|
|
# license for the pristine package is not an Open Source License, in which
|
|
# case the license is the MIT License). An "Open Source License" is a
|
|
# license that conforms to the Open Source Definition (Version 1.9)
|
|
# published by the Open Source Initiative.
|
|
|
|
# Please submit bugfixes or comments via https://bugs.opensuse.org/
|
|
#
|
|
|
|
|
|
%define cpan_name Set-CrossProduct
|
|
Name: perl-Set-CrossProduct
|
|
Version: 3.1.0
|
|
Release: 0
|
|
# 3.001 -> normalize -> 3.1.0
|
|
%define cpan_version 3.001
|
|
License: Artistic-1.0 OR GPL-1.0-or-later
|
|
Summary: Work with the cross product of two or more sets
|
|
URL: https://metacpan.org/release/%{cpan_name}
|
|
Source0: https://cpan.metacpan.org/authors/id/B/BR/BRIANDFOY/%{cpan_name}-%{cpan_version}.tar.gz
|
|
Source1: cpanspec.yml
|
|
Source100: README.md
|
|
BuildArch: noarch
|
|
BuildRequires: perl
|
|
BuildRequires: perl-macros
|
|
BuildRequires: perl(ExtUtils::MakeMaker) >= 6.64
|
|
BuildRequires: perl(Test::More) >= 1
|
|
Provides: perl(Set::CrossProduct) = %{version}
|
|
%undefine __perllib_provides
|
|
%{perl_requires}
|
|
|
|
%description
|
|
Given sets S(1), S(2), ..., S(k), each of cardinality n(1), n(2), ..., n(k)
|
|
respectively, the cross product of the sets is the set CP of ordered tuples
|
|
such that { <s1, s2, ..., sk> | s1 => S(1), s2 => S(2), .... sk => S(k). }
|
|
|
|
If you do not like that description, how about:
|
|
|
|
Create a list by taking one item from each array, and do that for all
|
|
possible ways that can be done, so that the first item in the list is
|
|
always from the first array, the second item from the second array, and so
|
|
on.
|
|
|
|
If you need to see it:
|
|
|
|
A => ( a, b, c )
|
|
B => ( 1, 2, 3 )
|
|
C => ( foo, bar )
|
|
|
|
The cross product of A and B and C, A x B x C, is the set of tuples shown:
|
|
|
|
( a, 1, foo )
|
|
( a, 1, bar )
|
|
( a, 2, foo )
|
|
( a, 2, bar )
|
|
( a, 3, foo )
|
|
( a, 3, bar )
|
|
( b, 1, foo )
|
|
( b, 1, bar )
|
|
( b, 2, foo )
|
|
( b, 2, bar )
|
|
( b, 3, foo )
|
|
( b, 3, bar )
|
|
( c, 1, foo )
|
|
( c, 1, bar )
|
|
( c, 2, foo )
|
|
( c, 2, bar )
|
|
( c, 3, foo )
|
|
( c, 3, bar )
|
|
|
|
In code, it looks like this:
|
|
|
|
use v5.26;
|
|
use Set::CrossProduct;
|
|
|
|
my $cross = Set::CrossProduct->new( {
|
|
A => [ qw( a b c ) ],
|
|
B => [ qw( 1 2 3 ) ],
|
|
C => [ qw( foo bar ) ],
|
|
} );
|
|
|
|
while( my $t = $cross->get ) {
|
|
printf "( %s, %s, %s )\n", $t->@{qw(A B C)};
|
|
}
|
|
|
|
If one of the sets happens to be empty, the cross product is empty too.
|
|
|
|
A => ( a, b, c )
|
|
B => ( )
|
|
|
|
In this case, A x B is the empty set, so you'll get no tuples.
|
|
|
|
This module combines the arrays that you give to it to create this cross
|
|
product, then allows you to access the elements of the cross product in
|
|
sequence, or to get all of the elements at once. Be warned! The cardinality
|
|
of the cross product, that is, the number of elements in the cross product,
|
|
is the product of the cardinality of all of the sets.
|
|
|
|
The constructor, 'new', gives you an iterator that you can use to move
|
|
around the cross product. You can get the next tuple, peek at the previous
|
|
or next tuples, or get a random tuple. If you were inclined, you could even
|
|
get all of the tuples at once, but that might be a very large list. This
|
|
module lets you handle the tuples one at a time.
|
|
|
|
I have found this module very useful for creating regression tests. I
|
|
identify all of the boundary conditions for all of the code branches, then
|
|
choose bracketing values for each of them. With this module I take all of
|
|
the values for each test and create every possibility in the hopes of
|
|
exercising all of the code. Of course, your use is probably more
|
|
interesting. :)
|
|
|
|
%prep
|
|
%autosetup -n %{cpan_name}-%{cpan_version}
|
|
|
|
find . -type f ! -path "*/t/*" ! -name "*.pl" ! -path "*/bin/*" ! -path "*/script/*" ! -path "*/scripts/*" ! -name "configure" -print0 | xargs -0 chmod 644
|
|
|
|
%build
|
|
perl Makefile.PL INSTALLDIRS=vendor
|
|
%make_build
|
|
|
|
%check
|
|
make test
|
|
|
|
%install
|
|
%perl_make_install
|
|
%perl_process_packlist
|
|
%perl_gen_filelist
|
|
|
|
%files -f %{name}.files
|
|
%doc Changes examples
|
|
%license LICENSE
|
|
|
|
%changelog
|