Skip to content

Commit

Permalink
. r Parse2Inputs to always return a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed Feb 26, 2024
1 parent ef1be47 commit 7717338
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ void testWithTypesTransformersAndBoth()
1,3.3 -> 3.3
""";
ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll(t -> t.getFirst() * t.getSecond());
ParseInput.from(expected).withTypes(Integer.class, Double.class).verifyAll((i,d) -> i * d);
ParseInput.from(expected).transformTo(Integer::parseInt, Double::parseDouble).verifyAll(t -> t.getFirst() * t.getSecond());












// ParseInput.from(expected).withTypes(String.class).transformTo(Integer::parseInt)
// .verifyAll(Integer::toBinaryString);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public void verifyAll(Function1<OUT, Object> transform)
Approvals.verifyAll("", parse(), s -> print(s.getFirst(), transform.call(s.getSecond())),
new Options().inline(expected));
}
public <T1, T2> ParseInputWith2Parameters<T1, T2, Tuple<T1, T2>> withTypes(Class<T1> type1, Class<T2> type2)
public <T1, T2> ParseInputWith2Parameters<T1, T2> withTypes(Class<T1> type1, Class<T2> type2)
{
return ParseInputWith2Parameters.create(expected, getTransformerForClass(type1),
getTransformerForClass(type2));
}
public <T1, T2> ParseInputWith2Parameters<T1, T2, Tuple<T1, T2>> transformTo(Function1<String, T1> transformer1,
public <T1, T2> ParseInputWith2Parameters<T1, T2> transformTo(Function1<String, T1> transformer1,
Function1<String, T2> transformer2)
{
return ParseInputWith2Parameters.create(expected, transformer1, transformer2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import com.spun.util.Tuple;
import org.lambda.functions.Function1;
import org.lambda.functions.Function2;
import org.lambda.query.Queryable;

public class ParseInputWith2Parameters<IN1, IN2, OUT>
public class ParseInputWith2Parameters<IN1, IN2>
{
private final String expected;
private final Function1<String, OUT> transformer;
public ParseInputWith2Parameters(String expected, Function1<String, OUT> transformer)
private final Function1<String, Tuple<IN1, IN2>> transformer;
public ParseInputWith2Parameters(String expected, Function1<String, Tuple<IN1, IN2>> transformer)
{
this.expected = expected;
this.transformer = transformer;
}

public static <IN1, IN2> ParseInputWith2Parameters<IN1, IN2, Tuple<IN1, IN2>> create(String expected,
public static <IN1, IN2> ParseInputWith2Parameters<IN1, IN2> create(String expected,
Function1<String, IN1> t1, Function1<String, IN2> t2)
{
Function1<String, Tuple<IN1, IN2>> f = s -> {
Expand All @@ -25,13 +25,16 @@ public static <IN1, IN2> ParseInputWith2Parameters<IN1, IN2, Tuple<IN1, IN2>> cr
};
return new ParseInputWith2Parameters<>(expected, f);
}
// public <OUT2> ParseInputWith2Parameters<OUT2> transformTo(Function1<IN1, OUT2> transformer1)
// {
// Function1<String, OUT2> transformer2 = (String t) -> transformer1.call(transformer.call(t));
// return new ParseInputWith2Parameters<>(expected, transformer2);
// }
public void verifyAll(Function1<OUT, Object> transform)
public void verifyAll(Function1<Tuple<IN1, IN2>, Object> transform)
{
getParseInput().verifyAll(transform);
}
public void verifyAll(Function2<IN1, IN2, Object> transform)
{
getParseInput().verifyAll((t) -> transform.call(t.getFirst(), t.getSecond()));
}
private ParseInput<Tuple<IN1, IN2>> getParseInput()
{
new ParseInput<OUT>(expected, s -> new Tuple<>(s, transformer.call(s))).verifyAll(transform);
return new ParseInput<>(expected, s -> new Tuple<>(s, transformer.call(s)));
}
}

0 comments on commit 7717338

Please sign in to comment.