锘??xml version="1.0" encoding="utf-8" standalone="yes"?>邻家有女韩剧在线观看国语,亚洲日本免费,日韩一区有码在线http://www.aygfsteel.com/chaocai/category/45371.htmlzh-cnSun, 05 Aug 2012 21:12:00 GMTSun, 05 Aug 2012 21:12:00 GMT60The Clojure Program To solve N Queens Problemhttp://www.aygfsteel.com/chaocai/archive/2012/08/05/384844.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Sun, 05 Aug 2012 15:26:00 GMThttp://www.aygfsteel.com/chaocai/archive/2012/08/05/384844.htmlhttp://www.aygfsteel.com/chaocai/comments/384844.htmlhttp://www.aygfsteel.com/chaocai/archive/2012/08/05/384844.html#Feedback0http://www.aygfsteel.com/chaocai/comments/commentRss/384844.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/384844.htmlThe following program is about solving N-Queens problem (http://en.wikipedia.org/wiki/Eight_queens_puzzle) by Clojure. If you have the better solution in Clojure or Haskell, welcome to provide your solution.
(ns queens)
(defn conflictInRow? [queens newqueen]
  (some #(= newqueen %) queens)
)
(defn conflictInDia? [queens newqueen]
  (let [dia (count queens) 
        n1 (fn [queen] (Math/abs (- dia (.indexOf queens queen))))
        n2 (fn [queen] (Math/abs (- newqueen queen)))]
    (some #(= (n1 %) (n2 %)) queens)
   )
 )
(defn conflict? [queens newqueen]
  (or (conflictInRow? queens newqueen) (conflictInDia? queens newqueen))
 )
(def cnt (atom 0))
(defn put-queens [queens newqueen boardSize ]
  (if (= (count queens) boardSize)  
    (do
      (println queens)
      (reset! cnt (inc @cnt))
    )
    (do 
      ;(println queens)
      (if (> newqueen boardSize)
     
           (if (and (= (peek queens) boardSize) (= (count queens) 1))
               (throw (Exception. (str "That's all " @cnt)))
               (recur (pop queens) (inc (peek queens)) boardSize )
           )
     
        (if (conflict? queens newqueen)
            
             (recur queens (inc newqueen) boardSize )
             
          (do
             (put-queens (conj queens newqueen) 1 boardSize )
             (recur queens (inc newqueen) boardSize )
           )
        )
       )
      )
    )
    
)
(defn queens [boardSize] 
    (put-queens [] 1 boardSize)
 )


Chao Cai (钄¤秴錛?/div>

Sr. Software Dev Engineer 
Amazon.com

 


]]>TDD Tipshttp://www.aygfsteel.com/chaocai/archive/2011/01/09/342623.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Sun, 09 Jan 2011 08:55:00 GMThttp://www.aygfsteel.com/chaocai/archive/2011/01/09/342623.htmlhttp://www.aygfsteel.com/chaocai/comments/342623.htmlhttp://www.aygfsteel.com/chaocai/archive/2011/01/09/342623.html#Feedback1http://www.aygfsteel.com/chaocai/comments/commentRss/342623.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/342623.htmlHow to design the testable software? You may always find some best practices about designing for scalable, extensible or maintainable. To be testable, the best way should be TDD. Followings are some tips from my real practices on TDD.

1 TDD is design process; it let you design for testing, naturally

Write the test firstly, it does not only help you find the bugs; but the most important point is to let you design for test naturally.

Also you should keep in mind, tests not only help you find bugs, but also protect your codes; when some changes impact on your existing codes, the tests will be broken.

 

2 Keep the implementation simple

Keep your implementation simple, just let the test pass. The complex implementation may introduce the logics or codes not covered by the tests, even leads some codes not testable.

 

3 TDD in each scope.

You may get to know the concept ATDD (acceptance test driven development). TDD could be used in every phase of the development and by the different granularity.

To ATDD, you could consider on using some existing framework such as FIT, these frameworks will be bridge between business logic and implementation logic.

Recently, the concept BDD (behavior driven development) is introduced to the ATDD process, so the BDD frameworks such as JBehave is also the good choice.

 


Different TDD process could be nested and should be nested don’t let your step too large.

 

4 keep each step small enough

Always keep each step small to avoid introducing the untestable codes or logics and pass each test quickly.

 

 

6 Always refactor

This step is always overlooked in TDD process; however it is the very important step. Also, never forget refactor should involve all your tests.

 

Why can't write test firstly?

 1.not think how to meature the codes

2. The current step maybe too large, should separate into small ones

3. The codes with ugly dependencies


 http://blog.csdn.net/chaocai2004/archive/2011/01/09/6125479.aspx


Chao Cai (钄¤秴)

Sr. SDE

Amazon.com

 



]]>
綆楁硶鐨勬椂闂村鏉傚害http://www.aygfsteel.com/chaocai/archive/2010/06/18/323815.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Fri, 18 Jun 2010 07:26:00 GMThttp://www.aygfsteel.com/chaocai/archive/2010/06/18/323815.htmlhttp://www.aygfsteel.com/chaocai/comments/323815.htmlhttp://www.aygfsteel.com/chaocai/archive/2010/06/18/323815.html#Feedback1http://www.aygfsteel.com/chaocai/comments/commentRss/323815.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/323815.html鐩鎬俊澶у瀵逛簬綆楁硶鐨勬椂闂村鏉傚害O閮戒笉浼氶檶鐢燂紝涓嶈繃浣犵煡閬撲竴涓畻娉曠殑鏃墮棿澶嶆潅搴︽槸濡備綍璁$畻鍑烘潵鐨勫悧錛?/span>

