Skip to content
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

Merged
merged 12 commits into from
Dec 28, 2017
Merged

added random postal code generator, wikiword, tests and manual entry #28

merged 12 commits into from
Dec 28, 2017

Conversation

keetron
Copy link
Contributor

@keetron keetron commented Dec 16, 2017

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.

@fhoeben
Copy link
Owner

fhoeben commented Dec 16, 2017

Looks quite nice. Have you found you can use the postal codes often?
For the Netherlands I'm used to applications that look up full address based on postal code and house number; for those the postal codes generated this way will not be acceptable.

@keetron
Copy link
Contributor Author

keetron commented Dec 16, 2017

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.
All regex expressions are taken from https://rgxdb.com/r/316F0I2N and as you might notice is taht I implemented all these and nothing else. For my test, I needed a valid Dutch postal code and a non-Dutch postal code where the country is known. And even then, the actual premium calculation service is stubbed, so if the code represents a valid region is not checked.

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.

@fhoeben
Copy link
Owner

fhoeben commented Dec 16, 2017

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.

@keetron
Copy link
Contributor Author

keetron commented Dec 16, 2017

I was afraid you'd have an issue with that.

What I could do is three things:

  • refactor to no longer need the dependency, basically copy the project code into HSAC and keep the regex driven string generation that might be good for something else.
  • refactor to no longer need the dependency by using the RandomUtil and some String magic for a few countries, so abandon the regex entirely.
  • close the PR, I will not be using the FitNesse implementation for now as my client cannot handle Java 8 and use the base Java code in my project. I wrote it here so others could benefit from fairly basic code.

You pick one 😄

@keetron
Copy link
Contributor Author

keetron commented Dec 16, 2017

As an aside, Generex uses the Apache licence.

@fhoeben
Copy link
Owner

fhoeben commented Dec 17, 2017

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.

@keetron
Copy link
Contributor Author

keetron commented Dec 23, 2017

working on the basic implementation now and I was wondering if and how you would approach an "optional" block in a postal code?
Say the US code can be 5 numbers with an optional 4 numbers, separated by a hyphen. I can write both and generate a random number, which will tell me by a modulus 2 of 1 or 0 which of the two generators I should use but that feels clunky. There got to be a better way. Would you (or anyone else reading this) have a suggestion that is only a few lines long?

@keetron
Copy link
Contributor Author

keetron commented Dec 23, 2017

When committing, I got these errors:
Error:(95, 16) Plugin 'org.apache.maven.plugins:maven-source-plugin:2.4' not found
Error:(108, 16) Plugin 'org.apache.maven.plugins:maven-javadoc-plugin:2.10.2' not found
Error:(121, 16) Plugin 'org.apache.maven.plugins:maven-gpg-plugin:1.6' not found
Just so you know.

@keetron
Copy link
Contributor Author

keetron commented Dec 23, 2017

Also, I removed some codes that were cumbersome to reproduce without a regex. Mostly because I am lazy.

Copy link
Owner

@fhoeben fhoeben left a 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
Copy link
Owner

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

Copy link
Contributor Author

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();
Copy link
Owner

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?

Copy link
Contributor Author

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) {
Copy link
Owner

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?

Copy link
Contributor Author

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);
Copy link
Owner

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?

Copy link
Contributor Author

@keetron keetron Dec 26, 2017

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.

@fhoeben
Copy link
Owner

fhoeben commented Dec 27, 2017

Kan je leven met mijn aanpassingen?

@keetron
Copy link
Contributor Author

keetron commented Dec 27, 2017

Ja, ik leer hier ook weer een hoop van 😄

@fhoeben fhoeben merged commit 1fd5c29 into fhoeben:master Dec 28, 2017
@keetron keetron deleted the RandomPostalCode branch December 30, 2017 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants