public static List<Group> enumerateFrom(Group root) {
        List<Group> leaves = new ArrayList<>();
        visitNode(root, leaves);
        return leaves;
    }
@Test
    void multipleLeafGroupsAreEnumerated() throws Exception {
        Group g = new Group(0, "donkeykong", dummyDistribution());
        Group child = new Group(1, "mario", dummyDistribution());
        child.addSubGroup(new Group(2, "toad"));
        child.addSubGroup(new Group(3, "yoshi"));
        g.addSubGroup(child);
        g.addSubGroup(new Group(4, "luigi"));

        List<Group> leaves = LeafGroups.enumerateFrom(g);
        // Ensure that output order matches insertion order.
        leaves.sort((a, b) -> Integer.compare(a.getIndex(), b.getIndex()));
        assertThat(leaves.size(), is(3));
        assertThat(leaves.get(0).getName(), is("toad"));
        assertThat(leaves.get(1).getName(), is("yoshi"));
        assertThat(leaves.get(2).getName(), is("luigi"));
    }