package ru.istolbov;

import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * Test.
 * @author istolbov
 * @version $Id$
 */
 public class TurnTest {
	 /**
	  * Test turn back array.
	  */
	  @Test
	  public void whenWeTurnBackArray() {
		  final int[] targetArray = new int[] {5, 4, 3, 2, 1};
		  final int[] testArray = new int[] {1, 2, 3, 4, 5};
		  final Turn turn = new Turn();
		  final int[] resultArray = turn.back(testArray);
		  assertThat(resultArray, is(targetArray));
	  }
	  /**
	  * Test sort.
	  */
	  @Test
	  public void whenWeSortArray() {
		  final int[] targetArray = new int[] {1, 2, 3, 4, 5};
		  final int[] testArray = new int[] {5, 3, 4, 1, 2};
		  final Turn turn = new Turn();
		  final int[] resultArray = turn.sort(testArray);
		  assertThat(resultArray, is(targetArray));
	  }
	  /**
	  * Test rotate.
	  */
	  @Test
	  public void whenWeRotateArray() {
		  final int[][] targetArray = new int[][] {{13, 9, 5, 1}, {14, 10, 6, 2}, {15, 11, 7, 3}, {16, 12, 8, 4}};
		  final int[][] testArray = new int[][] {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
		  final Turn turn = new Turn();
		  final int[][] resultArray = turn.rotate(testArray);
		  assertThat(resultArray, is(targetArray));
	  }
	   /**
	  * Test duplicateDelete.
	  */
	  @Test
	  public void whenWeDuplicateDeleteInArray() {
		  final String[] targetArray = new String[] {"Привет", "Мир", "Май"};
		  final String[] testArray = new String[] {"Привет", "Привет", "Мир", "Привет", "Май", "Май", "Мир"};
		  final Turn turn = new Turn();
		  final String[] resultArray = turn.duplicateDelete(testArray);
		  assertThat(resultArray, is(targetArray));
	  }
	  /**
	  * Test join.
	  */
	  @Test
	  public void whenWeJoinArrays() {
		  final int[] firstTestArray = new int[] {1, 3, 5, 7, 9};
		  final int[] secondTestArray = new int[] {2, 4, 6, 8, 10};
		  final int[] targetArray = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
		  final Turn turn = new Turn();
		  final int[] resultArray = turn.join(firstTestArray, secondTestArray);
		  assertThat(resultArray, is(targetArray));
	  }
 }