private static void testComposedType_write(System.Type t, afh.Application.Log log) { System.Type elem = t.GetElementType(); log.WriteLine(Types.CSharpName(t)); log.AddIndent(); log.WriteVar("&", t.IsByRef); log.WriteVar("*", t.IsPointer); log.WriteVar("[]", t.IsArray); if (t.IsGenericParameter) { log.WriteLine("This is a generic parameter."); } if (t.IsGenericType) { log.WriteVar("Namespace", t.Namespace); log.WriteVar("Name", t.Name); log.WriteVar("FullName", t.FullName); foreach (System.Type type in t.GetGenericArguments()) { testComposedType_write(type, log); } } if (t.IsNested) { log.WriteVar("ParentType", t.DeclaringType); } if (elem != null) { log.WriteVar("ElementType", t.GetElementType()); testComposedType_write(elem, log); } log.RemoveIndent(); }
public static void TestRegexMatch1(afh.Application.Log log) { using (log.Lock()){ StringRegex.RegLan reglan = new StringRegex.RegLan("こんにちは|さようなら"); log.WriteLine("Regular Expression: {0}", reglan); foreach (StringRegex.Capture c in reglan.Matches("こんにちは さようなら こんにちは こんにちは さようなら")) { log.WriteLine("Match! : {0}", c.Value); } reglan = new StringRegex.RegLan(@"(?<l>\d+)(?<o>(?:\+|\-))(?<r>\d+)"); log.WriteLine("Regular Expression: {0}", reglan); foreach (StringRegex.Capture c in reglan.Matches("3+2+4+5 1+2+3 2+3 4+7 123+321")) { int l = int.Parse(c.Groups["l"].Last); int r = int.Parse(c.Groups["r"].Last); bool o = c.Groups["o"].Last.Value == "+"; log.WriteLine("{0} を計算すると→: {1}", c, o?l + r:l - r); } log.WriteLine("== System.Text.RegularExpressions の場合 =="); Rgx::Regex rgx = new Rgx::Regex(@"(?<l>\d+)(?<o>(?:\+|\-))(?<r>\d+)"); log.WriteLine("Regular Expression: {0}", rgx.ToString()); foreach (Rgx::Match m in rgx.Matches("3+2+4+5 1+2+3 2+3 4+7 123+321")) { int l = int.Parse(m.Groups["l"].Value); int r = int.Parse(m.Groups["r"].Value); bool o = m.Groups["o"].Value == "+"; log.WriteLine("{0} を計算すると→: {1}", m.Value, o?l + r:l - r); } } }
private void ReadType(System.Type type) { const Ref::BindingFlags BF = Ref::BindingFlags.Static | Ref::BindingFlags.Public | Ref::BindingFlags.NonPublic; afh.Application.Log log = Program.log; log.WriteLine("ReadType: {0}", type.FullName); foreach (Ref::MethodInfo minfo in type.GetMethods(BF)) { // 超いい加減引数チェック if (TestMethod.IsTestable(minfo)) { TestMethod test = new TestMethod(minfo); test.WriteSummary(log); this.listBox1.Items.Add(test); } BenchMethodAttribute benchattr = BenchMethod.GetAttribute(minfo, log); if (benchattr != null) { BenchMethod bench = new BenchMethod(minfo, benchattr); this.listBox1.Items.Add(bench); } } }
public static void 仮想関数とデリゲート(afh.Application.Log log) { D仮想関数とデリゲート d = ((object)reglan).ToString; log.WriteLine(d.Method.DeclaringType); log.WriteLine(d.Method); }
} // 67.99 - 24.91 = 43.08 ns public static unsafe void tst_NanOrInf_Representation(afh.Application.Log log) { System.Action <double> test = delegate(double value){ long signif16 = (int)(*(long *)(&value) >> 48); string str = ""; for (int i = 0x8000; i > 0; i >>= 1) { str += (signif16 & i) != 0?'1':'0'; } log.WriteVar(value.ToString(), str); }; test(0); test(1); test(1121.44); test(.31312312e-10); test(-1); test(-0.5); test(-0.25); log.WriteLine(); test(3.1415926575323846264e100); test(3.1415926575323846264e-100); log.WriteLine(); test(double.NaN); test(double.PositiveInfinity); test(double.NegativeInfinity); }
public static string test1(afh.Application.Log log) { System.Text.StringBuilder b = new System.Text.StringBuilder(); log.WriteLine(TestParse("x=y=+++a+b--c*d+a/c/o!")); log.WriteLine(TestParse("(a+b)*c")); return(b.ToString()); }
public virtual unsafe System.Windows.Forms.Control GetControl() { afh.Application.Log l = UI.TreeNode.ShareLog; l.Clear(); l.Lock(); l.WriteLine("Binary dump of first 512 bytes:"); fixed(byte *img = &this.file.image[0]) { byte *table = img + (uint)entry.offset; byte *end = table + System.Math.Min((uint)entry.length, 512u); for (int i = 1; table < end; table++, i++) { l.AppendText(table->ToString("X2")); if (i >= 16) { i = 0; l.AppendText("\r\n"); } else { l.AppendText(" "); } } } l.Unlock(); return(UI.TreeNode.ShareTxtBox); }
static void Main() { System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); log = afh.Application.LogView.Instance.CreateLog("<afh.ImageArrange>"); //afh.File.Riff.RiffFile riff=afh.File.Riff.RiffFile.FromFile(@"C:\Documents and Settings\koichi\デスクトップ\ANI\IE5.ani"); /* * ThumbsFile file=ThumbsFile.OpenFile(@"C:\IMAGE\Images\test.thm"); * file.AddFileDirectory(@"C:\IMAGE\Images\sm1278957"); * file.Save(); * //*/ //ThumbsFile file=ThumbsFile.OpenFile(@"C:\IMAGE\Images\test.thm"); // Main #if true { Form1 form1 = new Form1(); form1.ReadFile(@"F:\IMAGE\東方画像\imgarn.thm"); //form1.ReadFile(@"C:\IMAGE\東方画像\imgarn.thm"); //form1.ReadFile(@"C:\IMAGE\Images\test.thm"); System.Windows.Forms.Application.Run(form1); } #else //*/ // Debug { DebugLayout form1 = new DebugLayout(); System.Windows.Forms.Application.Run(form1); } #endif }
} // 488.01 ns //=========================================================== // sin 速度 //=========================================================== public static void test_sin_correctness(afh.Application.Log log) { for (int i = 0; i < 30; i++) { tComplex x = sin1(cmpx_arr[i]); tComplex y = sin2(cmpx_arr[i]); if (tComplex.AreEqual(x, y)) { log.WriteLine("sin1 = sin2"); } else if (tComplex.AreAlmostEqual(x, y)) { log.WriteLine("sin1 ≒ sin2"); } else if (tComplex.AreNear(x, y)) { log.WriteLine("sin1 〜 sin2"); } else { log.WriteLine("sin1 ≠ sin2"); log.WriteLine(cmpx_arr[i].real); log.WriteLine(sin_corr_1(cmpx_arr[i].real)); log.WriteLine(sin_corr_2(cmpx_arr[i].real)); } } }
private static void typeNames(afh.Application.Log log) { foreach (System.Type t in types) { string name = t.Name; log.WriteLine("{0} // hashcode : 0x{1:X}", name, name.GetHashCode()); } }
//=========================================================== // argument //=========================================================== public static void tstMathAtan2(afh.Application.Log log) { log.WriteLine(System.Math.Atan2(0, 0)); // 0 log.WriteLine(System.Math.Atan2(double.NaN, double.NaN)); // NaN log.WriteLine(System.Math.Atan2(double.PositiveInfinity, double.PositiveInfinity)); // NaN log.WriteLine(System.Math.Atan2(double.PositiveInfinity, 0)); // π/2 log.WriteLine(System.Math.Atan2(0, double.PositiveInfinity)); // 0 }
/// <summary> /// 指定した log を選択した状態にし、内容が表示される様にします。 /// </summary> /// <param name="log">選択した状態にする Log を指定します。 /// 元からこのインスタンスに登録されている Log を指定する必要があります。</param> public void EnsureVisibleLog(afh.Application.Log log) { if (!this.listBox1.Items.Contains(log)) { return; } this.listBox1.SelectedItem = log; }
public static void tst_FloatRem(afh.Application.Log log) { log.WriteLine(11.2 % 3.1); log.WriteLine(-11.2 % 3.1); log.WriteLine(-11.2 - IntUtils.Floor(-11.2, 3.1)); log.WriteLine(System.Math.IEEERemainder(-11.2, 3.1)); log.WriteLine("--角度の実験--"); log.WriteLine(System.Math.Atan2(-1, 1)); }
public static unsafe void tst_NanOrInf_Representation2(afh.Application.Log log) { //double inf_d=double.PositiveInfinity; long inf = 0x7ff0000000000000; //*(long*)(&inf_d); int i = 0, pinf = 0, ninf = 0, nan = 0; System.Random r = new System.Random(); byte[] buff = new byte[8]; fixed(byte *p = buff) { long *plong = (long *)p; for (i = 0; i < 0x100000; i++) { r.NextBytes(buff); *plong |= inf; // 0x0123456789ABCDEF //*plong&=~0x4000000000000000; //*plong&=~0x2000000000000000; //*plong&=~0x1000000000000000; //*plong&=~0x0800000000000000; //*plong&=~0x0400000000000000; //*plong&=~0x0200000000000000; //*plong&=~0x0100000000000000; //*plong&=~0x0080000000000000; //*plong&=~0x0040000000000000; //*plong&=~0x0020000000000000; //*plong&=~0x0010000000000000; //・ ↑ のどれか一つでも実行すると全て finite になる //・ 何も実行しないと全て NaN に為る (∞ が出ないのは確率的な問題) //→ と言う事は、finite かどうかは (value&0x7fff....!=0x7fff...) を調べれば良さそう? double val = 0 + *(double *)plong; if (double.IsPositiveInfinity(val)) { pinf++; } else if (double.IsNegativeInfinity(val)) { ninf++; } else if (double.IsNaN(val)) { nan++; } } } i -= pinf + ninf + nan; log.WriteVar("+∞", pinf.ToString()); log.WriteVar("-∞", ninf.ToString()); log.WriteVar("NaN", nan.ToString()); log.WriteVar("finite", i.ToString()); }
public static void dbg_Rational(afh.Application.Log log) { log.WriteLine(10 / (Rational)15 + 1); log.WriteLine(new Rational(3, 8) - 11); log.WriteLine(new Rational(1, 2) + new Rational(2, 3)); log.WriteLine(new Rational(2, 3) / Rational.Zero); log.WriteLine(new Rational(-2, 3) / Rational.Zero); log.WriteLine(Rational.Zero / Rational.Zero); log.WriteLine(Rational.PositiveInfinity + Rational.NegativeInfinity); }
public void WriteSummary(afh.Application.Log log) { log.WriteLine("Method: " + Types.GetMethodSignature(info)); if (description != "") { log.AddIndent(); log.WriteVar("Description", this.description); log.RemoveIndent(); } }
//=========================================================== // 計測 //=========================================================== public void Execute(afh.Application.Log log) { // 前書き log.Lock(); log.WriteLine(); log.WriteLine(STR_LINE); log.WriteLine("\tBenchmark を開始します。"); log.WriteLine("\t\tMethodName: {0}::{1}", minfo.DeclaringType.FullName, minfo.Name); if (this.Description != "") { log.WriteLine("\t\tDescription: {0}", this.Description); } log.WriteLine(STR_LINE); log.Unlock(); try{ int loop = 1; double msecs = 0; for (int i = 1; loop > 0; loop <<= 2, i++) { log.WriteLine("第 {0} 回計測開始 (Loop 回数: {1} 回):", i, loop); TimeSpan ts = this.meth(loop); log.WriteLine("\t経過時間: {0} ms", msecs = ts.TotalMilliseconds); if (ts.Seconds != 0) { break; } if (msecs < 16.0) { loop <<= 6; } } double time = msecs / loop; int iunit = 0; if (time > 0) { while (time < 1) { time *= 1000; iunit++; } } log.WriteLine("一回当たり時間: {0:F2} {1}s", time, units[iunit]); }catch (System.Exception e) { log.WriteError(e, "Bench の実行中に例外が発生しました。"); } // 後書き log.Lock(); log.WriteLine(STR_LINE); log.WriteLine("\tBenchmark を終了しました。"); log.WriteLine(STR_LINE); log.Unlock(); }
public static void test_括弧の一致(afh.Application.Log log) { Rgx::Regex rx = new System.Text.RegularExpressions.Regex( "^" + REP.CreateMatchParen('(', ')', true) + "$", System.Text.RegularExpressions.RegexOptions.Compiled ); log.WriteLine(rx.Match("fjsadfj(ssddd+dsada)dasdasd").Success); log.WriteLine(rx.Match("fjsadfj(ssddd+d(sada)dasdasd").Success); log.WriteLine(rx.Match("fjsadfj(ssddd+d(sada)das')')d\"((((((\"asd").Success); }
private static void TestRegexMatch(afh.Application.Log log, string regex, string text, bool expected) { StringRegex.RegLan reg = new StringRegex.RegLan(regex); bool r = reg.IsMatching(text); log.WriteLine("'{1}'∈/{0}/ : {2}", reg, text, r); if (r != expected) { log.WriteError("***ASSERTION FAILED*** 評価結果が予期した物と異なります!!!"); } }
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { if (this.listBox1.SelectedIndex < 0) { return; } if (this.listBox1.SelectedItem is afh.Application.Log) { this.CurrentLog = (afh.Application.Log) this.listBox1.SelectedItem; } }
public static void type分岐3_準備(afh.Application.Log log) { afh.Collections.DictionaryP <int, System.Type> dic = null; afh.Collections.DictionaryP <int, System.Type> dic0; int minwrap = int.MaxValue; int minshift = 0; for (int shift = 0; shift <= 28; shift++) { int wrap = type分岐3_準備1(shift, out dic0); if (wrap < minwrap) { dic = dic0; minwrap = wrap; minshift = shift; } } log.Lock(); if (minshift == 0) { log.WriteLine("switch(t.Name.GetHashCode()&0xf){"); } else { log.WriteLine("switch((t.Name.GetHashCode()>>{0})&0xf){{", minshift); } log.AddIndent(); int c = 1; for (int i = 0; i <= 0xf; i++) { // case i: System.Text.StringBuilder build = new System.Text.StringBuilder(); build.AppendFormat("case {0}:", i); bool _else = false; foreach (System.Type type in dic[i]) { if (_else) { build.Append("else "); } build.AppendFormat("if(t==typeof({0})){{\r\n", afh.Types.CSharpName(type)); build.AppendFormat(" c+={0};\r\n", c++); build.Append(" }"); _else = true; } build.Append("break;"); log.WriteLine(build.ToString()); } log.RemoveIndent(); log.WriteLine("}"); log.Unlock(); //*/ }
public static void test_templateProc(afh.Application.Log log) { const string input = @" namespace afh{ //#include ""mwg.Controls.WB.txt"" public static partial class Math{ //#define add hello(x) //#define square(x,y) ((x+y)*(y+x)) //#define RAW(x) x //#→template ADD_ARGS<abc,efg> {args[iArgs++]=double.Parse(abc);if(iArgs==NumberOfArgs)mode=efg;} //#←template //#→template ADD_ARGS<_word> {args[iArgs++]=double.Parse(_word);if(iArgs==NumberOfArgs)mode=SKIP_MODE;} //#←template //--------------------------------------------- //#>>delete これはごみごみ!!! //#<<delete RAW(""#Hello<xxx>#"") end; RAW(abc) end; public static void Main(){ //#ADD_ARGS<""0""> //#ADD_ARGS<word> //#ADD_ARGS<word> //#ADD_ARGS<word> //#ADD_ARGS<""0""> //#ADD_ARGS<SEKAI,OHAYOU!!> add;add; square(add,add); square(""#今日は ()()()((()))#"",789); } } } " ; log.WriteLine("入力:"); log.DumpString(input); log.WriteLine(); TemplateProcessor proc = new TemplateProcessor(); GenError e = new GenError(); string output = proc.Translate(input, "test", e); log.WriteLine("出力:"); log.DumpString(output); foreach (GenError.Error err in e.errors) { log.WriteLine(err); } }
//=========================================================== // IsInfinity 加算比較の有効性 //=========================================================== public static void tst_NanOrInf加算比較有効性(afh.Application.Log log) { double[] ddd = new double[] { double.NaN, double.PositiveInfinity, double.NegativeInfinity }; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { double result = ddd[x] + ddd[y]; bool ok = double.IsNaN(result) || double.IsInfinity(result); log.WriteLine("{0} + {1} = {2} : {3}", ddd[x], ddd[y], result, ok?"OK":"×××"); } } }
public static void test_stringLineColumn(afh.Application.Log log) { const string sample = @" 今日は 作用なら おほほほほほほほほ "; afh.Text.MultilineString mstr = new afh.Text.MultilineString(sample); log.DumpString(sample); log.WriteLine("3 行 1 列: {0}", mstr[3, 1]); }
public static void test_RgbHsvTrans(afh.Application.Log log) { System.Action <afh.Drawing.Color32Argb> test = delegate(afh.Drawing.Color32Argb c1){ afh.Drawing.ColorHsv c2 = (afh.Drawing.ColorHsv)c1; log.WriteLine("--- test ---"); log.WriteLine(c1); log.WriteLine(c2); log.WriteLine((afh.Drawing.Color32Argb)c2); }; test(0x78123456); test(0xffAACC98); test(0x03daf400); test(0x285f0088); }
public static void test_Preprocessor(afh.Application.Log log) { string input = System.IO.File.ReadAllText( System.IO.Path.Combine(afh.Application.Path.ExecutableDirectory, "test_preprocessor.cpp"), System.Text.Encoding.Default ); log.WriteLine("入力:"); //log.DumpString(input); log.WriteLine(); string output = new afh.Preprocessor.Preprocessor().Preprocess(input); log.WriteLine("出力:"); //log.DumpString(output); }
public static void tst_DoubleNaN(afh.Application.Log log) { log.Lock(); log.WriteLine("NaN 同士"); log.WriteLine(double.NaN == 0); log.WriteLine(double.NaN != 0); log.WriteLine(double.NaN == double.NaN); log.WriteLine(double.NaN != double.NaN); log.WriteLine(double.NaN < 0); log.WriteLine(double.NaN >= 0); log.WriteLine(double.NaN < double.NaN); log.WriteLine(double.NaN >= double.NaN); log.WriteLine(); log.WriteLine("+∞ 同士"); log.WriteLine(double.PositiveInfinity == double.PositiveInfinity); log.WriteLine(double.PositiveInfinity != double.PositiveInfinity); log.WriteLine(double.PositiveInfinity < double.PositiveInfinity); log.WriteLine(double.PositiveInfinity >= double.PositiveInfinity); log.WriteLine(); log.WriteLine("-∞ 同士"); log.WriteLine(double.NegativeInfinity == double.NegativeInfinity); log.WriteLine(double.NegativeInfinity != double.NegativeInfinity); log.WriteLine(double.NegativeInfinity < double.NegativeInfinity); log.WriteLine(double.NegativeInfinity >= double.NegativeInfinity); log.WriteLine(); log.WriteLine("NaN > 色々"); log.WriteLine(double.NaN > 0); log.WriteLine(double.NaN > 1); log.WriteLine(double.NaN > -1); log.WriteLine(double.NaN > double.NegativeInfinity); log.WriteLine(double.NaN > double.PositiveInfinity); log.WriteLine(); log.Unlock(); const double inf = double.PositiveInfinity; const double NaN = double.NaN; log.Lock(); log.WriteLine("初等関数と NaN"); log.WriteVar("Atan2(∞,∞)", System.Math.Atan2(inf, inf)); log.WriteVar("Atan2(∞,NaN)", System.Math.Atan2(inf, NaN)); log.WriteVar("Atan2(0,0)", System.Math.Atan2(0, 0)); log.WriteVar("Sqrt(∞)", System.Math.Sqrt(inf)); log.WriteVar("Sqrt(NaN)", System.Math.Sqrt(NaN)); log.Unlock(); }
public void Execute(afh.Application.Log log) { // 前書き log.Lock(); log.WriteLine(); log.WriteLine(STR_LINE); log.WriteLine("\tTest を開始します。"); log.WriteLine("\t\tMethodName: {0}::{1}", info.DeclaringType.FullName, info.Name); if (description != "") { log.WriteLine("\t\tDescription: {0}", this.description); } log.WriteLine(STR_LINE); log.Unlock(); bool failed = false; object ret = null; System.DateTime start = System.DateTime.Now; try { ret = this.info.Invoke(null, new object[] { log }); }catch (System.Exception e) { log.WriteError(e, "Test の実行中に例外が発生しました。"); failed = true; } System.TimeSpan ts = System.DateTime.Now - start; // 後書き log.Lock(); if (!failed && info.ReturnType != typeof(void)) { log.WriteLine(STR_LINE); log.WriteLine("戻り値 ({0}):", info.ReturnType); log.WriteLine(ret ?? "null"); } log.WriteLine(STR_LINE); log.WriteLine("\tTest を終了しました。"); log.WriteLine("\t\t経過時間: {0} ms", ts.TotalMilliseconds); log.WriteLine(STR_LINE); log.Unlock(); }
public static void testComposedType(afh.Application.Log log) { System.Action <System.Type> write = delegate(System.Type t){ testComposedType_write(t, log); }; Ref::MethodInfo minfo = typeof(UnitTest).GetMethod("testComposedType_meth", Ref::BindingFlags.Static | Ref::BindingFlags.NonPublic); Ref::ParameterInfo[] pinfos = minfo.GetParameters(); log.Lock(); write(typeof(int *)); write(pinfos[0].ParameterType); write(pinfos[1].ParameterType); write(pinfos[2].ParameterType); log.Unlock(); Ref::MethodInfo minfo2 = pinfos[2].ParameterType.GetMethod("Method", Ref::BindingFlags.Static | Ref::BindingFlags.Public); log.WriteLine(Types.GetMethodSignature(minfo)); log.WriteLine(Types.GetMethodSignature(minfo2)); }
//=========================================================== // 初期化 //=========================================================== public static BenchMethodAttribute GetAttribute(Ref::MethodInfo minfo, afh.Application.Log log) { object[] attrs = minfo.GetCustomAttributes(typeof(BenchMethodAttribute), false); if (attrs.Length == 0) { return(null); } BenchMethodAttribute attr = (BenchMethodAttribute)attrs[0]; if (!minfo.IsStatic) { log.WriteLine("メソッド '{0}' は static でない為 Benchmark を実行出来ません。", minfo); return(null); } if (minfo.GetParameters().Length != 0) { log.WriteLine("メソッド '{0}' の呼び出しには引数が必要なので Benchmark を実行出来ません。", minfo); return(null); } return(attr); }