-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added random postal code generator, wikiword, tests and manual entry #28
Conversation
Looks quite nice. Have you found you can use the postal codes often? |
Thank you, I spend about half of the time it took me to write, removing ugly or incorrect things so you would find it agreeable. The postal codes are valid as far as the regex goes, I needed it for that purpose. That is correct, the postal code is not build for that purpose but to be able to give an insurance calculator a region in which a risk is assessed and so it will pass a regex test for a country specific code. If I had the purpose of testing address lookup, I would build a small collection of codes and house numbers with the matching address so an assert on the returned value would be possible. |
A small 'problem' with this pull request is that it introduces dependencies. Normal plugin loading by FitNesse does not use maven or anything like that, so we would also have to update the pom.xml to create a '-with-dependencies' version, which could be placed in the wiki's plugins directory. And we should double check the license of the (transitive) dependencies, to ensure we can redistribute them. |
I was afraid you'd have an issue with that. What I could do is three things:
You pick one 😄 |
As an aside, Generex uses the Apache licence. |
So Generex is fine, because this is also Apache 2.0 license, but Generex uses dk.brics.automaton, which is BSD licensed. The regex generation is quite cool, so if you want to look at re-implementing that: it feels quite powerful, so I would gladly have it. BUT for the current purposes (and the relative simplicity of the postal code generation) option 2, just implementing with RandomUtil seems simpler and sufficient. |
working on the basic implementation now and I was wondering if and how you would approach an "optional" block in a postal code? |
When committing, I got these errors: |
Also, I removed some codes that were cumbersome to reproduce without a regex. Mostly because I am lazy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks quite good now, some minor issues now.
/** | ||
* Tests RandomPostalCodeGenerator. | ||
* The postal codes are checked on length only to validate teh switch | ||
* testing the correctness would be testing the Generex library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment no longer seems relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed, sorry for this oversight.
import java.util.Random; | ||
|
||
public class RandomPostalCodeGenerator { | ||
RandomUtil random = new RandomUtil(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this field cannot be private static final
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, so I changed it.
} | ||
|
||
private String pickOne(String result1, String result2) { | ||
if (Math.random() < 0.5) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no use random
for this choice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because random
wasn't on stackoverflow where I found this solution. Changed to use random
.
result = getRandomStringNumbers(4); | ||
break; | ||
case "US": | ||
String result1 = getRandomStringNumbers(5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not first make a choice and only add + "-" + getRandomStringNumbers(4)
if it is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this very clear in what it does and allowed me to use the pickOne
method.
Optimizing to generate as little Strings as possible will lead to complex code I feel.
…rmitted (all CA codes have length 7)
Kan je leven met mijn aanpassingen? |
Ja, ik leer hier ook weer een hoop van 😄 |
I did got an error at the pom.xml where IntelliJ could not find two plugins but considering I did not change anything in that area I figured I'd commit anyway.
The reason for this is that I needed a postal code generator and figured you might as well.