New Test-Startegy

This commit is contained in:
Michael Schimmel
2025-07-22 17:21:59 +02:00
parent c530f2fc0b
commit e6d41260f9
6 changed files with 311 additions and 42 deletions
+48
View File
@@ -89,6 +89,15 @@ type
constructor Create(const AFunc: TConstFunc<S, T>);
end;
TMycGenericAggregator<S, T> = class(TMycConverter<S, T>)
private
FFunc: TConstFunc<S, TConverter<S, T>.TBroadcastProc, TState>;
protected
function ProcessData(const Value: S): TState; override;
public
constructor Create(const AFunc: TConstFunc<S, TConverter<S, T>.TBroadcastProc, TState>);
end;
TMycGenericParallelConverter<S, T> = class(TMycConverter<S, T>)
private
FFunc: TConstFunc<S, T>;
@@ -235,6 +244,17 @@ type
property Sender: TMycContainedDataProvider<TArray<T>> read FSender implements TDataProvider<TArray<T>>.IDataProvider;
end;
TMycComposedConverter<S, T> = class(TMycProcessor<S>, TConverter<S, T>.IConverter)
private
FProcessor: IMycProcessor<S>;
FDataProvider: TDataProvider<T>;
protected
function ProcessData(const Value: S): TState; override;
function GetSender: TDataProvider<T>.IDataProvider;
public
constructor Create(const AProcessor: IMycProcessor<S>; const ADataProvider: TDataProvider<T>);
end;
implementation
uses
@@ -892,4 +912,32 @@ begin
FSender.Broadcast(Arr);
end;
constructor TMycGenericAggregator<S, T>.Create(const AFunc: TConstFunc<S, TConverter<S, T>.TBroadcastProc, TState>);
begin
inherited Create;
FFunc := AFunc;
end;
function TMycGenericAggregator<S, T>.ProcessData(const Value: S): TState;
begin
Result := FFunc(Value, function(const Value: T): TState begin Result := FSender.Broadcast(Value); end);
end;
constructor TMycComposedConverter<S, T>.Create(const AProcessor: IMycProcessor<S>; const ADataProvider: TDataProvider<T>);
begin
inherited Create;
FProcessor := AProcessor;
FDataProvider := ADataProvider;
end;
function TMycComposedConverter<S, T>.GetSender: TDataProvider<T>.IDataProvider;
begin
Result := FDataProvider;
end;
function TMycComposedConverter<S, T>.ProcessData(const Value: S): TState;
begin
Result := FProcessor.ProcessData(Value);
end;
end.
+14
View File
@@ -67,6 +67,8 @@ type
property Sender: TDataProvider<T>.IDataProvider read GetSender;
end;
TBroadcastProc = reference to function(const Value: T): TState;
strict private
class var
FNull: IConverter;
@@ -82,7 +84,9 @@ type
class operator Implicit(const A: IConverter): TConverter<S, T>; overload;
class operator Implicit(const A: TConverter<S, T>): IConverter; overload;
class function Construct(const Processor: IMycProcessor<S>; const DataProvider: TDataProvider<T>): TConverter<S, T>; static;
class function CreateGeneric(const Func: TConstFunc<S, T>): TConverter<S, T>; static;
class function CreateAggregation(const Func: TConstFunc<S, TBroadcastProc, TState>): TConverter<S, T>; static;
class function CreateParallel(const Func: TConstFunc<S, T>): TConverter<S, T>; static;
function Chain<R>(const Next: TConverter<T, R>): TConverter<T, R>; overload; inline;
@@ -221,6 +225,16 @@ begin
Result := Chain<R>(TMycGenericParallelConverter<T, R>.Create(Func));
end;
class function TConverter<S, T>.Construct(const Processor: IMycProcessor<S>; const DataProvider: TDataProvider<T>): TConverter<S, T>;
begin
Result := TMycComposedConverter<S, T>.Create(Processor, DataProvider);
end;
class function TConverter<S, T>.CreateAggregation(const Func: TConstFunc<S, TBroadcastProc, TState>): TConverter<S, T>;
begin
Result := TMycGenericAggregator<S, T>.Create(Func);
end;
class function TConverter<S, T>.CreateGeneric(const Func: TConstFunc<S, T>): TConverter<S, T>;
begin
Result := TMycGenericConverter<S, T>.Create(Func);
+1
View File
@@ -29,6 +29,7 @@ type
end;
TConstFunc<S, T> = reference to function(const Value: S): T;
TConstFunc<S, T, U> = reference to function(const Value1: S; const Value2: T): U;
TConstProc<T> = reference to procedure(const Value: T);
TConstFuncPredicate<S, T> = reference to function(const Value: S; out Res: T): Boolean;