1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        theftC 的屬性測試庫

        聯(lián)合創(chuàng)作 · 2023-09-28 17:08

        theft 是基于屬性測試的 C 庫。theft 并不是使用定義特定的輸入,運(yùn)行代碼,然后測試和檢測結(jié)果的方式,而是進(jìn)行屬性斷言(“任意可能的輸入,[條件]應(yīng)該一直存在”),尋找反例。如果找到一個(gè)參數(shù)導(dǎo)致斷言失敗,將會繼續(xù)尋找更簡單的參數(shù),如果仍然失敗,打印最小的失敗輸入。

        安裝 & 依賴

        theft 只依賴 C99。

        構(gòu)建:

        $ make

        構(gòu)建和運(yùn)行測試:

        $ make test

        安裝 libtheft :

        $ make install    # using sudo, if necessary
        

        用法

        首先,定義屬性函數(shù):

        static theft_trial_res
        prop_encoded_and_decoded_data_should_match(buffer *input) {
            // [compress & uncompress input, compare output & original input]
            // return THEFT_TRIAL_PASS, FAIL, SKIP, or ERROR
        }

        然后,生成測試參數(shù):

        static struct theft_type_info random_buffer_info = {
            .alloc = random_buffer_alloc_cb,    // allocate random instance
            .free = random_buffer_free_cb,      // free instance
            .hash = random_buffer_hash_cb,      // get hash of instance
            .shrink = random_buffer_shrink_cb,  // simplify instance
            .print = random_buffer_print_cb,    // print instance
        };

        最后,實(shí)例化:

        struct theft *t = theft_init(0);   // 0 -> auto-size bloom filter
        
        // Configuration for the property test
        struct theft_cfg cfg = {
            // name of the property, used for failure messages (optional)
            .name = __func__,
        
            // the property function under test
            .fun = prop_encoded_and_decoded_data_should_match,
        
            // list of structs with argument info; the property function
            // will be called with this many arguments
            .type_info = { &random_buffer_info },
        
            // number of trials to run; defaults to 100
            .trials = 1000,
        };
        
        // Run the property test. Any failures will be printed, with seeds.
        theft_run_res result = theft_run(t, &cfg);
        theft_free(t);
        return result == THEFT_RUN_PASS;

         

         

        瀏覽 24
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            国产精品白浆一区二小说 | www.做爱网站 | 三级片国产在线观看 | 做爱视屏网站 | 草草久久久亚洲黑人AV成人片 | 操逼视频免费观看操逼 | 女人被狂躁到高潮视频免费网站 | 久久久久久91香蕉国产 | 国产在线拍揄自揄拍无码网站新闻 | 夜夜操天天 |