/** @(#)TestColinaValle.java 2012 adolfo@di-mare.com Datos de prueba para {@code ColinaValle()}. @author Adolfo Di Mare */ import junit.framework.*; /** Datos de prueba para la rutina {@code ColinaValle()}. */ public class TestColinaValle extends TestCase { /** Retorna cuantos valores a partir de {@code V[i]} son ascendentes. Siempre cuenta {@code V[i]} como posición ascendente y por eso retorna por lo menos 1. Es incorrecto usar un valor de {@code i} fuera del vector. Retorna cero cuando el vector es nulo. */ public static int voySubiendo( int V[], int i ) { if (V==null) { return 0; } if (i<0||i>=V.length) { return 0; } int cantidad = 1; { /******************************\ * * * RELLENE CON SU ALGORITMO * * * \******************************/ } return cantidad; } /** test -> {@code voySubiendo()}. */ public void test_voySubiendo() { { int V[]= {00,10,20,30,-1}; assertTrue( 4 == voySubiendo( V,(0) ) ); } { int V[]= {00,10,20,30,30,60,-1}; assertTrue( 3 == voySubiendo( V,(3) ) ); } { int V[]= {00,-1}; assertTrue( 1 == voySubiendo( V,(0) ) ); } { int V[]= {00}; assertTrue( 1 == voySubiendo( V,(0) ) ); } { int V[]= null; assertTrue( 0 == voySubiendo( V,(0) ) ); } { int V[]= {00,10,20,30,-1}; assertTrue( 4 == voySubiendo( V,(0) ) ); } { int V[]= {00}; assertTrue( 0 == voySubiendo( V,(V.length)) ); } } /** Retorna cuantos valores a partir de {@code V[i]} son descendentes. Siempre cuenta {@code V[i]} como posición descendente y por eso retorna por lo menos 1. Es incorrecto usar un valor de {@code i} fuera del vector. Retorna cero cuando el vector es nulo. */ public static int voyBajando( int V[], int i ) { if (V==null) { return 0; } if (i<0||i>=V.length) { return 0; } int cantidad = 1; { /******************************\ * * * RELLENE CON SU ALGORITMO * * * \******************************/ } return cantidad; } /** test -> {@code voyBajando()}. */ public void test_voyBajando() { { int V[]= {30,20,10,00,+1}; assertTrue( 4 == voyBajando( V,(0) ) ); } { int V[]= {00,10,20,30,30,20,99}; assertTrue( 3 == voyBajando( V,(3) ) ); } { int V[]= {00,+1}; assertTrue( 1 == voyBajando( V,(0) ) ); } { int V[]= {00}; assertTrue( 1 == voyBajando( V,(0) ) ); } { int V[]= null; assertTrue( 0 == voyBajando( V,(0) ) ); } { int V[]= {00}; assertTrue( 0 == voyBajando( V,(V.length) ) ); } } /** Retorna "true" cuando los valores de {@code V[]} primero ascienden * y luego descienden. * Retorna "false" si el vetor es nulo. */ public static boolean soyColina( int V[] ) { if (V==null) { return false; } int subiendo = voySubiendo( V,(0) ); {{ if ( subiendo==0 ) { return false; } }} int bajando = voyBajando( V,(subiendo) ); {{ if ( bajando==0 ) { return false; } }} return ( subiendo+bajando == V.length ); } /** test -> {@code soyColina()}. */ public void test_soyColina() { { int V[]= {00,10,20,30,-1}; assertTrue( soyColina( V ) ); } { int V[]= {00,00,10,20,30,20,10}; assertTrue( soyColina( V ) ); } { int V[]= {00,+1}; assertFalse( soyColina( V ) ); } { int V[]= {00}; assertFalse( soyColina( V ) ); } { int V[]= null; assertFalse( soyColina( V ) ); } } /** Retorna "true" cuando los valores de {@code V[]} primero descienden * y luego ascienden. * Retorna "false" si el vetor es nulo. */ public static boolean soyValle( int V[] ) { if (V==null) { return false; } int bajando = voyBajando( V,(0) ); {{ if ( bajando==0 ) { return false; } }} int subiendo = voySubiendo( V,(bajando) ); {{ if ( subiendo==0 ) { return false; } }} return (subiendo+bajando == V.length ); } /** test -> {@code soyValle()}. */ public void test_soyValle() { { int V[]= {20,10,00,10,20}; assertTrue( soyValle( V ) ); } { int V[]= {30,30,20,10,10,20,30}; assertTrue( soyValle( V ) ); } { int V[]= {00,-1}; assertFalse( soyValle( V ) ); } { int V[]= {00}; assertFalse( soyValle( V ) ); } { int V[]= null; assertFalse( soyValle( V ) ); } } /** Retorna "true" cuando los valores de {@code V[]} primero ascienden * y luego descienden. * Retorna "false" si el vetor es nulo. */ /** Retorna cuantos valores a partir de {@code V[i]} son una secuencia piquitos. * Para que haya piguitos, la secuencia a partir de {@code V[i]} * debe ser primero creciente y luego decreciente, con valores * intercalados inmediatamente. * Es incorrecto usar un valor de {@code i} fuera del vector. * Retorna cero cuando el vector es nulo. */ public static int piquitos( int V[], int i ) { if (V==null) { return 0; } if (i<0||i>=V.length) { return 0; } int cantidad = 1; { /******************************\ * * * RELLENE CON SU ALGORITMO * * * \******************************/ } return cantidad; } /** test -> {@code piquitos()}. */ public void test_piquitos() { { int V[]= {1,2,1,2,1,2,1}; assertTrue( piquitos( V,(0) ) == V.length ); } { int V[]= {2}; assertTrue( piquitos( V,(0) ) == 1 ); } { int V[]= {1,2,3,4,5,6,7}; assertTrue( piquitos( V,(0) ) == 2 ); } { int V[]= {1,2,3,4,3,2,1}; assertTrue( piquitos( V,(0) ) == 2 ); } { int V[]= {2,1,2,1,2,1,2}; assertTrue( piquitos( V,((0)) ) == 1 ); } { int V[]= {2,2,1,2,1,2,1}; assertTrue( piquitos( V,((1)) ) == 1 ); } { int V[]= {1,2,1,2,1,2,1}; assertTrue( piquitos( V,((2)) ) == 5 ); } } } // EOF: TestColinaValle.java