Search in sources :

Example 1 with PLinkArrayBag

use of jcog.bag.impl.PLinkArrayBag in project narchy by automenta.

the class ArrayBagTest method testBudgetMerge.

@Test
public void testBudgetMerge() {
    PLinkArrayBag<String> a = new PLinkArrayBag<String>(4, plus, new HashMap<>(4));
    assertEquals(0, a.size());
    a.put(new PLink("x", 0.1f));
    a.put(new PLink("x", 0.1f));
    a.commit(null);
    assertEquals(1, a.size());
    PriReference<String> agx = a.get("x");
    Pri expect = new Pri(0.2f);
    assertTrue(Util.equals(expect.priElseNeg1(), agx.priElseNeg1(), 0.01f), agx + "==?==" + expect);
}
Also used : PLink(jcog.pri.PLink) PLinkArrayBag(jcog.bag.impl.PLinkArrayBag) Pri(jcog.pri.Pri) Test(org.junit.jupiter.api.Test)

Example 2 with PLinkArrayBag

use of jcog.bag.impl.PLinkArrayBag in project narchy by automenta.

the class ArrayBagTest method testCapacity.

@Test
public void testCapacity() {
    PLinkArrayBag a = new PLinkArrayBag(2, plus, new HashMap<>(2));
    a.put(new PLink("x", 0.1f));
    a.put(new PLink("y", 0.2f));
    a.print();
    System.out.println();
    assertEquals(2, a.size());
    a.commit(null);
    assertSorted(a);
    assertEquals(0.1f, a.priMin(), 0.01f);
    a.put(new PLink("z", 0.05f));
    a.print();
    System.out.println();
    assertEquals(2, a.size());
    assertTrue(a.contains("x") && a.contains("y"));
    assertFalse(a.contains("z"));
}
Also used : PLink(jcog.pri.PLink) PLinkArrayBag(jcog.bag.impl.PLinkArrayBag) Test(org.junit.jupiter.api.Test)

Example 3 with PLinkArrayBag

use of jcog.bag.impl.PLinkArrayBag in project narchy by automenta.

the class ArrayBagTest method testSort.

@Test
public void testSort() {
    PLinkArrayBag a = new PLinkArrayBag(4, plus, new HashMap<>(4));
    a.put(new PLink("x", 0.1f));
    a.put(new PLink("y", 0.2f));
    a.commit(null);
    Iterator<PriReference<String>> ii = a.iterator();
    assertEquals("y", ii.next().get());
    assertEquals("x", ii.next().get());
    assertEquals("[$0.2000 y, $0.1000 x]", a.listCopy().toString());
    System.out.println(a.listCopy());
    a.put(new PLink("x", 0.2f));
    System.out.println(a.listCopy());
    a.commit();
    // x should now be ahead
    // x first
    assertTrue(a.listCopy().toString().contains("x,"));
    // y second
    assertTrue(a.listCopy().toString().contains("y]"));
    ii = a.iterator();
    assertEquals("x", ii.next().get());
    assertEquals("y", ii.next().get());
}
Also used : PLink(jcog.pri.PLink) PLinkArrayBag(jcog.bag.impl.PLinkArrayBag) PriReference(jcog.pri.PriReference) Test(org.junit.jupiter.api.Test)

Aggregations

PLinkArrayBag (jcog.bag.impl.PLinkArrayBag)3 PLink (jcog.pri.PLink)3 Test (org.junit.jupiter.api.Test)3 Pri (jcog.pri.Pri)1 PriReference (jcog.pri.PriReference)1