package uk.co.nickthecoder.feather.runtime;
import org.junit.Test;
import java.util.*;
import static junit.framework.TestCase.*;
public class TestFeatherCollections {
@Test
public void stringSize() {
assertEquals(0, FeatherCollections.size(""));
assertEquals(1, FeatherCollections.size("H"));
assertEquals(5, FeatherCollections.size("Hello"));
}
@Test
public void charSequence() {
Iterator<Character> iterator = FeatherCollections.iterator("Hi");
assertTrue(iterator.hasNext());
assertEquals('H', iterator.next().charValue());
assertTrue(iterator.hasNext());
assertEquals('i', iterator.next().charValue());
assertFalse(iterator.hasNext());
Iterator<Character> empty = FeatherCollections.iterator("");
assertFalse(empty.hasNext());
}
@Test
public void arrayOfBoolean() {
boolean[] a = FeatherCollections.boolArrayOf(true, false, true);
assertTrue(a.getClass().isArray());
assertEquals(boolean.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(booleanArrayOf(true, false, true).toList(), a.toList());
}
@Test
public void arrayOfByte() {
byte[] a = FeatherCollections.byteArrayOf((byte) 3, (byte) 1, (byte) 2);
assertTrue(a.getClass().isArray());
assertEquals(byte.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(byteArrayOf(3, 1, 2).toList(), a.toList())
}
@Test
public void arrayOfChar() {
char[] a = FeatherCollections.charArrayOf('c', 'a', 'b');
assertTrue(a.getClass().isArray());
assertEquals(char.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(charArrayOf('c', 'a', 'b').toList(), a.toList())
}
@Test
public void arrayOfShort() {
short[] a = FeatherCollections.shortArrayOf((short) 3, (short) 1, (short) 2);
assertTrue(a.getClass().isArray());
assertEquals(short.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(shortArrayOf(3, 1, 2).toList(), a.toList())
}
@Test
public void arrayOfInt() {
int[] a = FeatherCollections.intArrayOf(1, 3, 2);
assertTrue(a.getClass().isArray());
assertEquals(int.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(intArrayOf(1, 3, 2).toList(), a.toList())
}
@Test
public void arrayOfLong() {
long[] a = FeatherCollections.longArrayOf(1L, 3L, 2L);
assertTrue(a.getClass().isArray());
assertEquals(long.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(longArrayOf(1, 3, 2).toList(), a.toList())
}
@Test
public void arrayOfFloat() {
float[] a = FeatherCollections.floatArrayOf(1f, 3f, 2f);
assertTrue(a.getClass().isArray());
assertEquals(float.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(floatArrayOf(1f, 3f, 2f).toList(), a.toList())
}
@Test
public void arrayOfDouble() {
double[] a = FeatherCollections.doubleArrayOf(1.0, 3.0, 2.0);
assertTrue(a.getClass().isArray());
assertEquals(double.class, a.getClass().getComponentType());
// Grr. We can't compare arrays directly, so convert them to lists.
//assertEquals(doubleArrayOf(1.0, 3.0, 2.0).toList(), a.toList())
}
@Test
public void arrayOfStrings() {
String[] a = FeatherCollections.arrayOf("Hello", "World");
assertTrue(a.getClass().isArray());
assertEquals(String.class, a.getClass().getComponentType());
//assertEquals(listOf("Hello", "World"), a.toList())
}
@Test
public void listOfStrings() {
List<String> a = FeatherCollections.listOf("Hello", "World");
assertEquals(ArrayList.class, a.getClass());
//assertEquals(listOf("Hello", "World"), a)
}
@Test
public void setOfStrings() {
Set<String> a = FeatherCollections.setOf("Hello", "World", "Hello");
assertEquals(HashSet.class, a.getClass());
//assertEquals(setOf("Hello", "World"), a);
}
@Test
public void mapOf() {
Map<Character, String> map = FeatherCollections.mapOf(new FPair<>('a', "Apple"), new FPair<>('b', "Banana"));
assertEquals(HashMap.class, map.getClass());
assertEquals("Apple", map.get('a'));
assertEquals("Banana", map.get('b'));
Map<Character, String> emptyMap = FeatherCollections.mapOf();
assertTrue(emptyMap.isEmpty());
}
/* 'to' is no longer used?
@Test
public void to() {
FPair<Character, String> pair = FeatherCollections.to('a', "Apple");
assertEquals(FPair.class, pair.getClass());
assertEquals(pair.first.charValue(), 'a');
assertEquals(pair.second, "Apple");
}
*/
@Test
public void toArray() {
String[] a = FeatherCollections.toArray(String.class, Arrays.asList("Hello", "World"));
assertTrue(a.getClass().isArray());
assertEquals(String.class, a.getClass().getComponentType());
}
@Test
public void toBoolArray() {
boolean[] a = FeatherCollections.toBoolArray(Arrays.asList(true, false, true));
assertTrue(a.getClass().isArray());
assertEquals(boolean.class, a.getClass().getComponentType());
//assertEquals(listOf(true, false, true), a.toList())
}
@Test
public void toCharArray() {
char[] a = FeatherCollections.toCharArray(Arrays.asList('b', 'd', 'a'));
assertTrue(a.getClass().isArray());
assertEquals(char.class, a.getClass().getComponentType());
//assertEquals(listOf('b', 'd', 'a'), a.toList())
}
@Test
public void toByteArray() {
byte[] a = FeatherCollections.toByteArray(Arrays.asList((byte) 1, (byte) 3, (byte) 2));
assertTrue(a.getClass().isArray());
assertEquals(byte.class, a.getClass().getComponentType());
//assertEquals(listOf < Byte > (1, 3, 2), a.toList())
}
@Test
public void toShortArray() {
short[] a = FeatherCollections.toShortArray(Arrays.asList((short) 1, (short) 3, (short) 2));
assertTrue(a.getClass().isArray());
assertEquals(short.class, a.getClass().getComponentType());
//assertEquals(listOf < Short > (1, 3, 2), a.toList())
}
@Test
public void toIntArray() {
int[] a = FeatherCollections.toIntArray(Arrays.asList(1, 3, 2));
assertTrue(a.getClass().isArray());
assertEquals(int.class, a.getClass().getComponentType());
//assertEquals(listOf(1, 3, 2), a.toList())
}
@Test
public void toLongArray() {
long[] a = FeatherCollections.toLongArray(Arrays.asList(1L, 3L, 2L));
assertTrue(a.getClass().isArray());
assertEquals(long.class, a.getClass().getComponentType());
//assertEquals(listOf(1L, 3L, 2L), a.toList())
}
@Test
public void toFloatArray() {
float[] a = FeatherCollections.toFloatArray(Arrays.asList(1f, 3f, 2f));
assertTrue(a.getClass().isArray());
assertEquals(float.class, a.getClass().getComponentType());
//assertEquals(listOf(1f, 3f, 2f), a.toList())
}
@Test
public void toDoubleArray() {
double[] a = FeatherCollections.toDoubleArray(Arrays.asList(1.0, 3.0, 2.0));
assertTrue(a.getClass().isArray());
assertEquals(double.class, a.getClass().getComponentType());
//assertEquals(listOf(1.0, 3.0, 2.0), a.toList())
}
}