private void doComparisonsOnObjects(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); assertEquals( "Comparing " + a + " and " + b + " as objects", signum(comparator.compare(a, b)), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as objects (inverse)", -signum(comparator.compare(b, a)), expectedSignum); }
public void testHash() throws Exception { assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabcd"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertNotSame( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 2).hashCode()); }
private void runTests(String aStr, String bStr, int signum) throws Exception { ImmutableBytesWritable a = new ImmutableBytesWritable( Bytes.toBytes(aStr)); ImmutableBytesWritable b = new ImmutableBytesWritable( Bytes.toBytes(bStr)); doComparisonsOnObjects(a, b, signum); doComparisonsOnRaw(a, b, signum); // Tests for when the offset is non-zero a = new ImmutableBytesWritable(Bytes.toBytes("xxx" + aStr), 3, aStr.length()); b = new ImmutableBytesWritable(Bytes.toBytes("yy" + bStr), 2, bStr.length()); doComparisonsOnObjects(a, b, signum); doComparisonsOnRaw(a, b, signum); // Tests for when offset is nonzero and length doesn't extend to end a = new ImmutableBytesWritable(Bytes.toBytes("xxx" + aStr + "zzz"), 3, aStr.length()); b = new ImmutableBytesWritable(Bytes.toBytes("yy" + bStr + "aaa"), 2, bStr.length()); doComparisonsOnObjects(a, b, signum); doComparisonsOnRaw(a, b, signum); }
public void testSpecificCompare() { ImmutableBytesWritable ibw1 = new ImmutableBytesWritable(new byte[]{0x0f}); ImmutableBytesWritable ibw2 = new ImmutableBytesWritable(new byte[]{0x00, 0x00}); ImmutableBytesWritable.Comparator c = new ImmutableBytesWritable.Comparator(); assertFalse("ibw1 < ibw2", c.compare( ibw1, ibw2 ) < 0 ); }
public void testSpecificCompare() { ImmutableBytesWritable ibw1 = new ImmutableBytesWritable(new byte[]{0x0f}); ImmutableBytesWritable ibw2 = new ImmutableBytesWritable(new byte[]{0x00, 0x00}); ImmutableBytesWritable.Comparator c = new ImmutableBytesWritable.Comparator(); assertFalse("ibw1 < ibw2", c.compare( ibw1, ibw2 ) < 0 ); }
private void doComparisonsOnRaw(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) throws IOException { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); ByteArrayOutputStream baosA = new ByteArrayOutputStream(); ByteArrayOutputStream baosB = new ByteArrayOutputStream(); a.write(new DataOutputStream(baosA)); b.write(new DataOutputStream(baosB)); assertEquals( "Comparing " + a + " and " + b + " as raw", signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as raw (inverse)", -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())), expectedSignum); }
public void testHash() throws Exception { assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertEquals( new ImmutableBytesWritable(Bytes.toBytes("xxabcd"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("abc")).hashCode()); assertNotSame( new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 3).hashCode(), new ImmutableBytesWritable(Bytes.toBytes("xxabc"), 2, 2).hashCode()); }
private void runTests(String aStr, String bStr, int signum) throws Exception { ImmutableBytesWritable a = new ImmutableBytesWritable( Bytes.toBytes(aStr)); ImmutableBytesWritable b = new ImmutableBytesWritable( Bytes.toBytes(bStr)); doComparisonsOnObjects(a, b, signum); doComparisonsOnRaw(a, b, signum); // Tests for when the offset is non-zero a = new ImmutableBytesWritable(Bytes.toBytes("xxx" + aStr), 3, aStr.length()); b = new ImmutableBytesWritable(Bytes.toBytes("yy" + bStr), 2, bStr.length()); doComparisonsOnObjects(a, b, signum); doComparisonsOnRaw(a, b, signum); // Tests for when offset is nonzero and length doesn't extend to end a = new ImmutableBytesWritable(Bytes.toBytes("xxx" + aStr + "zzz"), 3, aStr.length()); b = new ImmutableBytesWritable(Bytes.toBytes("yy" + bStr + "aaa"), 2, bStr.length()); doComparisonsOnObjects(a, b, signum); doComparisonsOnRaw(a, b, signum); }
private void doComparisonsOnObjects(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); assertEquals( "Comparing " + a + " and " + b + " as objects", signum(comparator.compare(a, b)), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as objects (inverse)", -signum(comparator.compare(b, a)), expectedSignum); }
private void doComparisonsOnRaw(ImmutableBytesWritable a, ImmutableBytesWritable b, int expectedSignum) throws IOException { ImmutableBytesWritable.Comparator comparator = new ImmutableBytesWritable.Comparator(); ByteArrayOutputStream baosA = new ByteArrayOutputStream(); ByteArrayOutputStream baosB = new ByteArrayOutputStream(); a.write(new DataOutputStream(baosA)); b.write(new DataOutputStream(baosB)); assertEquals( "Comparing " + a + " and " + b + " as raw", signum(comparator.compare(baosA.toByteArray(), 0, baosA.size(), baosB.toByteArray(), 0, baosB.size())), expectedSignum); assertEquals( "Comparing " + a + " and " + b + " as raw (inverse)", -signum(comparator.compare(baosB.toByteArray(), 0, baosB.size(), baosA.toByteArray(), 0, baosA.size())), expectedSignum); }