Search in sources :

Example 1 with AtomicNibbleArray

use of org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray in project LanternServer by LanternPowered.

the class AtomicNibbleArrayTest method testPackedArrayConstructor.

@Test
public void testPackedArrayConstructor() {
    byte[] valuesPacked = { B | A << 4, (byte) (C | D << 4), E };
    byte[] values = { B, A, C, D, E };
    AtomicNibbleArray array = new AtomicNibbleArray(values.length, valuesPacked, true);
    assertEquals(array.length(), values.length);
    assertArrayEquals(values, array.getArray());
    assertArrayEquals(valuesPacked, array.getPackedArray());
    for (int i = 0; i < values.length; i++) {
        assertEquals(array.get(i), values[i]);
        array.set(i, (byte) i);
        assertEquals(array.get(i), i);
    }
}
Also used : AtomicNibbleArray(org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray) Test(org.junit.Test)

Example 2 with AtomicNibbleArray

use of org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray in project LanternServer by LanternPowered.

the class AtomicNibbleArrayTest method testGetSet.

@Test
public void testGetSet() {
    AtomicNibbleArray array = new AtomicNibbleArray(SIZE);
    for (int i = 0; i < array.length(); i++) {
        array.set(i, A);
        assertEquals(array.get(i), A);
        array.set(i, B);
        assertEquals(array.get(i), B);
        array.set(i, C);
        assertEquals(array.get(i), C);
    }
}
Also used : AtomicNibbleArray(org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray) Test(org.junit.Test)

Example 3 with AtomicNibbleArray

use of org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray in project LanternServer by LanternPowered.

the class AtomicNibbleArrayTest method testGetAndSet.

@Test
public void testGetAndSet() {
    AtomicNibbleArray array = new AtomicNibbleArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        array.set(i, A);
        assertEquals(A, array.getAndSet(i, B));
        assertEquals(B, array.getAndSet(i, E));
        assertEquals(E, array.getAndSet(i, A));
    }
}
Also used : AtomicNibbleArray(org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray) Test(org.junit.Test)

Example 4 with AtomicNibbleArray

use of org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray in project LanternServer by LanternPowered.

the class AtomicNibbleArrayTest method testCompareAndSet.

@Test
public void testCompareAndSet() {
    AtomicNibbleArray array = new AtomicNibbleArray(SIZE);
    for (int i = 0; i < SIZE; i++) {
        array.set(i, A);
        assertTrue(array.compareAndSet(i, A, B));
        assertTrue(array.compareAndSet(i, B, C));
        assertEquals(C, array.get(i));
        assertFalse(array.compareAndSet(i, D, E));
        assertEquals(C, array.get(i));
        assertTrue(array.compareAndSet(i, C, E));
        assertEquals(E, array.get(i));
    }
}
Also used : AtomicNibbleArray(org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray) Test(org.junit.Test)

Example 5 with AtomicNibbleArray

use of org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray in project LanternServer by LanternPowered.

the class AtomicNibbleArrayTest method testLazyGetSet.

@Test
public void testLazyGetSet() {
    AtomicNibbleArray array = new AtomicNibbleArray(SIZE);
    for (int i = 0; i < array.length(); i++) {
        array.lazySet(i, A);
        assertEquals(array.get(i), A);
        array.lazySet(i, B);
        assertEquals(array.get(i), B);
        array.lazySet(i, C);
        assertEquals(array.get(i), C);
    }
}
Also used : AtomicNibbleArray(org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray) Test(org.junit.Test)

Aggregations

AtomicNibbleArray (org.lanternpowered.server.util.collect.array.concurrent.AtomicNibbleArray)7 Test (org.junit.Test)6 AtomicIntegerArray (java.util.concurrent.atomic.AtomicIntegerArray)1 AtomicByteArray (org.lanternpowered.server.util.collect.array.concurrent.AtomicByteArray)1 AtomicShortArray (org.lanternpowered.server.util.collect.array.concurrent.AtomicShortArray)1