Package edu.umd.cloud9.io.map

Examples of edu.umd.cloud9.io.map.HMapIFW


    // make sure this does nothing
    m1.decode();

    assertTrue(m1.size() == 0);

    HMapIFW m2 = HMapIFW.create(m1.serialize());

    assertTrue(m2.size() == 0);
  }
View Full Code Here


public class HMapIFWTest {

  @Test
  public void testBasic() throws IOException {
    HMapIFW m = new HMapIFW();

    m.put(2, 5.0f);
    m.put(1, 22.0f);

    float value;

    assertEquals(m.size(), 2);

    value = m.get(2);
    assertTrue(value == 5.0f);

    value = m.remove(2);
    assertEquals(m.size(), 1);

    value = m.get(1);
    assertTrue(value == 22.0f);
  }
View Full Code Here

  }

  @Test
  public void testSerialize1() throws IOException {
    HMapIFW.setLazyDecodeFlag(false);
    HMapIFW m1 = new HMapIFW();

    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes = m1.serialize();
    HMapIFW n2 = HMapIFW.create(bytes);

    float value;

    assertEquals(n2.size(), 2);

    value = n2.get(3);
    assertTrue(value == 5.0f);

    value = n2.remove(3);
    assertEquals(n2.size(), 1);

    value = n2.get(4);
    assertTrue(value == 22.0f);
  }
View Full Code Here

  }

  @Test
  public void testSerializeLazy1() throws IOException {
    HMapIFW.setLazyDecodeFlag(true);
    HMapIFW m1 = new HMapIFW();

    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes = m1.serialize();
    HMapIFW m2 = HMapIFW.create(bytes);

    assertFalse(m2.isDecoded());
    assertEquals(2, m2.size());

    int[] keys = m2.getKeys();
    float[] values = m2.getValues();

    assertTrue(keys[0] == 3);
    assertTrue(keys[1] == 4);

    assertTrue(values[0] == 5.0f);
    assertTrue(values[1] == 22.0f);

    m2.decode();
    assertTrue(m2.isDecoded());
   
    float value;
    assertEquals(m2.size(), 2);

    value = m2.get(3);
    assertTrue(value == 5.0f);

    value = m2.remove(3);
    assertEquals(1, m2.size());

    value = m2.get(4);
    assertTrue(value == 22.0f);
  }
View Full Code Here

  }

  @Test
  public void testSerializeLazy2() throws IOException {
    HMapIFW.setLazyDecodeFlag(true);
    HMapIFW m1 = new HMapIFW();

    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes = m1.serialize();
    HMapIFW m2 = HMapIFW.create(bytes);

    assertFalse(m2.isDecoded());
    assertEquals(2, m2.size());

    int[] keys = m2.getKeys();
    float[] values = m2.getValues();

    assertTrue(keys[0] == 3);
    assertTrue(keys[1] == 4);

    assertTrue(values[0] == 5.0f);
    assertTrue(values[1] == 22.0f);

    m2.decode();
    float value;
    assertEquals(m2.size(), 2);

    value = m2.get(3);
    assertTrue(value == 5.0f);

    value = m2.remove(3);
    assertEquals(m2.size(), 1);

    value = m2.get(4);
    assertTrue(value == 22.0f);
  }
View Full Code Here

  @Test
  public void testLazyPlus1() throws IOException {
    HMapIFW.setLazyDecodeFlag(true);
   
    HMapIFW m1 = new HMapIFW();
    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes1 = m1.serialize();
   
    HMapIFW m2 = new HMapIFW();
    m2.put(3, 1.0f);
    m2.put(4, 1.0f);
    m2.put(5, 1.0f);

    byte[] bytes2 = m2.serialize();

    HMapIFW n1 = HMapIFW.create(bytes1);
    HMapIFW n2 = HMapIFW.create(bytes2);

    assertFalse(n1.isDecoded());
    assertEquals(2, n1.size());

    assertFalse(n2.isDecoded());
    assertEquals(3, n2.size());

    // n1 isn't decoded, n2 isn't decoded
    n1.plus(n2);

    assertTrue(n1.size() == 3);
    assertTrue(n1.get(3) == 6.0f);
    assertTrue(n1.get(4) == 23.0f);
    assertTrue(n1.get(5) == 1.0f);
    assertTrue(n1.isDecoded());
    assertFalse(n2.isDecoded());
  }
