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

feat: Random function: add test and private declaration #1673

Merged
merged 1 commit into from Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -57,7 +57,7 @@ public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0 || nbArg == 1 || nbArg == 2;
}

final Random random = new Random();
private final Random random = new Random();

public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
Expand Down
50 changes: 50 additions & 0 deletions test/net/sourceforge/plantuml/tim/stdlib/RandomFuntionTest.java
@@ -0,0 +1,50 @@
package net.sourceforge.plantuml.tim.stdlib;

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

import java.util.Arrays;
import java.util.Collections;

import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.IndicativeSentencesGeneration;
import org.junit.jupiter.api.RepeatedTest;

import net.sourceforge.plantuml.tim.EaterException;
import net.sourceforge.plantuml.tim.EaterExceptionLocated;
import net.sourceforge.plantuml.tim.TFunction;
import net.sourceforge.plantuml.tim.expression.TValue;

/**
* Tests the builtin function.
*/
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)

class RandomFunctionTest {
TFunction cut = new RandomFunction();
final String cutName = "Random";
final String repetitionLabel = "[{currentRepetition}/{totalRepetitions}] ";

@RepeatedTest(value = 10, name = repetitionLabel + cutName + "()")
void test_with_no_argument() throws EaterException, EaterExceptionLocated {
final TValue tValue = cut.executeReturnFunction(null, null, null, Collections.emptyList(), null);
assertThat(tValue.toInt()).isIn(0, 1);
}

@RepeatedTest(value = 10, name = repetitionLabel + cutName + "(7)")
void test_with_one_argument() throws EaterException, EaterExceptionLocated {
final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(7)), null);
assertThat(tValue.toInt()).isBetween(0, 7-1);
}

@RepeatedTest(value = 10, name = repetitionLabel + cutName + "(0, 7)")
void test_with_two_argument_first_zero() throws EaterException, EaterExceptionLocated {
final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(0), TValue.fromInt(7)), null);
assertThat(tValue.toInt()).isBetween(0, 7-1);
}

@RepeatedTest(value = 10, name = repetitionLabel + cutName + "(3, 7)")
void test_with_two_argument() throws EaterException, EaterExceptionLocated {
final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(3), TValue.fromInt(7)), null);
assertThat(tValue.toInt()).isBetween(3, 7-1);
}
}