Java:生成幂集
这可能是与语言无关的/有用的答案可能只是在伪代码中。
我有一个程序想在一系列输入下进行测试。该程序需要一组文件,其中一个被指定为根。我想使用所有可能的文件子集运行该程序。 (包含相同文件但具有不同根的两个子集被认为是不同的。)
这是一个相同的示例。假设我有文件 A、B 和 C。我想用以下内容进行测试:
{A}, root = A
{B}, root = B
{C}, root = C
{A B}, root = A
{A B}, root = B
{B C}, root = B
{B C}, root = C
{A C}, root = A
{A C}, root = C
{A B C}, root = A
{A B C}, root = B
{A B C}, root = C
等等。我相信这将是动力组。
给定一个充满文件的目录,在 Java 中生成这个集合的最佳方法是什么?
This could be language agnostic/helpful answers could just be in pseudo-code.
I have a program that I would like to test under a range of inputs. This program takes a set of files, one of which is designated as the root. I want to run the program with all possible subsets of files. (Two subsets, containing the same files, but with different roots, are considered to be different.)
Here's a same example. Say I have files A, B, and C. I would want to test with:
{A}, root = A
{B}, root = B
{C}, root = C
{A B}, root = A
{A B}, root = B
{B C}, root = B
{B C}, root = C
{A C}, root = A
{A C}, root = C
{A B C}, root = A
{A B C}, root = B
{A B C}, root = C
and so on. I believe this would be the powerset.
What is the best way to generate this set in Java, given a directory full of files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您说的是 Java,但请看一下:使用 C# 的排列、组合和变体泛型。
You said Java, but please take a look on this: Permutations, Combinations, and Variations using C# Generics.
下面是对所有可能的 mixes 进行测试的递归方法的伪代码。最大子集优先:
当然,如果您首先想要最小的子集,那么重组并不难。
Here's pseudocode for a recursive approach to doing tests on all possible mixes.largest-subsets-first:
Not hard to reorg if you want smallest subsets first, of course.
这就是你所追求的(伪代码)吗?
这将构建一个集合,然后将该集合和集合中的每个条目传递给 do-test 方法。
Is this what you are after (psuedocode)?
This would build a set, then pass the set and each entry in the set to a
do-test
method.