Skip to content

Commit

Permalink
Replace double with long in IndexedSetTest
Browse files Browse the repository at this point in the history
  • Loading branch information
cc committed Aug 16, 2015
1 parent d9f409e commit a152104
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions servers/src/test/java/tachyon/master/next/IndexedSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,26 @@

public class IndexedSetTest {
private static class Pair {
// mInt is private, mDouble is public, this is deliberate to assure both private and public
// fields can be accessed.
private int mInt;
public double mDouble;
private long mLong;

public Pair(int i, double d) {
public Pair(int i, long l) {
mInt = i;
mDouble = d;
mLong = l;
}

public int intValue() {
return mInt;
}

public long longValue() {
return mLong;
}
}

private IndexedSet<Pair> mSet;
private IndexedSet.FieldIndex<Pair> mIntIndex;
private IndexedSet.FieldIndex<Pair> mDoubleIndex;
private IndexedSet.FieldIndex<Pair> mLongIndex;

@Before
public void before() {
Expand All @@ -52,15 +54,15 @@ public Object getFieldValue(Pair o) {
return o.intValue();
}
};
mDoubleIndex = new IndexedSet.FieldIndex<Pair>() {
mLongIndex = new IndexedSet.FieldIndex<Pair>() {
public Object getFieldValue(Pair o) {
return o.mDouble;
return o.longValue();
}
};
mSet = new IndexedSet<Pair>(mIntIndex, mDoubleIndex);
mSet = new IndexedSet<Pair>(mIntIndex, mLongIndex);
for (int i = 0; i < 3; i ++) {
for (int d = 0; d < 3; d ++) {
mSet.add(new Pair(i, (double)d));
for (long l = 0; l < 3; l ++) {
mSet.add(new Pair(i, l));
}
}
}
Expand All @@ -71,29 +73,29 @@ public void containsTest() {
Assert.assertTrue(mSet.contains(mIntIndex, i));
}
Assert.assertFalse(mSet.contains(mIntIndex, 4));
for (int d = 0; d < 3; d ++) {
Assert.assertTrue(mSet.contains(mDoubleIndex, (double)d));
for (long l = 0; l < 3; l ++) {
Assert.assertTrue(mSet.contains(mLongIndex, l));
}
Assert.assertFalse(mSet.contains(mDoubleIndex, 2.9));
Assert.assertFalse(mSet.contains(mLongIndex, 4L));
}

@Test
public void getTest() {
for (int i = 0; i < 3; i ++) {
Set<Pair> set = mSet.getByField(mIntIndex, i);
Assert.assertEquals(3, set.size());
List<Double> doubles = new ArrayList<Double>(set.size());
List<Long> longs = new ArrayList<Long>(set.size());
for (Pair o : set) {
doubles.add(o.mDouble);
longs.add(o.longValue());
}
Collections.sort(doubles);
Collections.sort(longs);
for (int j = 0; j < 3; j ++) {
Assert.assertEquals(new Double(j), doubles.get(j));
Assert.assertEquals(new Long(j), longs.get(j));
}

set = mSet.getByField(mDoubleIndex, i);
set = mSet.getByField(mLongIndex, i);
Assert.assertEquals(0, set.size()); // i is integer, must be in the same type
set = mSet.getByField(mDoubleIndex, (double) i);
set = mSet.getByField(mLongIndex, (long) i);
Assert.assertEquals(3, set.size());
List<Integer> ints = new ArrayList<Integer>(set.size());
for (Pair o : set) {
Expand All @@ -109,19 +111,19 @@ public void getTest() {
@Test
public void removeTest() {
Pair toRemove = mSet.all().iterator().next();
Assert.assertEquals(3, mSet.getByField(mDoubleIndex, toRemove.mDouble).size());
Assert.assertEquals(3, mSet.getByField(mLongIndex, toRemove.longValue()).size());
Assert.assertEquals(9, mSet.size());
Assert.assertTrue(mSet.remove(toRemove));
Assert.assertEquals(8, mSet.size());
Assert.assertEquals(2, mSet.getByField(mIntIndex, toRemove.intValue()).size());
Assert.assertEquals(2, mSet.getByField(mDoubleIndex, toRemove.mDouble).size());
Assert.assertEquals(2, mSet.getByField(mLongIndex, toRemove.longValue()).size());
}

@Test
public void removeNonExistTest() {
Assert.assertFalse(mSet.remove(new Pair(-1, -1)));
Assert.assertFalse(mSet.removeByField(mIntIndex, -1));
Assert.assertFalse(mSet.removeByField(mDoubleIndex, -1.0));
Assert.assertFalse(mSet.removeByField(mLongIndex, -1L));
}

@Test
Expand All @@ -133,8 +135,8 @@ public void removeByFieldTest() {
Assert.assertEquals(0, mSet.getByField(mIntIndex, 1).size());
Assert.assertEquals(3, mSet.getByField(mIntIndex, 0).size());
Assert.assertEquals(3, mSet.getByField(mIntIndex, 2).size());
for (int d = 0; d < 3; d ++) {
Assert.assertEquals(2, mSet.getByField(mDoubleIndex, (double)d).size());
for (long l = 0; l < 3; l ++) {
Assert.assertEquals(2, mSet.getByField(mLongIndex, l).size());
}
}
}

0 comments on commit a152104

Please sign in to comment.