Exemplo n.º 1
0
  @Test
  public void testInducedPermutation() {
    List<String> origData = Arrays.asList(new String[] {"a", "b", "c", "d", "d"});
    List<String> permutedData = Arrays.asList(new String[] {"d", "b", "c", "a", "d"});

    DummyRandomKey drk = new DummyRandomKey(RandomKey.inducedPermutation(origData, permutedData));
    List<String> decoded = drk.decode(origData);

    Assert.assertEquals("d", decoded.get(0));
    Assert.assertEquals("b", decoded.get(1));
    Assert.assertEquals("c", decoded.get(2));
    Assert.assertEquals("a", decoded.get(3));
    Assert.assertEquals("d", decoded.get(4));

    try {
      RandomKey.inducedPermutation(
          Arrays.asList(new String[] {"a", "b", "c", "d", "d"}),
          Arrays.asList(new String[] {"a", "b", "c", "d"}));
      Assert.fail("Uncaught exception");
    } catch (MathIllegalArgumentException e) {
      // no-op
    }
    try {
      RandomKey.inducedPermutation(
          Arrays.asList(new String[] {"a", "b", "c", "d", "d"}),
          Arrays.asList(new String[] {"a", "b", "c", "d", "f"}));
      Assert.fail("Uncaught exception");
    } catch (MathIllegalArgumentException e) {
      // no-op
    }
  }
Exemplo n.º 2
0
 @Test
 public void testEqualRepr() {
   DummyRandomKey drk = new DummyRandomKey(new Double[] {0.2, 0.2, 0.5});
   List<String> decodedData = drk.decode(Arrays.asList(new String[] {"a", "b", "c"}));
   Assert.assertEquals("a", decodedData.get(0));
   Assert.assertEquals("b", decodedData.get(1));
   Assert.assertEquals("c", decodedData.get(2));
 }
Exemplo n.º 3
0
  @Test
  public void testIdentityPermutation() {
    DummyRandomKey drk = new DummyRandomKey(RandomKey.identityPermutation(5));
    List<String> decoded = drk.decode(Arrays.asList(new String[] {"a", "b", "c", "d", "e"}));

    Assert.assertEquals("a", decoded.get(0));
    Assert.assertEquals("b", decoded.get(1));
    Assert.assertEquals("c", decoded.get(2));
    Assert.assertEquals("d", decoded.get(3));
    Assert.assertEquals("e", decoded.get(4));
  }
Exemplo n.º 4
0
  @Test
  public void testDecode() {
    DummyRandomKey drk = new DummyRandomKey(new Double[] {0.4, 0.1, 0.5, 0.8, 0.2});
    List<String> decoded = drk.decode(Arrays.asList(new String[] {"a", "b", "c", "d", "e"}));

    Assert.assertEquals("b", decoded.get(0));
    Assert.assertEquals("e", decoded.get(1));
    Assert.assertEquals("a", decoded.get(2));
    Assert.assertEquals("c", decoded.get(3));
    Assert.assertEquals("d", decoded.get(4));
  }
Exemplo n.º 5
0
  @Test
  public void testIsSame() {
    DummyRandomKey drk1 = new DummyRandomKey(new Double[] {0.4, 0.1, 0.5, 0.8, 0.2});
    DummyRandomKey drk2 = new DummyRandomKey(new Double[] {0.4, 0.1, 0.5, 0.8, 0.2});
    DummyRandomKey drk3 = new DummyRandomKey(new Double[] {0.4, 0.15, 0.5, 0.8, 0.2});
    DummyRandomKey drk4 = new DummyRandomKey(new Double[] {0.4, 0.25, 0.5, 0.8, 0.2});
    DummyRandomKey drk5 = new DummyRandomKey(new Double[] {0.4, 0.25, 0.5, 0.8, 0.2, 0.5});

    Assert.assertTrue(drk1.isSame(drk2));
    Assert.assertTrue(drk2.isSame(drk3));
    Assert.assertFalse(drk3.isSame(drk4));
    Assert.assertFalse(drk4.isSame(drk5));
  }