0
想象我有這樣一個類:函數引用的賦值如何進行單元測試?
type TFunctionWrapper<T1,T2> = class
private
FFunc : TFunc<T1,T2>;
public
constructor Create(AFunc : TFunc<T1,T2>);
function Apply(AValue : T1) : T2;
end;
與實施
constructor TFunctionWrapper<T1,T2>.Create(AFunc : TFunc<T1,T2>);
begin
FFunc := AFunc;
end;
function TFunctionWrapper<T1,T2>.Apply(AValue : T1) : T2;
begin
Result := FFunc(AValue);
end;
如何測試,如果分配的功能是一樣的嗎?函數引用不能與F1 = F2
相提並論,因爲它導致一個編譯器錯誤:
[dcc32 Error] Project1.dpr(37): E2035 Not enough actual parameters
,
這使得相當不錯的感覺。
無論如何,問題仍然存在:如何測試是否將函數賦值給字段按預期工作,而不僅僅測試字段和函數是否在相同輸入上返回相同結果?