How does someone go about doing unit testing for functions that could legitimately return a huge variety of responses depending on input? I'm working with a program that will take a string of ASCII characters and output corresponding Unicode characters according to a fairly simple map/system (SAMPA, Kirshenbaum, etc.). I want to learn how to do thorough unit testing and good design, but this one has me stumped.
I can definitely test each individual character or sequence of characters in those systems, and even a few that combine characters. But to test every possible character in any possible combination? That's definitely no longer unit testing. Would it be integration testing? How would you test something like this? How do you decide how thorough you need to be able to test it?
To illustrate maybe a little better, I can assert that f("N") === "ŋ", that f("r\\") === "ɹ"; etc.
But testing that f("Nr\\") === "ŋɹ" and f("r\\N") === "ɹŋ" gets less sustainable.
Now consider that there are dozens and dozens of these "translations", some are 1:1 in terms of string length, but sometimes 2 characters of input result in anywhere from 1 to 3 characters of output; depending on the system. It's not possible to test every possible combination, and errors could easily sneak in where input strings are divided incorrectly (seeing the tokens in "r\\N" as "r" and "\\N" rather than "r\\" and "N", for example).
I need to be able to test that a) individual tokens result in the expected output, and that b) strings of tokens are divided correctly. I think B is the one that has me confused on how to test it.
Aucun commentaire:
Enregistrer un commentaire