Racketはデジタルと中国語の変換アルゴリズム3(プログラムテスト)を実現する

22562 ワード

前の2編はアラビア数字と中国語数字の相互転化を紹介した.詳細は以下を参照してください.
  • Racketは数字と中国語の変換アルゴリズム1(アラビア数字から中国語数字に変換)を実現した.https://blog.csdn.net/chinazhangyong/article/details/80588160
  • Racketは数字と中国語の変換アルゴリズム2(中国語の数字をアラビア数字に変換)を実現した.https://blog.csdn.net/chinazhangyong/article/details/80602803

  • 次にプログラムをテストします.
    一、テストデータの準備
    このステップは重要で、テストデータが様々な状況をカバーしていないと、隠されたBugが発見できない可能性があります.以前にいくつかのテストデータを組織して行ったテストが現れ、その後、下のテストデータで「億万」という繰り返し分節量詞Bugが現れた.
    ここでは「アルゴリズムの楽しさ」で提供されたテストデータを使用します.メガ分節が増加したため,従来のベースにメガ分節のテストデータが増加した.
    (define ch-test-list
      '((" " " " " " " " " " " " " " " " " " " " "  " "   " "    " "     " "  " "    " "     " "    " "      " "  " "  " "     " "    " "   " "   " "   " "  " "   " "     " "      " "      " "        " "       " "            " "        " "           " "            " "            " "                   " "                                 " "                                                          ")
        (" " " " " " " " " " " " " " " " " " " " "  " "   " "    " "     " "  " "    " "     " "    " "      " "  " "  " "     " "    " "   " "   " "   " "  " "   " "     " "      " "      " "        " "       " "            " "        " "           " "            " "            " "                   " "                                 " "                                                          ")
        (0 1 2 3 4 5 6 7 8 9 10 11 110 111 100 102 1020 1001 1015 1000 10000 20010 20001 100000 1000000 10000000 100000000 1000000000 1000001000 1000000100 200010 2000105 20001007 2000100190 1040010000 200012301 2005010010 4009060200 4294967295 12345006789001234069 5843602890024812345006789001234069)))

    ここでは、ネストされたリスト(2 D配列)でテストデータが保存され、提供されていることがわかります.
    二、変換プログラムのインポート
    (require "number-chinese.rkt"
             "chinese-number.rkt")

    三、アラビア数字から中国語数字への転換をテストする
    for/listでリストを遍歴して検出すればよい.
    ;       :
    (display ;      。
     (for/list [(num (list-ref ch-test-list 2))
                (ch (list-ref ch-test-list 0))]
       (if (equal? (number->chinese num) ch)
           (format "~a->~a
    "
    num ch)
    (format " !~a ~a, ~a
    "
    num ch (number->chinese num))
    )
    )
    )
    (display ; 。 (for/list [(num (list-ref ch-test-list 2)) (ch-t (list-ref ch-test-list 1))] (if (equal? (number->chinese num #:style 'capitalization) ch-t) (format "~a->~a
    "
    num ch-t)
    (format " !~a ~a, ~a
    "
    num ch-t (number->chinese num #:style 'capitalization))
    )
    )
    )

    四、中国語の数字をテストしてアラビア数字を回転する
    同上.
    ;       :
    (display ;      。
     (for/list [(ch (list-ref ch-test-list 0))
                (num (list-ref ch-test-list 2))]
       (if (= (chinese->number ch) num)
           (format "~a->~a
    "
    ch num)
    (format " !~a ~a, ~a。
    "
    ch num (chinese->number ch))
    )
    )
    )
    (display ; 。 (for/list [(ch-t (list-ref ch-test-list 1)) (num (list-ref ch-test-list 2))] (if (= (chinese->number ch-t #:style 'capitalization) num) (format "~a->~a
    "
    ch-t num)
    (format " !~a ~a, ~a。
    "
    ch-t num (chinese->number ch-t #:style 'capitalization))
    )
    )
    )

    五、全てのソースプログラム
    #lang racket
    (require "number-chinese.rkt"
             "chinese-number.rkt")
    
    (define ch-test-list
      '((" " " " " " " " " " " " " " " " " " " " "  " "   " "    " "     " "  " "    " "     " "    " "      " "  " "  " "     " "    " "   " "   " "   " "  " "   " "     " "      " "      " "        " "       " "            " "        " "           " "            " "            " "                   " "                                 " "                                                          ")
        (" " " " " " " " " " " " " " " " " " " " "  " "   " "    " "     " "  " "    " "     " "    " "      " "  " "  " "     " "    " "   " "   " "   " "  " "   " "     " "      " "      " "        " "       " "            " "        " "           " "            " "            " "                   " "                                 " "                                                          ")
        (0 1 2 3 4 5 6 7 8 9 10 11 110 111 100 102 1020 1001 1015 1000 10000 20010 20001 100000 1000000 10000000 100000000 1000000000 1000001000 1000000100 200010 2000105 20001007 2000100190 1040010000 200012301 2005010010 4009060200 4294967295 12345006789001234069 5843602890024812345006789001234069)))
    
    ;       :
    (display ;      。
     (for/list [(num (list-ref ch-test-list 2))
                (ch (list-ref ch-test-list 0))]
       (if (equal? (number->chinese num) ch)
           (format "~a->~a
    "
    num ch) (format " !~a ~a, ~a
    "
    num ch (number->chinese num))))) (display ; 。 (for/list [(num (list-ref ch-test-list 2)) (ch-t (list-ref ch-test-list 1))] (if (equal? (number->chinese num #:style 'capitalization) ch-t) (format "~a->~a
    "
    num ch-t) (format " !~a ~a, ~a
    "
    num ch-t (number->chinese num #:style 'capitalization))))) ; : (display ; 。 (for/list [(ch (list-ref ch-test-list 0)) (num (list-ref ch-test-list 2))] (if (= (chinese->number ch) num) (format "~a->~a
    "
    ch num) (format " !~a ~a, ~a。
    "
    ch num (chinese->number ch))))) (display ; 。 (for/list [(ch-t (list-ref ch-test-list 1)) (num (list-ref ch-test-list 2))] (if (= (chinese->number ch-t #:style 'capitalization) num) (format "~a->~a
    "
    ch-t num) (format " !~a ~a, ~a。
    "
    ch-t num (chinese->number ch-t #:style 'capitalization)))))

    印刷したテスト結果に合格しました.