@@ -0,0 +1,2324 @@
+package org.grouplens.lenskit.knn.item;%0A%0Aimport static org.junit.Assert.*;%0Aimport static org.hamcrest.Matchers.*;%0A%0Aimport it.unimi.dsi.fastutil.longs.LongAVLTreeSet;%0Aimport it.unimi.dsi.fastutil.longs.LongSortedSet;%0Aimport org.grouplens.lenskit.collections.ScoredLongList;%0Aimport org.grouplens.lenskit.collections.ScoredLongListIterator;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0A/**%0A * @author Michael Ekstrand%0A */%0Apublic class TestItemItemModelAccumulator %7B%0A    LongSortedSet universe;%0A    /**%0A     * An accumulator with a size of 5 and universe of %5B1,10%5D.%0A     */%0A    ItemItemModelAccumulator accum;%0A%0A    @Before%0A    public void newAccumulator() %7B%0A        universe = new LongAVLTreeSet();%0A        for (long i = 1; i %3C= 10; i++) %7B%0A            universe.add(i);%0A        %7D%0A        accum = new ItemItemModelAccumulator(5, universe);%0A    %7D%0A%0A    @Test%0A    public void testEmpty() %7B%0A        ItemItemModel model = accum.build();%0A        assertThat(model, notNullValue());%0A        assertThat(model.getItemUniverse(), equalTo(universe));%0A    %7D%0A    %0A    @Test%0A    public void testAccum() %7B%0A        accum.put(1, 2, Math.PI);%0A        accum.put(7, 3, Math.E);%0A        ItemItemModel model = accum.build();%0A        ScoredLongList nbrs = model.getNeighbors(1);%0A        assertThat(nbrs, hasSize(1));%0A        assertThat(nbrs.get(0), equalTo(2L));%0A        assertThat(nbrs.getScore(0), closeTo(Math.PI, 1.0e-6));%0A        nbrs = model.getNeighbors(7);%0A        assertThat(nbrs, hasSize(1));%0A        assertThat(nbrs.get(0), equalTo(3L));%0A        assertThat(nbrs.getScore(0), closeTo(Math.E, 1.0e-6));%0A    %7D%0A%0A    @Test%0A    public void testTruncate() %7B%0A        for (long i = 1; i %3C= 10; i++) %7B%0A            for (long j = 1; j %3C= 10; j += (i %25 3) + 1) %7B%0A                accum.put(i, j, Math.pow(Math.E, -i) * Math.pow(Math.PI, -j));%0A            %7D%0A        %7D%0A        ItemItemModel model = accum.build();%0A        ScoredLongList nbrs = model.getNeighbors(1);%0A        assertThat(nbrs, hasSize(5));%0A        nbrs = model.getNeighbors(4);%0A        assertThat(nbrs, hasSize(5));%0A        ScoredLongListIterator iter = nbrs.iterator();%0A        while (iter.hasNext()) %7B%0A            long j = iter.nextLong();%0A            double s = iter.getScore();%0A            assertThat(s, closeTo(Math.pow(Math.E, -4) * Math.pow(Math.PI, -j), 1.0e-6));%0A        %7D%0A    %7D%0A%7D%0A

Test the item-item model accumulator