### Question:
PowerSet { public Set<PowerSet> getOnPowerSet(int minOn) { Set<PowerSet> sets = new HashSet<PowerSet>(); if (sizeOn() <= minOn) { return sets; } for (int p=0; p<set.length; p++){ if (set[p]){ PowerSet cs = new PowerSet(this); cs.switchOff(p); sets.add(cs); sets.addAll(cs.getOnPowerSet(minOn)); } } return sets; } PowerSet(int size);  PowerSet(boolean[] set);  PowerSet(PowerSet powerSet); void switchOn(int i); void switchOff(int i); boolean isOn(int i); boolean isOff(int i); boolean isChild(List<PowerSet> parents); boolean isChild(PowerSet potentialParent); List<PowerSet> getChildren(List<PowerSet> invalidParents); int size(); @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); Set<PowerSet> getOnPowerSet(int minOn); int sizeOn(); int getDiff(PowerSet child);  }### Answer:
@Test public void testGetOnPowerSet() { PowerSet original = new PowerSet(new boolean[] { false, false, false }); Set<PowerSet> pss = original.getOnPowerSet(0); assertEquals("Empty PowerSet has no subsets", 0, pss.size()); original.switchOn(0); pss = original.getOnPowerSet(0); assertEquals("PowerSet of size one has one subset", 1, pss.size()); for (PowerSet ps : pss) { assertEquals("The subset of PowerSet of size 1 is the empty PowerSet", 0, ps.sizeOn()); } original.switchOn(1); pss = original.getOnPowerSet(0); assertEquals("PowerSet of size two has three subsets", 3, pss.size()); for (PowerSet ps : original.getOnPowerSet(1)) { assertEquals("The subsets of PowerSet of size 2 at one distance have one active index.", 1, ps.sizeOn()); } original.switchOn(2); pss = original.getOnPowerSet(0); assertEquals("PowerSet of size three has eight subsets", 7, pss.size()); for (PowerSet ps : original.getOnPowerSet(2)) { assertEquals("The subsets of PowerSet of size 3 at one distance have two active indices.", 2, ps.sizeOn()); } }
@Test @Ignore public void testPerformance() { boolean[] set = new boolean[10]; Arrays.fill(set, true); PowerSet original = new PowerSet(set); long time10 = System.currentTimeMillis(); original.getOnPowerSet(0); time10 = (System.currentTimeMillis() - time10) / 1000; System.out.print(String.format("Computing PowerSet of size 10 took %d seconds", time10)); set = new boolean[11]; Arrays.fill(set, true); original = new PowerSet(set); long time11 = System.currentTimeMillis(); original.getOnPowerSet(0); time11 = (System.currentTimeMillis() - time11) / 1000; System.out.print(String.format("Computing PowerSet of size 11 took %d seconds",time11)); assertTrue(time11 > time10); }