Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IList<T> Tests #10

Open
Grauenwolf opened this issue Jun 2, 2021 · 1 comment
Open

IList<T> Tests #10

Grauenwolf opened this issue Jun 2, 2021 · 1 comment

Comments

@Grauenwolf
Copy link
Owner

Old Version

foreach (var itemType in Class.ListT.Where(t => t.IsCreatable))
{ 

    <text>

	@TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_Add") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        var oldCount = objectUnderTest.Count;
        @itemType.FullName newItem;

        try
        {
            newItem = @itemType.GetConstructorCode();
            objectUnderTest.Add(newItem);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("oldCount + 1", "objectUnderTest.Count")
        @Assert.IsTrue("objectUnderTest.Contains(newItem)")

	}


	@TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_AddClear") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        @itemType.FullName newItem;
        
        try
        {
            newItem = @itemType.GetConstructorCode();
            objectUnderTest.Add(newItem);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            
        @Assert.IsTrue("objectUnderTest.Contains(newItem)")

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")
        @Assert.IsFalse("objectUnderTest.Contains(newItem)")

	}


	@TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_Clear") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;         

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

	}


    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_AddRemove") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        var oldCount = objectUnderTest.Count;
        
        @itemType.FullName newItem;

        try
        {
            newItem = @itemType.GetConstructorCode();
            objectUnderTest.Add(newItem);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("oldCount + 1", "objectUnderTest.Count")
        @Assert.IsTrue("objectUnderTest.Contains(newItem)")

        objectUnderTest.Remove(newItem);
        
        @Assert.AreEqual("oldCount", "objectUnderTest.Count")
        @Assert.IsFalse("objectUnderTest.Contains(newItem)")
	}


    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_AddRemoveAt") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        var oldCount = objectUnderTest.Count;
        @itemType.FullName newItem;

        try
        {
            newItem = @itemType.GetConstructorCode();
            objectUnderTest.Add(newItem);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("oldCount + 1", "objectUnderTest.Count")
        @Assert.IsTrue("objectUnderTest.Contains(newItem)")

        var newIndex = objectUnderTest.IndexOf(newItem);
        objectUnderTest.RemoveAt(newIndex);
        
        @Assert.AreEqual("oldCount", "objectUnderTest.Count")
        @Assert.IsFalse("objectUnderTest.Contains(newItem)")
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_InsertFirst") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var testItem = @itemType.GetConstructorCode();
        objectUnderTest.Insert(0, testItem);

        @Assert.AreEqual("4", "objectUnderTest.Count")
        @Assert.AreEqual("0", "objectUnderTest.IndexOf(testItem)")                     
        @Assert.IsTrue("objectUnderTest.Contains(testItem)")
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_InsertMiddle") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var testItem = @itemType.GetConstructorCode();
        objectUnderTest.Insert(2, testItem);

        @Assert.AreEqual("4", "objectUnderTest.Count")
        @Assert.AreEqual("2", "objectUnderTest.IndexOf(testItem)")                     
        @Assert.IsTrue("objectUnderTest.Contains(testItem)")
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_InsertLast") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var testItem = @itemType.GetConstructorCode();
        objectUnderTest.Insert(3, testItem);

        @Assert.AreEqual("4", "objectUnderTest.Count")
        @Assert.AreEqual("3", "objectUnderTest.IndexOf(testItem)")                     
        @Assert.IsTrue("objectUnderTest.Contains(testItem)")
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_Middle") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[5];

        objectUnderTest.CopyTo(array, 1);

        @Assert.AreEqual(@itemType.DefaultValue, "array[0]");
        @Assert.AreEqual("newItem1", "array[1]");
        @Assert.AreEqual("newItem2", "array[2]");
        @Assert.AreEqual("newItem3", "array[3]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[4]");
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_Front") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[5];

        objectUnderTest.CopyTo(array, 0);

        @Assert.AreEqual("newItem1", "array[0]");
        @Assert.AreEqual("newItem2", "array[1]");
        @Assert.AreEqual("newItem3", "array[2]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[3]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[4]");
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_End") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[5];

        objectUnderTest.CopyTo(array, 2);

        @Assert.AreEqual(@itemType.DefaultValue, "array[0]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[1]");
        @Assert.AreEqual("newItem1", "array[2]");
        @Assert.AreEqual("newItem2", "array[3]");
        @Assert.AreEqual("newItem3", "array[4]");            
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_Full") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[3];

        objectUnderTest.CopyTo(array, 0);

        @Assert.AreEqual("newItem1", "array[0]");
        @Assert.AreEqual("newItem2", "array[1]");
        @Assert.AreEqual("newItem3", "array[2]");
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_TooSmall") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[2];

        try
        {
            objectUnderTest.CopyTo(array, 0);
            @Assert.Fail("\"This should have thrown an exception.\"")
        }
        catch (ArgumentException)
        {
            //OK
        }

        //make sure nothing was over-written
        @Assert.AreEqual(@itemType.DefaultValue, "array[0]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[1]");
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_PastEnd") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[3];

        try
        {
            objectUnderTest.CopyTo(array, 1);
            @Assert.Fail("\"This should have thrown an exception\"")
        }
        catch (ArgumentException)
        {
            //OK
        }

        //make sure nothing was over-written
        @Assert.AreEqual(@itemType.DefaultValue, "array[0]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[1]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[2]");

	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_OOR") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        var array = new @(itemType.FullName)[3];

        try
        {
            objectUnderTest.CopyTo(array, -1);
            @Assert.Fail("\"This should have thrown an exception.\"")
        }
        catch (ArgumentOutOfRangeException)
        {
            //OK
        }

        //make sure nothing was over-written
        @Assert.AreEqual(@itemType.DefaultValue, "array[0]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[1]");
        @Assert.AreEqual(@itemType.DefaultValue, "array[2]");
        
        
	}

    @TestAttribute
    public void @(Test.ClassName + "_ListT_" + itemType.SafeName + "_CopyTo_Null") ()
	{
		IList<@itemType.FullName> objectUnderTest = CreateObject();

		if (objectUnderTest.IsReadOnly)
            return;

        objectUnderTest.Clear();
        @Assert.AreEqual("0", "objectUnderTest.Count")

        @itemType.FullName newItem1;
        @itemType.FullName newItem2;
        @itemType.FullName newItem3;

        try
        {
            newItem1 = @itemType.GetConstructorCode();
            newItem2 = @itemType.GetConstructorCode();
            newItem3 = @itemType.GetConstructorCode();

            objectUnderTest.Add(newItem1);
            objectUnderTest.Add(newItem2);
            objectUnderTest.Add(newItem3);
        }
        catch (ArgumentException)
        {
            //OK
            return;
        }            

        @Assert.AreEqual("3", "objectUnderTest.Count")

        try
        {
            objectUnderTest.CopyTo(null, -1);
            @Assert.Fail("\"This should have thrown an exception.\"")
        }
        catch (ArgumentNullException)
        {
            //OK
        }

	}





    </text>
}
@Grauenwolf
Copy link
Owner Author

We'll want to duplicate this for IReadOnlyList<T>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant