[Cuppa-users:46] Re: 表明の拡張

Zurück zum Archiv-Index

FUKUDA Fumiki ffuku****@ntes*****
2002年 6月 11日 (火) 13:03:36 JST


επιστημηです。

--- "[Cuppa-users:45] Re: 表明の拡張" / 渋川よしき / 2002/06/11 12:33:29 +0900 ---

>> # こんなASSERT欲しい。てのないですか?
>RubyUnitとかPyUnitにはあるけどCppUnitにはないやつですが、

なるほど、こんなのがあるんだ...

それぞれ、どんなコード吐けばいいかな...

>CUPPA_ASSERT_EXCEPTION(expect_exception, target_code)
>--> target_codeを実行してexpect_exception例外がスローされたらOK。
>  例外が起きない or 違う例外だったらNG

try {
  target_code;
  CPPUNIT_FAIL("no exceptionthrown");
} catch ( ecpect_exception ) {
  // おっけー
} catch ( ... ) {
  CPPUNIT_FAIL("exception thrown rather than " #expect_exception);
}

>CUPPA_ASSERT_BETWEEN(expect_min, expect_max, actual)
>--> 実行結果が expect_min, expect_maxの間ならOK

if ( except_min > actual || expect_max < actual ) {
  CPPUNIT_FAIL("expected between ... but was ...");
}

>CUPPA_ASSERT_PROBABLE(probability, time, condition)
>--> time回、target_codeを実行してprobability以上の確率でconditionが
>    trueならOK。ゲームプログラミングとかに欲しいかも。

int expect_trues = probability * time;
int trues = 0;
for ( int i = 0; i < time; ++i ) {
  if ( condition ) ++trues;
}
if ( expect_trues > trues ) {
  CPPUNIT_FAIL("だめじゃん");
}

...って感じすか。どれもやれなくはないですね。
マクロ内で完結しろっていわれるとキツいのもあるけど。
できればCppUnit自体をいじらずに...ちょっと考えてみましょうか。
 
-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...



Cuppa-users メーリングリストの案内
Zurück zum Archiv-Index