Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
fix(#1195): fix isin generation
Browse files Browse the repository at this point in the history
  • Loading branch information
pdaulbyscottlogic committed Sep 2, 2019
1 parent c4faec9 commit c01ef5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.scottlogic.deg.common.ValidationException;
import com.scottlogic.deg.generator.utils.RandomNumberGenerator;

import java.util.function.Function;
import java.util.stream.Stream;

public class ChecksumStringGenerator implements StringGenerator {
Expand All @@ -33,19 +34,24 @@ public ChecksumStringGenerator(StringGenerator checksumlessGenerator, ChecksumMa
@Override
public Stream<String> generateAllValues() {
return checksumlessGenerator.generateAllValues()
.map(string -> string + checksumMaker.makeChecksum(string));
.map(addChecksum());
}


@Override
public Stream<String> generateRandomValues(RandomNumberGenerator randomNumberGenerator) {
return checksumlessGenerator.generateRandomValues(randomNumberGenerator)
.map(string -> string + checksumMaker.makeChecksum(string));
.map(addChecksum());
}

@Override
public Stream<String> generateInterestingValues() {
return checksumlessGenerator.generateInterestingValues()
.map(string -> string + checksumMaker.makeChecksum(string));
.map(addChecksum());
}

private Function<String, String> addChecksum() {
return string -> string + checksumMaker.makeChecksum(string);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public MergeResult<StringRestrictions> intersect(StringRestrictions other) {

private MergeResult<StringRestrictions> isLengthAcceptable(TextualRestrictions other) {
if (anyRegexes(other)){
throw new ValidationException("Combining a regex constraint with an " + this.toString() + " constraint is not supported.");
throw new ValidationException("Combining a regex constraint with a " + this.toString() + " constraint is not supported.");
}

StringGenerator intersect = other.createGenerator().intersect(new RegexStringGenerator(type.getRegex(), true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void shouldEndAllSedolsWithValidCheckDigit() {

final Iterator<String> allSedols = target.generateAllValues().iterator();

for (int ii = 0; ii < NumberOfTests; ++ii) {
for (int i = 0; i < NumberOfTests; ++i) {
final String nextSedol = allSedols.next();
final char checkDigit = FinancialCodeUtils.calculateSedolCheckDigit(nextSedol.substring(0, 6));
assertThat(nextSedol.charAt(6), equalTo(checkDigit));
Expand All @@ -53,7 +53,7 @@ public void shouldEndAllRandomCusipsWithValidCheckDigit() {

final Iterator<String> allSedols = target.generateRandomValues(new JavaUtilRandomNumberGenerator()).iterator();

for (int ii = 0; ii < NumberOfTests; ++ii) {
for (int i = 0; i < NumberOfTests; ++i) {
final String nextSedol = allSedols.next();
final char checkDigit = FinancialCodeUtils.calculateSedolCheckDigit(nextSedol.substring(0, 6));
assertThat(nextSedol.charAt(6), equalTo(checkDigit));
Expand Down

0 comments on commit c01ef5a

Please sign in to comment.