Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

added: semi randomized unit tests for Utils.Pair #158

Merged
merged 1 commit into from

2 participants

@Ahimta

added: Override annotation to Pair#apply(F from), just to make the java compiler a bit happier
added: comments to Pair#apply(F from)

@Ahimta Ahimta added: semi randomized unit tests for Utils.Pair
added: @Override to Pair#apply(F from), just to make the java compiler a bit happier
added: comments to Pair#apply(F from)
55d9ba4
@vinothchandar vinothchandar commented on the diff
test/unit/voldemort/utils/PairTest.java
@@ -0,0 +1,80 @@
+package voldemort.utils;
+
+import static org.hamcrest.CoreMatchers.is;
@vinothchandar Collaborator

is this import in a jar already on lib?

@Ahimta
Ahimta added a note

Thanks for the heads up.
Now that you mention it, I remember that hamcrest has it own jar file in many projects.

I checked the build path of the project in eclipse.
All libraries used are in the project.

Further more, I went to junit 4.11 javadocs (unfortunately didn't find 4.6 javadocs), and found hamcrest matchers there: http://junit.org/javadoc/latest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@vinothchandar vinothchandar merged commit 16db905 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2014
  1. @Ahimta

    added: semi randomized unit tests for Utils.Pair

    Ahimta authored
    added: @Override to Pair#apply(F from), just to make the java compiler a bit happier
    added: comments to Pair#apply(F from)
This page is out of date. Refresh to see the latest.
View
6 src/java/voldemort/utils/Pair.java
@@ -49,6 +49,12 @@ public Pair(F first, S second) {
this.second = second;
}
+ /**
+ * @param from
+ * @return {@code this.second} if {@code from == this.first} even if
+ * {@code from} and {@code this.first} are both null
+ */
+ @Override
public S apply(F from) {
if(from == null ? first == null : from.equals(first))
return second;
View
80 test/unit/voldemort/utils/PairTest.java
@@ -0,0 +1,80 @@
+package voldemort.utils;
+
+import static org.hamcrest.CoreMatchers.is;
@vinothchandar Collaborator

is this import in a jar already on lib?

@Ahimta
Ahimta added a note

Thanks for the heads up.
Now that you mention it, I remember that hamcrest has it own jar file in many projects.

I checked the build path of the project in eclipse.
All libraries used are in the project.

Further more, I went to junit 4.11 javadocs (unfortunately didn't find 4.6 javadocs), and found hamcrest matchers there: http://junit.org/javadoc/latest/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
+
+import java.util.Random;
+
+import org.junit.Test;
+
+public class PairTest {
+
+ private final static int TIMES = 10000;
+ private final static Random randomGenerator = new Random();
+
+ @Test
+ public void testGetFirst_and_getSecond() {
+
+ for(int i = 0; i < TIMES; i++) {
+ final int first = randomGenerator.nextInt();
+ final long second = randomGenerator.nextLong();
+ final Pair<Integer, Long> pair = new Pair<Integer, Long>(first, second);
+
+ assertThat(pair.getFirst(), is(first));
+ assertThat(pair.getSecond(), is(second));
+ }
+ }
+
+ @Test
+ public void testEquals() {
+
+ for(int i = 0; i < TIMES; i++) {
+ final int first = randomGenerator.nextInt();
+ final long second = randomGenerator.nextLong();
+ final Pair<Integer, Long> pair = new Pair<Integer, Long>(first, second);
+
+ assertThat(pair.equals(null), is(false));
+ assertThat(pair.equals(randomGenerator), is(false));
+
+ assertThat(pair.equals(new Pair<Integer, Long>(first + 1, second)), is(false));
+ assertThat(pair.equals(new Pair<Integer, Long>(first, second + 1)), is(false));
+
+ assertThat(pair.equals(new Pair<Integer, Long>(first, second)), is(true));
+ }
+ }
+
+ @Test
+ public void testApply() {
+
+ for(int i = 0; i < TIMES; i++) {
+ final int first = randomGenerator.nextInt();
+ final long second = randomGenerator.nextLong();
+ final Pair<Integer, Long> pair = new Pair<Integer, Long>(first, second);
+
+ assertThat(pair.apply(first), is(second));
+ assertThat((new Pair<Integer, Long>(null, second)).apply(null), is(second));
+
+ assertNull(pair.apply(first + 1));
+
+ assertNull((new Pair<Integer, Long>(first, null)).apply(first));
+ assertNull((new Pair<Integer, Long>(first, null)).apply(null));
+ assertNull((new Pair<Integer, Long>(null, second)).apply(first));
+ assertNull((new Pair<Integer, Long>(null, null)).apply(null));
+ }
+ }
+
+ @Test
+ public void testCreate() {
+
+ for(int i = 0; i < TIMES; i++) {
+ final int first = randomGenerator.nextInt();
+ final long second = randomGenerator.nextLong();
+
+ assumeThat(Pair.create(first, second).equals(new Pair<Integer, Long>(first, second)),
+ is(true));
+ }
+ }
+
+}
Something went wrong with that request. Please try again.