Last active
October 20, 2023 20:28
-
-
Save luissimas/a7071e9f7ba078fb2fdca6ccf61cf0c3 to your computer and use it in GitHub Desktop.
Casos de teste para os exercícios propostos em sala de aula utilizando o framework JUnit 5.
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
/* | |
* | |
* Nome: Luís Augusto Simas do Nascimento. | |
* RA: 790828 | |
*/ | |
package org.example; | |
import org.junit.jupiter.api.AfterEach; | |
import org.junit.jupiter.api.BeforeEach; | |
import org.junit.jupiter.api.Test; | |
import static org.junit.jupiter.api.Assertions.*; | |
class UtilsTest { | |
@Test | |
void testGerarNumeroAleatorioNumeroNoIntervalo() { | |
Utils utils = new Utils(); | |
var res = utils.gerarNumeroAleatorio(1, 10); | |
assertTrue(res >= 1 && res <= 10); | |
} | |
@Test | |
void testGerarNumeroAleatorioForaDoIntervalo() { | |
Utils utils = new Utils(); | |
var res = utils.gerarNumeroAleatorio(-1, 10); | |
assertEquals(res, -1); | |
} | |
@Test | |
void testGerarNumeroAleatorioIntervaloInvalido() { | |
Utils utils = new Utils(); | |
var res = utils.gerarNumeroAleatorio(10, 1); | |
assertEquals(res, -1); | |
} | |
@Test | |
void testAcharCaracterValidaComprimentoNegativo() { | |
Utils utils = new Utils(); | |
var res = utils.acharCaracter(-1, "uma cadeia de caracteres".toCharArray(), 'a'); | |
assertEquals(res, "comprimento invalido"); | |
} | |
@Test | |
void testAcharCaracterValidaComprimentoGrandeDemais() { | |
Utils utils = new Utils(); | |
var res = utils.acharCaracter(21, "uma cadeia de caracteres".toCharArray(), 'c'); | |
assertEquals(res, "comprimento invalido"); | |
} | |
@Test | |
void testAcharCaracterValidaComprimentoDiferenteDaCadeia() { | |
Utils utils = new Utils(); | |
var res = utils.acharCaracter(10, "uma cadeia maior que 10 caracteres".toCharArray(), 'i'); | |
assertEquals(res, "comprimento fornecido diferente do comprimento real"); | |
} | |
@Test | |
void testAcharCaracterRetornaPosicao() { | |
Utils utils = new Utils(); | |
var res = utils.acharCaracter(5, "abcdf".toCharArray(), 'c'); | |
assertEquals(res, "2"); | |
} | |
@Test | |
void testAcharCaracterRetornaCaracterNaoEncontrado() { | |
Utils utils = new Utils(); | |
var res = utils.acharCaracter(5, "abcdf".toCharArray(), 'z'); | |
assertEquals(res, "caracter nao encontrado"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment