douguan8940 2014-04-07 23:18
浏览 14
已采纳

C - 编写自定义处理程序

I've written a custom test method in PHP to give me a custom response when running simple tests. Is there a way to implement this in C without having to re-invent the wheel?

function test($assertion, $msg = null)
{
    assert_options(ASSERT_WARNING, false);

    if(assert($assertion))
    {
        echo "PASS: {$assertion}
";
    }
    else
    {
        echo $msg, "
", "FAIL: {$assertion}
";
    }
}

My solution: (edit)

void test(bool expected, bool actual)
{
    printf((expected == actual) ? "PASS" : "FAIL");
}
  • 写回答

1条回答 默认 最新

  • doucheng7534 2014-04-07 23:58
    关注

    I think this is what you're looking for:

    void test(bool expected, bool actual, char *msg)
    {
        printf(((expected == actual) ? "PASS: %s
    " : "FAIL: %s
    "), msg);
    }
    

    It has the same test-like characteristics and it outputs a simple message in the same format as your PHP function. Note that I have not tested this and I'm not sure if the ternary in the printf actually compiles, but my guess is that it does.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码