Skip to content

Commit

Permalink
Add unit-tests for IntMap builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sarveswaran-m committed Oct 13, 2023
1 parent 3f1f844 commit 2cd8f2a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.trivago.fastutilconcurrentwrapper;

import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingIntFloatMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongFloatMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentIntFloatMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongFloatMap;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConcurrentIntFloatMapBuilderTest {
private final float DEFAULT_VALUE = -1f;

@Test
public void simpleBuilderTest() {
public void buildsBusyWaitingMap() {
ConcurrentIntFloatMapBuilder b = ConcurrentIntFloatMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentIntFloatMapBuilder.MapMode.BUSY_WAITING)
.withLoadFactor(0.8f);
Expand All @@ -18,14 +26,17 @@ public void simpleBuilderTest() {

map.put(1, 10.1f);
float v = map.get(1);

assertTrue(map instanceof ConcurrentBusyWaitingIntFloatMap);
assertEquals(10.1f, v);
assertEquals(map.get(2), map.getDefaultValue());
}

@Test
public void simpleBuilderTest0() {
public void buildsBlockingMap() {
ConcurrentIntFloatMapBuilder b = ConcurrentIntFloatMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentIntFloatMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.8f);
Expand All @@ -34,21 +45,9 @@ public void simpleBuilderTest0() {

map.put(1, 10.1f);
float v = map.get(1);
assertEquals(10.1f, v);
}

@Test
public void defValueTest() {
ConcurrentIntFloatMapBuilder b = ConcurrentIntFloatMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(10.22f)
.withInitialCapacity(100)
.withMode(ConcurrentIntFloatMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.8f);

IntFloatMap map = b.build();

float v = map.get(1);
assertEquals(10.22f, v);
assertTrue(map instanceof ConcurrentIntFloatMap);
assertEquals(10.1f, v);
assertEquals(map.get(2), map.getDefaultValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.trivago.fastutilconcurrentwrapper;

import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingIntIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentIntIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongIntMap;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConcurrentIntIntMapBuilderTest {
private final int DEFAULT_VALUE = -1;

@Test
public void simpleBuilderTest() {
public void buildsBusyWaitingMap() {
ConcurrentIntIntMapBuilder b = ConcurrentIntIntMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentIntIntMapBuilder.MapMode.BUSY_WAITING)
.withLoadFactor(0.8f);
Expand All @@ -18,14 +25,17 @@ public void simpleBuilderTest() {

map.put(1, 10);
float v = map.get(1);

assertTrue(map instanceof ConcurrentBusyWaitingIntIntMap);
assertEquals(10, v);
assertEquals(map.get(2), map.getDefaultValue());
}

@Test
public void simpleBuilderTest0() {
public void buildsBlockingMap() {
ConcurrentIntIntMapBuilder b = ConcurrentIntIntMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentIntIntMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.8f);
Expand All @@ -34,21 +44,9 @@ public void simpleBuilderTest0() {

map.put(1, 10);
float v = map.get(1);
assertEquals(10, v);
}

@Test
public void defValueTest() {
ConcurrentIntIntMapBuilder b = ConcurrentIntIntMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(20)
.withInitialCapacity(100)
.withMode(ConcurrentIntIntMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.8f);

IntIntMap map = b.build();

float v = map.get(1);
assertEquals(20, v);
assertTrue(map instanceof ConcurrentIntIntMap);
assertEquals(10, v);
assertEquals(map.get(2), map.getDefaultValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.trivago.fastutilconcurrentwrapper;

import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongFloatMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongFloatMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongIntMap;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConcurrentLongFloatMapBuilderTest {
private final float DEFAULT_VALUE = -1f;

@Test
public void simpleBuilderTest() {
public void buildsBusyWaitingMap() {
ConcurrentLongFloatMapBuilder b = ConcurrentLongFloatMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentLongFloatMapBuilder.MapMode.BUSY_WAITING)
.withLoadFactor(0.8f);
Expand All @@ -18,14 +25,17 @@ public void simpleBuilderTest() {

map.put(1L, 10.1f);
float v = map.get(1L);

assertTrue(map instanceof ConcurrentBusyWaitingLongFloatMap);
assertEquals(10.1f, v);
assertEquals(map.get(2L), map.getDefaultValue());
}

@Test
public void simpleBuilderTest0() {
public void buildsBlockingMap() {
ConcurrentLongFloatMapBuilder b = ConcurrentLongFloatMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentLongFloatMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.8f);
Expand All @@ -34,21 +44,9 @@ public void simpleBuilderTest0() {

map.put(1L, 10.1f);
float v = map.get(1L);
assertEquals(10.1f, v);
}

@Test
public void defaultValueTest() {
ConcurrentLongFloatMapBuilder b = ConcurrentLongFloatMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(22.22f)
.withInitialCapacity(100)
.withMode(ConcurrentLongFloatMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.8f);

LongFloatMap map = b.build();

float v = map.get(1L);
assertEquals(22.22f, v);
assertTrue(map instanceof ConcurrentLongFloatMap);
assertEquals(10.1f, v);
assertEquals(map.get(2L), map.getDefaultValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.trivago.fastutilconcurrentwrapper;

import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongIntMap;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConcurrentLongIntMapBuilderTest {
private final int DEFAULT_VALUE = -1;

@Test
public void buildsBusyWaitingMap() {
ConcurrentLongIntMapBuilder b = ConcurrentLongIntMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentLongIntMapBuilder.MapMode.BUSY_WAITING)
.withLoadFactor(0.9f);

LongIntMap map = b.build();

map.put(1L, 10);
int v = map.get(1L);

assertTrue(map instanceof ConcurrentBusyWaitingLongIntMap);
assertEquals(10, v);
assertEquals(map.get(2L), map.getDefaultValue());
}

@Test
public void buildsBlockingMap() {
ConcurrentLongIntMapBuilder b = ConcurrentLongIntMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentLongIntMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.9f);

LongIntMap map = b.build();

map.put(1L, 10);
long v = map.get(1L);

assertTrue(map instanceof ConcurrentLongIntMap);
assertEquals(10, v);
assertEquals(map.get(2L), map.getDefaultValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package com.trivago.fastutilconcurrentwrapper;

import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingIntIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongLongMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongIntMap;
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongLongMap;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ConcurrentLongLongMapBuilderTest {
private final long DEFAULT_VALUE = -1L;

@Test
public void simpleBuilderTest() {
ConcurrentLongLongMapBuilder b = ConcurrentLongLongMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentLongLongMapBuilder.MapMode.BUSY_WAITING)
.withLoadFactor(0.9f);
Expand All @@ -19,14 +26,17 @@ public void simpleBuilderTest() {

map.put(1L, 10L);
long v = map.get(1L);

assertTrue(map instanceof ConcurrentBusyWaitingLongLongMap);
assertEquals(10L, v);
assertEquals(map.get(2L), map.getDefaultValue());
}

@Test
public void simpleBuilderTest0() {
public void buildsBlockingMap() {
ConcurrentLongLongMapBuilder b = ConcurrentLongLongMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(0)
.withDefaultValue(DEFAULT_VALUE)
.withInitialCapacity(100)
.withMode(ConcurrentLongLongMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.9f);
Expand All @@ -35,21 +45,9 @@ public void simpleBuilderTest0() {

map.put(1L, 10L);
long v = map.get(1L);
assertEquals(10L, v);
}

@Test
public void defaultValueTest() {
ConcurrentLongLongMapBuilder b = ConcurrentLongLongMapBuilder.newBuilder()
.withBuckets(2)
.withDefaultValue(10L)
.withInitialCapacity(100)
.withMode(ConcurrentLongLongMapBuilder.MapMode.BLOCKING)
.withLoadFactor(0.9f);

LongLongMap map = b.build();

long v = map.get(1L);
assertTrue(map instanceof ConcurrentLongLongMap);
assertEquals(10L, v);
assertEquals(map.get(2L), map.getDefaultValue());
}
}

0 comments on commit 2cd8f2a

Please sign in to comment.