Created
March 3, 2013 19:49
-
-
Save wfaler/5077938 to your computer and use it in GitHub Desktop.
QuickCheck with Java (this will fail until you implement equals on name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.java.quickcheck.Generator; | |
import net.java.quickcheck.generator.PrimitiveGenerators; | |
import net.java.quickcheck.generator.iterable.Iterables; | |
import org.junit.Test; | |
import static org.junit.Assert.assertEquals; | |
public class QuickcheckTest { | |
@Test | |
public void equals(){ | |
for(Name name : Iterables.toIterable(new NameGenerator())){ | |
assertEquals(name, new Name(name.getFirst(), name.getLast())); | |
} | |
} | |
} | |
class Name { | |
private final String first; | |
private final String last; | |
public Name(String first, String last) { | |
super(); | |
this.first = first; | |
this.last = last; | |
} | |
public String getLast() { return last; } | |
public String getFirst() { return first; } | |
} | |
class NameGenerator implements net.java.quickcheck.Generator<Name>{ | |
Generator<String> first = PrimitiveGenerators.strings(); | |
Generator<String> last = PrimitiveGenerators.strings(); | |
@Override public Name next() { | |
return new Name(first.next(), last.next()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment