2010-02-19
カスタム版TZTesterの1E-9誤差許容対応をvector<double>にも適用する
|以前、結果がdoubleの場合に±1E-9の誤差を認めるようにTZTesterをカスタマイズしたが、SRM462 Div1Mediumのようにvector<double>の場合には未対応だったので再改造。
以下、前回(cafelier版+naoya_tパッチ)からの差分。
--- tangentz.old/TZTester.java 2010-02-19 21:02:27.000000000 +0900 +++ TZTesters/tangentz/TZTester.java 2010-02-19 22:13:30.000000000 +0900 @@ -32,7 +32,7 @@ private static final String k_PROBLEM = "$PROBLEM$"; private static final String k_RUNTEST = "$RUNTEST$"; private static final String k_TESTCODE = "$TESTCODE$"; - private static final String k_VERSION = "\n// Powered by TZTester 1.01 [25-Feb-2003] customized by cafelier, timer support by naoya_t"; + private static final String k_VERSION = "\n// Powered by TZTester 1.01 [25-Feb-2003] customized by cafelier, timer and 1e-9 tolerance support by naoya_t"; // Cut tags private static final String k_BEGINCUT = "// BEGIN CUT HERE\n"; @@ -237,6 +237,12 @@ if (TypeString.equals("double")) { Code.append("double diff = Expected - Received; if (diff < 0) diff = -diff; "); Code.append("if (diff < 1e-9) cerr << \"PASSED\" << timer() << endl; "); + } else if (TypeString.equals("vector <double>")) { // vector<double> support added on Feb 19, 2010 by naoya_t + Code.append("bool passed = Received.size()==Expected.size(); "); + Code.append("if (passed) for (int i=0,c=Received.size(); i<c; i++) { "); + Code.append("double diff = Expected[i] - Received[i]; if (diff < 0) diff = -diff; "); + Code.append("if (diff >= 1e-9) { passed = false; break; }} "); + Code.append("if (passed) cerr << \"PASSED\" << timer() << endl; "); } else { Code.append("if (Expected == Received) cerr << \"PASSED\" << timer() << endl; "); }
EmK2010/02/25 23:27こんにちは。
その実装では、空のvector<double>に対して常にPASSEDと判定する気がします。
n4_t2010/02/25 23:38そうですね。vectorのサイズが等しいかチェックしてませんし…もう少しまじめにチェックするよう加筆しました。こんなところで撃墜されるとは。