View Full Code Here

 
  @Test
  public void testLazyPlus2() throws IOException {
    HMapIFW.setLazyDecodeFlag(true);
   
    HMapIFW m1 = new HMapIFW();
    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes1 = m1.serialize();
   
    HMapIFW m2 = new HMapIFW();
    m2.put(3, 1.0f);
    m2.put(4, 1.0f);
    m2.put(5, 1.0f);

    byte[] bytes2 = m2.serialize();

    HMapIFW n1 = HMapIFW.create(bytes1);
    HMapIFW n2 = HMapIFW.create(bytes2);

    assertFalse(n1.isDecoded());
    assertEquals(2, n1.size());

    assertFalse(n2.isDecoded());
    assertEquals(3, n2.size());

    // n1 isn't decoded, n2 is
    n2.decode();
    n1.plus(n2);

    assertTrue(n1.size() == 3);
    assertTrue(n1.get(3) == 6.0f);
    assertTrue(n1.get(4) == 23.0f);
    assertTrue(n1.get(5) == 1.0f);
    assertTrue(n1.isDecoded());
    assertTrue(n2.isDecoded());
  }
View Full Code Here

 
  @Test
  public void testLazyPlus3() throws IOException {
    HMapIFW.setLazyDecodeFlag(true);
   
    HMapIFW m1 = new HMapIFW();
    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes1 = m1.serialize();
   
    HMapIFW m2 = new HMapIFW();
    m2.put(3, 1.0f);
    m2.put(4, 1.0f);
    m2.put(5, 1.0f);

    byte[] bytes2 = m2.serialize();

    HMapIFW n1 = HMapIFW.create(bytes1);
    HMapIFW n2 = HMapIFW.create(bytes2);

    assertFalse(n1.isDecoded());
    assertEquals(2, n1.size());

    assertFalse(n2.isDecoded());
    assertEquals(3, n2.size());

    // n2 isn't decoded, n1 is
    n1.decode();
    n1.plus(n2);

    assertTrue(n1.size() == 3);
    assertTrue(n1.get(3) == 6.0f);
    assertTrue(n1.get(4) == 23.0f);
    assertTrue(n1.get(5) == 1.0f);
    assertTrue(n1.isDecoded());
    assertFalse(n2.isDecoded());
  }
View Full Code Here

 
  @Test
  public void testLazyPlus4() throws IOException {
    HMapIFW.setLazyDecodeFlag(true);
   
    HMapIFW m1 = new HMapIFW();
    m1.put(3, 5.0f);
    m1.put(4, 22.0f);

    byte[] bytes1 = m1.serialize();
   
    HMapIFW m2 = new HMapIFW();
    m2.put(3, 1.0f);
    m2.put(4, 1.0f);
    m2.put(5, 1.0f);

    byte[] bytes2 = m2.serialize();

    HMapIFW n1 = HMapIFW.create(bytes1);
    HMapIFW n2 = HMapIFW.create(bytes2);

    assertFalse(n1.isDecoded());
    assertEquals(2, n1.size());

    assertFalse(n2.isDecoded());
    assertEquals(3, n2.size());

    // both n1 and n2 are decoded
    n1.decode();
    n2.decode();
    n1.plus(n2);

    assertTrue(n1.size() == 3);
    assertTrue(n1.get(3) == 6.0f);
    assertTrue(n1.get(4) == 23.0f);
    assertTrue(n1.get(5) == 1.0f);
    assertTrue(n1.isDecoded());
    assertTrue(n2.isDecoded());
  }
View Full Code Here

    assertTrue(n2.isDecoded());
  }
 
  @Test
  public void testSerializeEmpty() throws IOException {
    HMapIFW m1 = new HMapIFW();

    // make sure this does nothing
    m1.decode();

    assertTrue(m1.size() == 0);

    byte[] bytes = m1.serialize();
    HMapIFW m2 = HMapIFW.create(bytes);

    assertTrue(m2.size() == 0);
  }
View Full Code Here

TOP

Related Classes of edu.umd.cloud9.io.map.HMapIFW

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.