package codility.challenges;

import static org.junit.Assert.*;

import org.junit.*;

import codility.generic.Array;
import codility.generic.Maths;


public class MinStepsToSingleValue
{
	@Test
	public void test() {
		assertEquals(0, new MinStepsToSingleValue().solution(new int[] {}));
    	assertEquals(0, new MinStepsToSingleValue().solution(new int[] {1}));
    	assertEquals(0, new MinStepsToSingleValue().solution(new int[] {1,1}));
    	assertEquals(4, new MinStepsToSingleValue().solution(new int[] {1,5}));
    	assertEquals(1, new MinStepsToSingleValue().solution(new int[] {1,2}));
    	assertEquals(4, new MinStepsToSingleValue().solution(new int[] {5,1}));
		assertEquals(0, new MinStepsToSingleValue().solution(new int[] {1,1,1}));
		assertEquals(1, new MinStepsToSingleValue().solution(new int[] {1,2,1}));
		assertEquals(1, new MinStepsToSingleValue().solution(new int[] {1,2,1}));
		assertEquals(1, new MinStepsToSingleValue().solution(new int[] {1,1,2}));
		assertEquals(4, new MinStepsToSingleValue().solution(new int[] {1,1,5}));
		assertEquals(4, new MinStepsToSingleValue().solution(new int[] {5,5,1}));
		assertEquals(4, new MinStepsToSingleValue().solution(new int[] {1,5,2}));
		assertEquals(5, new MinStepsToSingleValue().solution(new int[] {1,6,2}));
	}

	public int solution(int[] a) 
    {
    	int steps = 0;
    	
    	if (a.length < 2) {
    		return 0;
    	}
    	
    	int[] d = Array.calcDiffrerences(a);
    	int maxDifference = Maths.maxAbs(d);
    	for (int i = 0; i < d.length; i++) 
    	{
    		steps = maxDifference;
    	}
    	
    	return steps;
    }
}

@@ -207,18 +207,20 @@
  test() 
+%0A%09
 %7B%0A
-
 %09%09assert
@@ -278,29 +278,29 @@
 int%5B%5D %7B%7D));%0A
+%09
     
-%09
 assertEquals
@@ -353,29 +353,29 @@
 nt%5B%5D %7B1%7D));%0A
+%09
     
-%09
 assertEquals
@@ -430,29 +430,29 @@
 %5B%5D %7B1,1%7D));%0A
+%09
     
-%09
 assertEquals
@@ -507,29 +507,29 @@
 %5B%5D %7B1,5%7D));%0A
+%09
     
-%09
 assertEquals
@@ -588,21 +588,21 @@
 1,2%7D));%0A
+%09
     
-%09
 assertEq
@@ -669,84 +669,8 @@
 ));%0A
-%09%09assertEquals(0, new MinStepsToSingleValue().solution(new int%5B%5D %7B1,1,1%7D));%0A
 %09%09as
@@ -809,32 +809,108 @@
 nt%5B%5D %7B1,2,1%7D));%0A
+%09%09assertEquals(0, new MinStepsToSingleValue().solution(new int%5B%5D %7B1,1,1%7D));%0A
 %09%09assertEquals(1
@@ -1312,18 +1312,12 @@
 a) %0A
-    %7B%0A    
+%09%7B%0A%09
 %09int
@@ -1328,20 +1328,16 @@
 ps = 0;%0A
-    
 %09%0A    %09i
@@ -1577,16 +1577,13 @@
  steps;%0A
-    
+%09
 %7D%0A%7D%0A

Update MinStepsToSingleValue.java