;================================================================
; test/unit_test 单元测试
; unit_test_func_mahjong_hand.erb 手牌相关
;================================================================


;;;单元测试 @mj_call_chii
;;;@return 1通过 0未通过
@unit_test_func_mj_call_chii()
{
    #DIMS CONST TestCase, 6 =
        "1m2m3m4m5m5m0m6m7m8m9m1z1z 4m 2m3m,3m5m,3m0m,5m6m,0m6m",
        "1p2p3p4p5p5p0p6p7p8p 5p 3p4p,4p6p,6p7p",
        "4s5s5s0s6s7s8s 6s 4s5s,4s0s,5s7s,0s7s,7s8s",
        "1m2m3m4m5m5m5m6m7m8m9m1z1z 4m 2m3m,3m5m,5m6m",
        "1p2p3p4p5p5p5p6p7p8p 0p 3p4p,4p6p,6p7p",
        "4s5s5s5s6s7s8s 6s 4s5s,5s7s,7s8s"
}
    #DIMS DYNAMIC temp, 3
    #DIMS DYNAMIC test_result
    #DIM DYNAMIC i
    FOR i, 0, VARSIZE("TestCase")
        SPLIT TestCase:i, " ", temp
        test_result '= mj_call_chii(temp:0, temp:1)
        IF test_result != temp:2
            CALL PrintLog(@"输入=%temp:0%_%temp:1% 期望输出=%temp:2% 实际输出=%test_result%", "test")
            SETTEXTBOX test_result
            RETURN 0
        ENDIF
    NEXT
    RETURN 1


;;;单元测试 @mj_call_pon
;;;@return 1通过 0未通过
@unit_test_func_mj_call_pon()
{
    #DIMS CONST TestCase, 7 =
        "1m2m3m4m5m5m0m6m7m8m9m1z1z 5m 5m0m,5m5m",
        "1p2p3p4p5p5p0p6p2z2z 5p 5p0p,5p5p",
        "4s5s5s0s6s3z3z 5s 5s0s,5s5s",
        "1m2m3m4m5m5m5m6m7m8m9m1z1z 0m 5m5m",
        "1p2p3p4p5p5p5p6p2z2z 0p 5p5p",
        "4s5s5s5s6s3z3z 0s 5s5s",
        "1z1z1z2z2z2z3z3z3z4z4z5z5z 4z 4z4z"
}
    #DIMS DYNAMIC temp, 3
    #DIMS DYNAMIC test_result
    #DIM DYNAMIC i
    FOR i, 0, VARSIZE("TestCase")
        SPLIT TestCase:i, " ", temp
        test_result '= mj_call_pon(temp:0, temp:1)
        IF test_result != temp:2
            CALL PrintLog(@"输入=%temp:0%_%temp:1% 期望输出=%temp:2% 实际输出=%test_result%", "test")
            RETURN 0
        ENDIF
    NEXT
    RETURN 1


;;;单元测试 @mj_call_kan
;;;@return 1通过 0未通过
@unit_test_func_mj_call_kan()
{
    #DIMS CONST TestCase, 7 =
        "1m2m3m4m5m5m0m6m7m8m9m1z1z 5m 5m5m0m",
        "1p2p3p4p5p5p0p6p2z2z 5p 5p5p0p",
        "4s5s5s0s6s3z3z 5s 5s5s0s",
        "1m2m3m4m5m5m5m6m7m8m9m1z1z 0m 5m5m5m",
        "1p2p3p4p5p5p5p6p2z2z 0p 5p5p5p",
        "4s5s5s5s6s3z3z 0s 5s5s5s",
        "1z1z1z2z2z2z3z3z3z4z4z5z5z 3z 3z3z3z"
}
    #DIMS DYNAMIC temp, 3
    #DIMS DYNAMIC test_result
    #DIM DYNAMIC i
    FOR i, 0, VARSIZE("TestCase")
        SPLIT TestCase:i, " ", temp
        test_result '= mj_call_kan(temp:0, temp:1)
        IF test_result != temp:2
            CALL PrintLog(@"输入=%temp:0%_%temp:1% 期望输出=%temp:2% 实际输出=%test_result%", "test")
            RETURN 0
        ENDIF
    NEXT
    RETURN 1


;;;单元测试 @mj_count_shanten
;;;@return 1通过 0未通过
@unit_test_func_mj_count_shanten()
    #DIMS DYNAMIC test_case, 100
    #DIMS DYNAMIC temp, 3
    #DIMS DYNAMIC test_result
    #DIM DYNAMIC i
    RESULTS '= REPLACE(LOADTEXT("erb/test/unit_test/test_case/shanten.csv"), "\r\n", "\n")
    SPLIT RESULTS, "\n", test_case
    FOR i, 0, RESULT
        SIF test_case:i == ""
            CONTINUE
        VARSET temp, ""
        SPLIT test_case:i, ",", temp
        ; CALL PrintLog(@"{i + 1, 2}. 单元测试 向听数计算 %temp:2%", "test")
        test_result '= TOSTR(mj_count_shanten(temp:0))
        IF test_result != temp:1
            CALL PrintLog(@"    输入=%temp:0% 期望输出=%temp:1% 实际输出=%test_result%", "test")
            RETURN 0
        ENDIF
    NEXT
    RETURN 1
