package com.weiwei.algo.test;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.weiwei.algo.study.QuickSort;
import com.weiwei.algo.study.QuickSortItr;
import com.weiwei.algo.util.ArrayUtil;

public class TestSort {

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void testQuickSort() {
        int[] input = { 24, 2, 45, 20, 56, 75, 2, 56, 99, 53, 12 };
        int[] sortedInput = { 2, 2, 12, 20, 24, 45, 53, 56, 56, 75, 99 };
        QuickSort.quickSort(input);
        boolean res = ArrayUtil.compare(input, sortedInput);
        TestCase.assertEquals(true, res);
    }

    @Test
    public void testQuickSort_2() {
        int[] input = { 31, 1 };
        int[] sortedInput = { 1, 31 };
        QuickSort.quickSort(input);
        boolean res = ArrayUtil.compare(input, sortedInput);
        TestCase.assertEquals(true, res);
    }

    @Test
    public void testQuickSortItr() {
        int[] input = { 24, 2, 45, 20, 56, 75, 2, 56, 99, 53, 12 };
        int[] sortedInput = { 2, 2, 12, 20, 24, 45, 53, 56, 56, 75, 99 };
        QuickSortItr.quickSort(input);
        boolean res = ArrayUtil.compare(input, sortedInput);
        TestCase.assertEquals(true, res);
    }

    @Test
    public void testQuickSortItr_2() {
        int[] input = { 31, 1 };
        int[] sortedInput = { 1, 31 };
        QuickSortItr.quickSort(input);
        boolean res = ArrayUtil.compare(input, sortedInput);
        TestCase.assertEquals(true, res);
    }

}
