I am working on a calculation project with lots of scientific, domain specific knowledge. As such, our client has given us CSV files populated with inputs and outputs. We can write unit tests by carefully copying over all this data to the setups and the asserts but we would like to avoid this as it is pure grunt work and missing a single decimal could invalidate our tests.
I have made a quick prototype that takes a simple CSV file and tun it into an input and output object using Common.BeanUtils.populate (works like a dream) and some brute force parsing. My file looks like such:
Inputs | AtomicNumber | AtomicWeight | IsIsotope | RateOfDecay |
| ### | ### | 1 | 0 |
Output | WillItBlend |
| 1 |
And this has worked so far. My problem is now I've come to a class that has collections and a file that looks like this:
Inputs | MoleculeId | StateAtRoomTemp | IsPosionous | IsShiny |
| ### | L | 1 | 1 |
Inputs | AtomicNumber | AtomicWeight | IsIsotope | RateOfDecay |
| ### | ### | 1 | 0 |
| ### | ### | 1 | 0 |
| ### | ### | 1 | 0 |
Output | WillItBlend |
| 1 |
where each molecule has a number of elements. What (if any) elegant solutions exist to easily make a molecule bean with a list of elements?
I have come up with a possible but not perfect solution. I could change the format from:
Inputs | AtomicNumber | AtomicWeight | IsIsotope | RateOfDecay |
| ### | ### | 1 | 0 |
| ### | ### | 1 | 0 |
| ### | ### | 1 | 0 |
to:
*Elements | AtomicNumber | AtomicWeight | IsIsotope | RateOfDecay |
| ### | ### | 1 | 0 |
| ### | ### | 1 | 0 |
| ### | ### | 1 | 0 |
When I hit that *, I use the PopulateUtils with the property name that follows to get the type. I then create a new bean of that type, populate it like I populated the normal inputs and then put that new object or collection of objects into the previously created bean. I am not proud of this solution so I will not accept this until it is clear that it wont get better.