Skip to content

Commit

Permalink
Merge pull request eclipse#715 from donraab/master
Browse files Browse the repository at this point in the history
Add test coverage to CharAdapter, CodePointAdapter and CodePointList.
  • Loading branch information
donraab committed Apr 22, 2019
2 parents b9d04e0 + fd03db3 commit 36fd612
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@

package org.eclipse.collections.impl.string.immutable;

import org.eclipse.collections.api.LazyCharIterable;
import org.eclipse.collections.api.bag.primitive.MutableCharBag;
import org.eclipse.collections.api.list.primitive.ImmutableCharList;
import org.eclipse.collections.impl.factory.Strings;
import org.eclipse.collections.impl.factory.primitive.CharBags;
import org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableCharListTestCase;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -114,4 +117,52 @@ public void testToString()
}
Assert.assertEquals(expectedString.toString(), this.classUnderTest().toString());
}

@Test
public void getCharacter()
{
CharAdapter adapter = Strings.asChars("123");
Assert.assertEquals(Character.valueOf('1'), adapter.getCharacter(0));
Assert.assertEquals(Character.valueOf('2'), adapter.getCharacter(1));
Assert.assertEquals(Character.valueOf('3'), adapter.getCharacter(2));
}

@Test
public void toImmutable()
{
CharAdapter adapter = Strings.asChars("123");
ImmutableCharList immutable = adapter.toImmutable();
Assert.assertSame(adapter, immutable);
}

@Test
public void asReversed()
{
CharAdapter adapter = Strings.asChars("123");
LazyCharIterable iterable = adapter.asReversed();
String string = iterable.makeString("");
Assert.assertEquals("321", string);
}

@Test
public void dotProduct()
{
CharAdapter adapter = Strings.asChars("123");
Verify.assertThrows(
UnsupportedOperationException.class,
() -> {
adapter.dotProduct(adapter);
});
}

@Test
public void binarySearch()
{
CharAdapter adapter = Strings.asChars("123");
Verify.assertThrows(
UnsupportedOperationException.class,
() -> {
adapter.binarySearch('2');
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import java.util.stream.Collectors;

import org.eclipse.collections.api.IntIterable;
import org.eclipse.collections.api.LazyIntIterable;
import org.eclipse.collections.api.list.primitive.ImmutableIntList;
import org.eclipse.collections.impl.block.factory.primitive.IntPredicates;
import org.eclipse.collections.impl.factory.Strings;
import org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableIntListTestCase;
import org.eclipse.collections.impl.test.Verify;
import org.junit.Assert;
Expand Down Expand Up @@ -415,6 +417,45 @@ public void primitiveParallelStream()
Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), this.newWith(1, 2, 3, 4, 5).primitiveParallelStream().boxed().collect(Collectors.toList()));
}

@Test
public void toImmutable()
{
CodePointAdapter adapter = Strings.asCodePoints("123");
ImmutableIntList immutable = adapter.toImmutable();
Assert.assertSame(adapter, immutable);
}

@Test
public void asReversed()
{
CodePointAdapter adapter = Strings.asCodePoints("123");
LazyIntIterable iterable = adapter.asReversed();
String string = iterable.collectChar(each -> (char) each).makeString("");
Assert.assertEquals("321", string);
}

@Test
public void dotProduct()
{
CodePointAdapter adapter = Strings.asCodePoints("123");
Verify.assertThrows(
UnsupportedOperationException.class,
() -> {
adapter.dotProduct(adapter);
});
}

@Test
public void binarySearch()
{
CodePointAdapter adapter = Strings.asCodePoints("123");
Verify.assertThrows(
UnsupportedOperationException.class,
() -> {
adapter.binarySearch((int) '2');
});
}

private static class SBAppendable implements Appendable
{
private final StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import java.util.stream.Collectors;

import org.eclipse.collections.api.IntIterable;
import org.eclipse.collections.api.LazyIntIterable;
import org.eclipse.collections.api.list.primitive.ImmutableIntList;
import org.eclipse.collections.api.list.primitive.MutableIntList;
import org.eclipse.collections.impl.block.factory.primitive.IntPredicates;
import org.eclipse.collections.impl.factory.primitive.IntLists;
import org.eclipse.collections.impl.list.immutable.primitive.AbstractImmutableIntListTestCase;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -407,6 +410,40 @@ public void primitiveParallelStream()
Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), CodePointList.from(1, 2, 3, 4, 5).primitiveParallelStream().boxed().collect(Collectors.toList()));
}

@Test
public void toImmutable()
{
CodePointList list = CodePointList.from("123");
ImmutableIntList immutable = list.toImmutable();
Assert.assertSame(list, immutable);
}

@Test
public void asReversed()
{
CodePointList list = CodePointList.from("123");
LazyIntIterable iterable = list.asReversed();
String string = iterable.collectChar(each -> (char) each).makeString("");
Assert.assertEquals("321", string);
}

@Test
public void dotProduct()
{
CodePointList list = CodePointList.from("123");
long actual = list.dotProduct(list);
MutableIntList mutable = IntLists.mutable.with((int) '1', (int) '2', (int) '3');
long expected = mutable.dotProduct(mutable);
Assert.assertEquals(expected, actual);
}

@Test
public void binarySearch()
{
CodePointList list = CodePointList.from("123");
Assert.assertEquals(1, list.binarySearch((int) '2'));
}

private static class SBAppendable implements Appendable
{
private final StringBuilder builder = new StringBuilder();
Expand Down

0 comments on commit 36fd612

Please sign in to comment.