Randomized testing for NGramAutomaton

Found an error dealing with empty automata.  Fixed it.
Found another error when trying to extract common components from exact
duplicates.  Fixed it too.

Change-Id: I313b12d4d67513dff40ac0bdc26cbf5b492ebf06