Skip to content

testing: improve test coverage DuplicateBracketsTest #6396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;

class DuplicateBracketsTest {

@ParameterizedTest
@CsvSource({"'((a + b) + (c + d))'", "'(a + b)'", "'a + b'", "'('", "''"})
@CsvSource({"'((a + b) + (c + d))'", "'(a + b)'", "'a + b'", "'('", "''", "'a + (b * c) - d'", "'(x + y) * (z)'", "'(a + (b - c))'"})
void testInputReturnsFalse(String input) {
assertFalse(DuplicateBrackets.check(input));
}

@ParameterizedTest
@CsvSource({"'(a + b) + ((c + d))'", "'((a + b))'", "'((((a + b)))))'"})
@CsvSource({"'(a + b) + ((c + d))'", "'((a + b))'", "'((((a + b)))))'", "'((x))'", "'((a + (b)))'", "'(a + ((b)))'", "'(((a)))'", "'(((())))'"})
void testInputReturnsTrue(String input) {
assertTrue(DuplicateBrackets.check(input));
}
Expand All @@ -26,4 +29,27 @@ void testInputReturnsTrue(String input) {
void testInvalidInput() {
assertThrows(IllegalArgumentException.class, () -> DuplicateBrackets.check(null));
}

@ParameterizedTest(name = "Should be true: \"{0}\"")
@MethodSource("provideInputsThatShouldReturnTrue")
void testDuplicateBracketsTrueCases(String input) {
assertTrue(DuplicateBrackets.check(input));
}

static Stream<Arguments> provideInputsThatShouldReturnTrue() {
return Stream.of(Arguments.of("()"), Arguments.of("(( ))"));
}

@ParameterizedTest(name = "Should be false: \"{0}\"")
@MethodSource("provideInputsThatShouldReturnFalse")
void testDuplicateBracketsFalseCases(String input) {
assertFalse(DuplicateBrackets.check(input));
}

static Stream<Arguments> provideInputsThatShouldReturnFalse() {
return Stream.of(Arguments.of("( )"), // whitespace inside brackets
Arguments.of("abc + def"), // no brackets
Arguments.of("(a + (b * c)) - (d / e)") // complex, but no duplicates
);
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy