DelFusa Blog 総本山

プログラミングの話題とかです。

NEW | PAGE-SELECT | NEXT

≫ EDIT

スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

| スポンサー広告 | --:-- | comments(-) | trackbacks(-) | TOP↑

≫ EDIT

とうとう完成した拡張For構文(再び)のテストコード


          ,,,,,,,,∧,,∧    
        @′ ミ;゚д゚彡  
        ,;と;,,;;;;;;U;;;;U;;彡;;,,,,     
     、,,;ミ;;          "''''彡'    ガルルルルル


ということで、テストコードです。

鬼テストです。
-----


procedure TForm1.FormCreate(Sender: TObject);
begin
 ReportMemoryLeaksOnShutdown := True;
end;

procedure testfor_;
var
 ReturnString: String;
 value: Integer;
 testI: Integer;
begin

 //通常テスト
 value := 0;
 for_.I := 1; with varI do while to_.I(9) do
 begin
  Assert(loop.I.First = (I = 1));
  Assert(loop.I.Last = (I = 9));

  value := value + I;
 end;
 Assert(value = 45);
 Assert(loop.I.count = 9);
 Assert(loop.I.value = 10);

 value := 0;
 for testI := 1 to 9 do
 begin
  value := value + testI;
 end;
 Assert(value = 45);
 Assert(testI = 10);

 //0からスタートテスト
 value := 0;
 for_.I := 0; with varI do while to_.I(10) do
 begin
  Assert(loop.I.First = (I = 0));
  Assert(loop.I.Last = (I = 10));

  value := value + I;
 end;
 Assert(55 = value);
 Assert(loop.I.count = 11);
 Assert(loop.I.value = 11);

 //1回だけループテスト
 value := 0;
 for_.I := 0; with varI do while to_.I(0) do
 begin
  Assert(loop.I.First = (I = 0));
  Assert(loop.I.Last = (I = 0));

  value := value + I;
 end;
 Assert(value = 0);
 Assert(loop.I.count = 1);
 Assert(loop.I.value = 1);

 value := 0;
 for_.I := 2; with varI do while to_.I(2) do
 begin
  Assert(loop.I.First = (I = 2));
  Assert(loop.I.Last = (I = 2));

  value := value + I;
 end;
 Assert(2 = value);
 Assert(loop.I.count = 1);
 Assert(loop.I.value = 3);

 //0回ループテスト
 value := -1;
 for_.I := 0; with varI do while to_.I(-1) do
 begin
  value := value + I;
 end;
 Assert(value = -1);
 Assert(loop.I.count = 0);
 Assert(loop.I.value = 0);

 value := 0;
 for_.I := 2; with varI do while to_.I(1) do
 begin
  value := value + I;
 end;
 Assert(0 = value);
 Assert(loop.I.count = 0);
 Assert(loop.I.value = 2);

 //Step指定ループ
 value := 0;
 for_.I := 10; with varI do while to_.I(100, 10) do
 begin
  Assert(loop.I.First = (I = 10));
  Assert(loop.I.Last = (I = 100));

  value := value + I;
 end;
 Assert(550 = value);
 Assert(loop.I.value = 110);

 //内部でIの値変更テスト
 value := 0;
 for_.I := 10; with varI do while to_.I(1000, 5) do
 begin
  Assert(loop.I.First = (I = 10));
  Assert(loop.I.Last = False);

  if I mod 10 <> 0 then continue;
  value := value + I;
  if 100 <= I then break;
 end;
 Assert(550 = value);
 Assert(loop.I.count = 19);
 Assert(loop.I.value = 100);

 //内部でIの値変更テスト
 value := 0;
 for_.I := 10; with varI do while to_.I(1000, 5) do
 begin
  Assert(loop.I.First = (I = 10));
  Assert(loop.I.Last = False);

  value := value + I;
  if 100 <= I then break;
  I := I + 5;
 end;
 Assert(550 = value);
 Assert(loop.I.count = 10);
 Assert(loop.I.value = 100);

 //down to テスト
 value := 0;
 for_.I := 9; with varI do while down_to_.i(1) do
 begin
  Assert(loop.I.First = (I = 9));
  Assert(loop.I.Last = (I = 1));

  value := value + I;
  Assert(I <> 0);
 end;
 Assert(45 = value);
 Assert(loop.I.count = 9);
 Assert(loop.I.value = 0);

 //down to テスト
 value := 0;
 for_.I := 10; with varI do while down_to_.i(0) do
 begin
  Assert(loop.I.First = (I = 10));
  Assert(loop.I.Last = (I = 0));

  value := value + I;
  Assert(I <> -1);
 end;
 Assert(55 = value);
 Assert(loop.I.count = 11);
 Assert(loop.I.value = -1);

 //down to step テスト
 value := 0;
 for_.I := 100; with varI do while down_to_.i(10, -10) do
 begin
  Assert(loop.I.First = (I = 100));
  Assert(loop.I.Last = (I = 10));

  value := value + I;
  Assert(False = (I <= 9) );
 end;
 Assert(550 = value);
 Assert(loop.I.count = 10);
 Assert(loop.I.value = 0);

 //二重ループテスト
 ReturnString := '';
 for_.J := 0; with varJ do while to_.J(10) do
 begin
  Assert(loop.J.First = (J = 0));
  Assert(loop.J.Last = (J = 10));

  for_.I := 2; with varI do while to_.I(3) do
  begin
   Assert(loop.I.First = (I = 2));
   Assert(loop.I.Last = (I = 3));

   ReturnString := ( IntToStr(J) + '-' + IntToStr(I) );
  end;
 end;
 Assert('10-3' = ReturnString);
 Assert(loop.I.count = 2);
 Assert(loop.J.count = 11);
 Assert(loop.I.value = 4);

 //二重ループ、I/J逆設定テスト
 ReturnString := '';
 for_.I := 0; with varI do while to_.I(10) do
 begin
  Assert(loop.I.First = (I = 0));
  Assert(loop.I.Last = (I = 10));

  for_.J := 2; with varJ do while to_.J(3) do
  begin
   Assert(loop.J.First = (J = 2));
   Assert(loop.J.Last = (J = 3));

   ReturnString := ( IntToStr(I) + '-' + IntToStr(J) );
  end;
 end;
 Assert('10-3' = ReturnString);
 Assert(loop.J.count = 2);
 Assert(loop.I.count = 11);
 Assert(loop.I.value = 11);

 //制御変数による無限ループテスト
 value := 0;
 for_.I := 0; with varI do while to_.I(0) do
 begin
  Inc(value);
  I := I - 1;

  if 1000 <= value then break;
 end;
 Assert(loop.I.Count = 1000);
 Assert(loop.I.value = -1);

 //制御変数による無限ループテスト
 value := 0;
 for_.I := 0; with varI do while to_.I(I+1) do
 begin
  Inc(value);

  if 1000 <= value then break;
 end;
 Assert(loop.I.Count = 1000);
 Assert(loop.I.value = 999);
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
 testfor_;