浠ュ墠鍦ㄥ涔犵畻娉曞拰鏁版嵁緇撴瀯鐨勬椂鍊欙紝瀵逛簬姣忕綆楁硶鐨勫鏉傚害閮芥槸姝昏鐨勫茍娌℃湁鐪熸鐨勫幓鐮旂┒浠栦滑鏄浣曡綆楀嚭鏉ワ紝鏈榪戠獊鐒跺綆楁硶浜х敓浜嗗叴瓚o紝榪嬌鑷繁鐮旂┒浜嗕竴涓嬬畻娉曞鏉傚害鐨勮綆楁柟娉曘?/span>

姒傚康

澶?/span>O琛ㄧず娉曡〃紺烘椂闂村鏉傛э紝娉ㄦ剰瀹冩槸鏌愪竴涓畻娉曠殑鏃墮棿澶嶆潅鎬с傚ぇO琛ㄧず鍙槸璇存湁涓婄晫錛岀敱瀹氫箟濡傛灉f(n)=O(n)錛岄偅鏄劇劧鎴愮珛f(n)=O(n^2)錛屽畠緇欎綘涓涓笂鐣岋紝浣嗗茍涓嶆槸涓婄‘鐣岋紝浣嗕漢浠湪琛ㄧず鐨勬椂鍊欎竴鑸兘涔犳儻琛ㄧず鍓嶈?/span>銆?/span>

鍙﹀闄や簡榪欎釜瀹樻柟姒傚康錛屼釜浜鴻涓哄ぇO琛ㄧず鐨勬槸闂瑙勬ān鍜岀畻娉曚腑璇彞鎵ц嬈℃暟鐨勫叧緋匯?/span>

浠ヤ簩鍒嗘煡鎵句負渚嬶紝鎴戜滑姹傝В瀹冪殑鏃墮棿澶嶆潅搴?/span>

1 璁捐妯′負n涓厓绱犳椂錛岃鎵цT(n)嬈?/span>

T(n)=T(n/2)+1

T(n)=[T(n/4)+1]+1

T(n)=T(n/2^m)+m

褰?/span>n=2^m

T(n)=T(1)+log2n

T(1)=1

鎵浠ュ叾綆楁硶澶嶆潅搴︿負O錛坙og2n錛?/span>



]]>
主站蜘蛛池模板: 汕尾市| 贵南县| 巩义市| 阿克陶县| 溧阳市| 岐山县| 石嘴山市| 佛冈县| 报价| 六枝特区| 嫩江县| 沈丘县| 孝昌县| 德惠市| 仙桃市| 威海市| 灵川县| 濉溪县| 孝昌县| 涟源市| 台湾省| 连山| 米泉市| 九寨沟县| 荣昌县| 泉州市| 三江| 古田县| 孟村| 呈贡县| 高邮市| 延长县| 马鞍山市| 河曲县| 宣恩县| 乃东县| 哈尔滨市| 嘉禾县| 伊宁市| 新和县| 东海县|