예제 #1
0
        public void ThrowsIndexOutOfRange()
        {
            var list = new SimpleArrayList <int>(1);

            list.Add(1);
            list.Add(2);
        }
예제 #2
0
        public void ToStringReturnsOnlySetValues()
        {
            var list = new SimpleArrayList <int>(4);

            list.Add(1);
            list.Add(2);

            Assert.AreEqual("1,2", list.ToString());
        }
예제 #3
0
        public void ToStringReturnsCommaSeparated()
        {
            var list = new SimpleArrayList <int>(2);

            list.Add(1);
            list.Add(2);

            Assert.AreEqual("1,2", list.ToString());
        }
예제 #4
0
        public void CountOccurencesReturnsCorrectNumber()
        {
            var list = new SimpleArrayList <int>(3);

            list.Add(1);
            list.Add(3);
            list.Add(1);

            Assert.AreEqual(2, list.CountOccurences(1));
        }
예제 #5
0
        public void ClearArray()
        {
            var list = new SimpleArrayList <int>(2);

            list.Add(3);
            list.Add(4);

            Assert.AreEqual("3,4", list.ToString());

            list.Clear();

            Assert.AreEqual("", list.ToString());
        }
예제 #6
0
        public void ReturnsDataAtIndex()
        {
            var list = new SimpleArrayList <int>(1);

            list.Add(2);
            Assert.AreEqual(list.Get(0), 2);
        }
예제 #7
0
    // Read an unlimited number of String; return an ArrayList
    public static SimpleArrayList GetStrings( )
    {
        SimpleArrayList array = new SimpleArrayList( );
        string          oneLine;

        Console.WriteLine("Enter any number of strings, one per line; ");
        Console.WriteLine("Terminate with empty line: ");
        try
        {
            while ((oneLine = Console.ReadLine( )) != null && oneLine != "")
            {
                array.Add(oneLine);
            }
        }
        catch (IOException)
        {
            Console.WriteLine("Unexpected IO Exception has shortened amount read");
        }
        Console.WriteLine("Done reading");
        return(array);
    }