/*
 * Copyright (C) 2009-2011 Mathias Doenitz
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.parboiled.common;

import org.testng.annotations.Test;

import java.util.Arrays;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class IntArrayStackTest {

    @Test
    public void testIntArrayStack() {
        IntArrayStack stack = new IntArrayStack();
        stack.push(1);
        stack.push(2);
        stack.push(6);

        assertFalse(stack.isEmpty());
        assertEquals(stack.size(), 3);
        assertEquals(stack.peek(), 6);
        assertEquals(stack.pop(), 6);
        assertEquals(stack.size(), 2);

        stack.push(8);
        assertEquals(stack.pop(), 8);
        assertEquals(stack.size(), 2);

        int[] buf = new int[5];
        stack.getElements(buf, 1);
        assertTrue(Arrays.equals(buf, new int[]{ 0, 1, 2, 0, 0 }));

        stack.clear();
        assertEquals(stack.size(), 0);
        assertTrue(stack.isEmpty());
    }

}
