import "copyright.stg"
import "primitiveLiteral.stg"

isTest() ::= "true"

targetPath() ::= "org/eclipse/collections/impl/list/immutable/primitive"

fileName(primitive) ::= "Immutable<primitive.name>SingletonListTest"

class(primitive) ::= <<
<body(primitive.type, primitive.wrapperName, primitive.name)>
>>

body(type, wrapperName, name) ::= <<
<copyright()>

package org.eclipse.collections.impl.list.immutable.primitive;

import org.eclipse.collections.api.list.primitive.Immutable<name>List;
import org.eclipse.collections.impl.factory.primitive.<name>Lists;
import org.eclipse.collections.impl.math.Mutable<wrapperName>;
import org.junit.Assert;
import org.junit.Test;

/**
 * JUnit test for {@link Immutable<name>SingletonList}.
 * This file was automatically generated from template file immutablePrimitiveSingletonListTest.stg.
 */
public class Immutable<name>SingletonListTest extends AbstractImmutable<name>ListTestCase
{
    @Override
    protected Immutable<name>List classUnderTest()
    {
        return <name>Lists.immutable.of(<(literal.(type))("1")>);
    }

    @Override
    @Test
    public void testEquals()
    {
        super.testEquals();
        Assert.assertNotEquals(this.newWith(<(literal.(type))("1")>), this.newWith());
    }

    @Test
    public void dotProduct()
    {
        Immutable<name>SingletonList list1 = new Immutable<name>SingletonList(<(literal.(type))("3")>);
        Immutable<name>SingletonList list2 = new Immutable<name>SingletonList(<(literal.(type))("3")>);
        Assert.assertEquals(<(wideLiteral.(type))("9")>, list1.dotProduct(list2)<(wideDelta.(type))>);
    }

    @Test(expected = IllegalArgumentException.class)
    public void dotProduct_throwsOnListsOfDifferentSizes()
    {
        Immutable<name>ArrayList list = Immutable<name>ArrayList.newListWith(<["1", "2"]:(literal.(type))(); separator=", ">);
        this.classUnderTest().dotProduct(list);
    }

    @Override
    @Test
    public void injectInto()
    {
        super.injectInto();

        Immutable<name>SingletonList iterable = new Immutable<name>SingletonList(<(literal.(type))("1")>);
        Mutable<wrapperName> result = iterable.injectInto(new Mutable<wrapperName>(<(literal.(type))("1")>), Mutable<wrapperName>::add);
        Assert.assertEquals(new Mutable<wrapperName>(<(literal.(type))("2")>), result);
    }

    @Override
    @Test
    public void injectIntoWithIndex()
    {
        Immutable<name>List list1 = this.newWith(<["1"]:(literal.(type))(); separator=", ">);
        Immutable<name>List list2 = this.newWith(<["1", "2", "3"]:(literal.(type))(); separator=", ">);
        Mutable<wrapperName> result = list1.injectIntoWithIndex(new Mutable<wrapperName>(<(literal.(type))("0")>), (Mutable<wrapperName> object, <type> value, int index) -> object.add(<(castIntToNarrowTypeWithParens.(type))("value * list2.get(index)")>));
        Assert.assertEquals(new Mutable<wrapperName>(<(literal.(type))("1")>), result);
    }

    @Override
    @Test
    public void toReversed()
    {
        Assert.assertEquals(<name>Lists.immutable.of(<(literal.(type))("1")>), this.classUnderTest().toReversed());
    }

    @Override
    @Test
    public void forEachWithIndex()
    {
        <wideType.(type)>[] sum = new <wideType.(type)>[1];
        this.classUnderTest().forEachWithIndex((<type> each, int index) -> sum[0] += each + index);

        Assert.assertEquals(1, sum[0], <(literal.(type))("0")>);
    }

    @Test
    public void binarySearch()
    {
        Assert.assertEquals(-1, this.classUnderTest().binarySearch(<(literal.(type))("0")>));
        Assert.assertEquals(0, this.classUnderTest().binarySearch(<(literal.(type))("1")>));
        Assert.assertEquals(-2, this.classUnderTest().binarySearch(<(literal.(type))("5")>));
    }
}

>>
