Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* pom.xml */
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.epam.automation</groupId>
- <artifactId>Task3</artifactId>
- <version>1.0-SNAPSHOT</version>
- <properties>
- <maven.compiler.source>17</maven.compiler.source>
- <maven.compiler.target>17</maven.compiler.target>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <junit5.version>5.6.2</junit5.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${junit5.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <version>${junit5.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-params</artifactId>
- <version>${junit5.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </project>
- /* HandyClass */
- package com.epam.automation;
- public class HandyClass {
- public static int countMaxUnequalConsecutive(String input){
- int max = 0;
- int current = 1;
- for (int i = 0; i < input.length() - 1; i++) {
- if (input.charAt(i) != input.charAt(i+1)){
- current++;
- } else {
- current = 1;
- }
- if (max < current){
- max = current;
- }
- }
- return max;
- }
- public static int countMaxEqualLatinLettersConsecutive(String input){
- int max = 0;
- int current = 1;
- if (input.matches("[A-Za-z]+")) {
- for (int i = 0; i < input.length() - 1; i++) {
- if (input.charAt(i) == input.charAt(i + 1)) {
- current++;
- } else {
- current = 1;
- }
- if (max < current) {
- max = current;
- }
- }
- } else {
- throw new IllegalArgumentException("Please enter latin letters");
- }
- return max;
- }
- public static int countMaxIdenticalDigitsConsecutive(String input){
- int max = 0;
- int current = 1;
- if(input.matches("[0-9]+")){
- for (int i = 0; i < input.length() - 1; i++) {
- if (input.charAt(i) == input.charAt(i + 1)) {
- current++;
- } else {
- current = 1;
- }
- if (max < current) {
- max = current;
- }
- }
- } else {
- throw new IllegalArgumentException("Please enter digits");
- }
- return max;
- }
- }
- /* Task3Tests */
- package com.epam.automation;
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.*;
- public class Task3Tests {
- @Test
- public void testCountMaxUnequalConsecutive(){
- assertEquals(0, HandyClass.countMaxUnequalConsecutive("a"));
- assertEquals(1, HandyClass.countMaxUnequalConsecutive("aa"));
- assertEquals(6, HandyClass.countMaxUnequalConsecutive("asdfgggsdjflllll"));
- assertEquals(15, HandyClass.countMaxUnequalConsecutive("abcdefbdjuhgdyk"));
- assertEquals(0, HandyClass.countMaxUnequalConsecutive(""));
- }
- @Test
- public void testCountMaxEqualLatinLettersConsecutive(){
- assertEquals(0, HandyClass.countMaxEqualLatinLettersConsecutive("a"));
- assertEquals(2, HandyClass.countMaxEqualLatinLettersConsecutive("aa"));
- assertEquals(5, HandyClass.countMaxEqualLatinLettersConsecutive("asdfgggsdjflllll"));
- assertEquals(1, HandyClass.countMaxEqualLatinLettersConsecutive("abcdefbdjuhgdyk"));
- }
- @Test
- public void testCountMaxEqualLatinLettersConsecutiveShouldThrow(){
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxEqualLatinLettersConsecutive("1223"));
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxEqualLatinLettersConsecutive("абв"));
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxEqualLatinLettersConsecutive("*;?)"));
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxIdenticalDigitsConsecutive(""));
- }
- @Test
- public void testCountMaxIdenticalDigitsConsecutive(){
- assertEquals(0, HandyClass.countMaxIdenticalDigitsConsecutive("1"));
- assertEquals(2, HandyClass.countMaxIdenticalDigitsConsecutive("55"));
- assertEquals(4, HandyClass.countMaxIdenticalDigitsConsecutive("13666638"));
- assertEquals(4, HandyClass.countMaxIdenticalDigitsConsecutive("123444567888868686"));
- assertEquals(1, HandyClass.countMaxIdenticalDigitsConsecutive("1234567890"));
- }
- @Test
- public void testCountMaxIdenticalDigitsConsecutiveShouldThrow(){
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxIdenticalDigitsConsecutive("abc"));
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxIdenticalDigitsConsecutive("абв"));
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxIdenticalDigitsConsecutive("*;?)"));
- assertThrows(IllegalArgumentException.class,
- () -> HandyClass.countMaxIdenticalDigitsConsecutive(""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement