当前位置:编程学习 > C#/ASP.NET >>

测试代码

网上疯传了的最佳代码,不晓得啥语言的,我摸拟了一个。

/*
 * Created by SharpDevelop 4.
 * User: 王不留行
 * Mail: toiiggww@163.com
 * Date: 2011-8-1
 * Time: 17:28
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

namespace CelestialEmpire
{
public class Location
{
public Location(int id){}
}
public class Accident
{
public DateTime DateTime{get;private set;}
public int Die{get;private set;}
public Location Area{get;private set;}
public bool IsAccurate{get;private set;}
public bool IsPublic{get;private set;}
public Accident( DateTime t, int d, Location l, bool a, bool p)
{
DateTime = t; Die=d; Area = l; IsAccurate = a; IsPublic =p;
Console.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
}
}
public interface ChaoPersion
{
bool believe( Accident crash);
}
public interface BrainWashing
{
void believe( Accident JuestSoSo);
void sayShit( string str);
void sayShit( Accident JustHappened);
}
public class Brainwasher:BrainWashing
{
public void believe(Accident JuestSoSo)
{ throw new NotExistsException(); }
public void sayShit(string str){ Console.WriteLine(str);}
public void sayShit(Accident acc){ Console.WriteLine("It "+(acc.JustHappened()?"happened yet!":"is always be happened!")); }
}
public class NotExistsException:Exception{}
public static class BrainwasherExtened
{
public static bool JustHappened( this Accident accident )
{ return accident.IsPublic || accident.IsAccurate; }
}
public class You:ChaoPersion
{
public bool believe(Accident crash) {
bool r = crash.IsAccurate && crash.IsPublic ;
if (!r) {throw new NotBelievableException();}
return r;
}
}
public class NotBelievableException:Exception{}
public class Acc723
{
public static void Main() {
Accident acc723 =
new Accident(new DateTime(2011,7,23),40,
             new Location(325402),false, false);
BrainWashing wyp = new Brainwasher();
You you = new You();
try {
if (you.believe(acc723)) {
wyp.believe(acc723);
}
} catch (Exception) {
wyp.sayShit("This is a miracle!");
}
finally {
wyp.sayShit( acc723 );
}
}
}
}

--------------------编程问答-------------------- 这个不怕被和谐……
补充:.NET技术 ,  非技术区
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,