end;

//────────────────────
再帰呼び出しテストも、
既存のFor I :=
と、比較してテストしてます。

再帰呼び出しコードは、7/27の記事で書いたものですね。


Panel1に、Edit1、Button1、Panel2をのせ
Panel2に、Edit2、Button2、Panel3をのせ
Panel3に、Edit3、Button3、をのせています。

var
 uReturnString1: String;
 uReturnString2: String;

type
 TRecursiveCallProcedure =
  procedure(Control: TControl; Args: array of variant);

procedure RecursiveCallControlOld(WinControl: TWinControl; Proc:
TRecursiveCallProcedure; Args: array of variant);

  procedure RecursiveCallChildControl(Parent: TWinControl);
  var
   i, value: Integer;
  begin
   value := 0;
   for i := 0 to Parent.ControlCount-1 do
   begin
    if (Parent.Controls[i] is TWinControl) then
     RecursiveCallChildControl( (Parent.Controls[i] as TWinControl) );

    Proc(Parent.Controls[i], Args);
    uReturnString2 := uReturnString2 + Parent.Controls[i].Name + ' ';
    Inc(value);
   end;
   uReturnString1 := uReturnString1 + IntToStr(value);
  end;
begin
 RecursiveCallChildControl(WinControl);
 Proc(WinControl, Args);
end;

procedure RecursiveCallControlNew(WinControl: TWinControl; Proc:
TRecursiveCallProcedure; Args: array of variant);

  procedure RecursiveCallChildControl(Parent: TWinControl);
  begin
   for_.I := 0; with varI do while to_.I(Parent.ControlCount-1) do
   begin
    if (Parent.Controls[i] is TWinControl) then
     RecursiveCallChildControl( (Parent.Controls[i] as TWinControl) );

    Proc(Parent.Controls[i], Args);
    uReturnString2 := uReturnString2 + Parent.Controls[i].Name + ' ';
   end;
   uReturnString1 := uReturnString1 + IntToStr(loop.I.value);
  end;

begin
 RecursiveCallChildControl(WinControl);
 Proc(WinControl, Args);
end;

//{----------------------------------------
procedure SetEnabled(Control: TControl; Args: array of variant);
begin
 Control.Enabled := Args[0];
end;

procedure SetChildControlEnabled(WinControl: TWinControl; Value: Boolean);
var
 CompareString1: String;
 CompareString2: String;
begin
 uReturnString1 := '';
 uReturnString2 := '';
 RecursiveCallControlOld(WinControl, SetEnabled, [Value]);
 CompareString1 := uReturnString1;
 CompareString2 := uReturnString2;

 uReturnString1 := '';
 uReturnString2 := '';
 RecursiveCallControlNew(WinControl, SetEnabled, [Value]);
 Assert(CompareString2 = uReturnString2);
 Assert(CompareString1 = uReturnString1);
end;
//----------------------------------------}

procedure TForm1.Button5Click(Sender: TObject);
begin
 SetChildControlEnabled(Panel1, not Panel1.Enabled);
end;


procedure TForm1.Button6Click(Sender: TObject);
begin
 Panel1.Enabled := not Panel1.Enabled;
end;


────────────────────
スポンサーサイト

| 未分類 | 23:07 | comments:0 | trackbacks(-) | TOP↑

COMMENT















非公開コメント

PREV | PAGE-SELECT | NEXT

上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。