Skip to content
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

Add : JUnit test for CompositeCodePoints and BooleanArrayConstraints #365

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -43,6 +43,18 @@ public BooleanArrayConstraint<T> contains(boolean v) {
return this;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @since 0.14.0

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please run ./mvnw formatter:format to format the source code

public BooleanArrayConstraint<T> onlyContains(boolean v){
this.predicates().add(ConstraintPredicate.of(x -> {
for(boolean e : x){
if(e != v)
return false;
}
return true;
},ARRAY_CONTAINS,() -> new Object[]{v},VALID));
return this;
}


@Override
protected ToIntFunction<boolean[]> size() {
return x -> x.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ else if (points instanceof CodePointsRanges) {
}
}



@Override
public Set<Integer> allExcludedCodePoints(E s) {
Set<Integer> excluded = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package am.ik.yavi.constraint.array;

import org.junit.jupiter.api.Test;

import java.util.function.Predicate;

import static org.assertj.core.api.Assertions.assertThat;

public class BooleanArrayConstraintTest {

private BooleanArrayConstraint<boolean[]> constraint = new BooleanArrayConstraint<>();

@Test
void containsTest(){
Predicate<boolean[]> predicate = constraint.contains(true).predicates().peekFirst().predicate();
assertThat(predicate.test(new boolean[]{true,false})).isTrue();
assertThat(predicate.test(new boolean[]{false,false})).isFalse();
}

@Test
void onlyContainsTest(){
Predicate<boolean[]> predicate = constraint.onlyContains(true).predicates().peekFirst().predicate();
assertThat(predicate.test(new boolean[]{true,true,true})).isTrue();
assertThat(predicate.test(new boolean[]{true,true,false})).isFalse();
}

@Test
void sizeTestFailed(){
Predicate<boolean[]> predicate = constraint.fixedSize(3).predicates().peekFirst().predicate();
assertThat(predicate.test(new boolean[]{true,true})).isFalse();
}

@Test
void sizeTestPass(){
Predicate<boolean[]> predicate = constraint.fixedSize(3).predicates().peekFirst().predicate();
assertThat(predicate.test(new boolean[]{true,true,true})).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static am.ik.yavi.constraint.charsequence.codepoints.UnicodeCodePoints.HIRAGANA;
import static am.ik.yavi.constraint.charsequence.codepoints.UnicodeCodePoints.KATAKANA;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import am.ik.yavi.constraint.charsequence.CodePoints;
import am.ik.yavi.constraint.charsequence.CodePoints.CodePointsSet;
Expand All @@ -44,6 +45,27 @@ void codePointRange() {
assertThat(codePoints.allExcludedCodePoints("あいアイEF")).contains(0x0045, 0x0046);
}

@Test
void checkCodePointRange(){

CodePoints.CodePointsRanges<String> cp = () -> Arrays.asList(
CodePoints.Range.of('A','D'));

CodePoints<String> codePoints = new CompositeCodePoints<>(cp);
assertThat(codePoints.allExcludedCodePoints("ABCD")).isEmpty();
assertThat(codePoints.allExcludedCodePoints("EF")).contains(0x0045, 0x0046);
assertThat(codePoints.allExcludedCodePoints("CDE")).contains(0x0045);
}

@Test
void checkEmptyCompositeCodePoints()
{
assertThrows(IllegalArgumentException.class, () -> {
CodePoints<String> codePoints = new CompositeCodePoints<>();
}, "No code point is included");

}

@Test
void codePointsSet() {
CodePointsSet<String> cp1 = () -> new LinkedHashSet<>(
Expand Down