Created
March 17, 2012 23:04
-
-
Save rodrigoamaral/2066224 to your computer and use it in GitHub Desktop.
Dojo @ UFS - 14/03/2012
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import junit.framework.TestCase; | |
| public class PATest extends TestCase { | |
| public ProgressaoAritmetica pa = new ProgressaoAritmetica(); | |
| public void test123() { | |
| ArrayList<int[]> esperado = new ArrayList<int[]>(); | |
| esperado.add(new int[] {1,2,3}); | |
| assertTrue(isArrayEquals(esperado, pa.identificar(new int[] {1,2,3})) ); | |
| } | |
| public void test123_1357() { | |
| ArrayList<int[]> esperado = new ArrayList<int[]>(); | |
| esperado.add(new int[] {1,2,3}); | |
| esperado.add(new int[] {1,3,5,7}); | |
| assertTrue(isArrayEquals(esperado, pa.identificar(new int[] {1,2,3,5,7})) ); | |
| } | |
| public boolean isArrayEquals(ArrayList<int[]> a, ArrayList<int[]> b){ | |
| if (a.size() != b.size()) | |
| return false; | |
| for (int i = 0; i < a.size(); i++) | |
| if (!Arrays.equals(a.get(i),b.get(i))) | |
| return false; | |
| return true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| public class ProgressaoAritmetica { | |
| public ArrayList<int[]> identificar(int[] seq) { | |
| ArrayList<int[]> sequencias = new ArrayList<int[]>(); | |
| if (this.identificarSequenciaSimples(seq) != null) | |
| return sequencias; | |
| } | |
| private ArrayList<Integer> identificarSequenciaSimples(int[] seq) { | |
| ArrayList<Integer> retorno = new ArrayList<Integer>(); | |
| Integer item = seq[0]; | |
| retorno.add(item); | |
| for (int i = 1; i < seq.length; i++) { | |
| if (seq[i] == item +1) { | |
| retorno.add(item); | |
| } | |
| item = seq[i]; | |
| } | |
| if (retorno.size() > 2) | |
| return retorno; | |
| else | |
| return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment