【问题标题】:tescase for javascript code finding closest to zerotescase 用于查找最接近于零的 javascript 代码
【发布时间】:2013-12-15 05:20:56
【问题描述】:

我想知道我的代码的测试用例是什么。 在下面提供我的代码... 如何在 jasmine 中编写测试用例 代码完全在js中...

function lowestEpsilon(of) {

    return of.reduce(minimal, [Infinity, Infinity]).shift()

    // pass around a pair of [value, Math.abs(value)] and replace
    // it if the current item has a better absolute value.
    function minimal(previously, value) {
        var absolute = Math.abs(value)
        if ( absolute < previously[1] )
            return [value, absolute]
        return previously
    }
}

lowestEpsilon([1,2,-0.5])

lowestEpsilon([50,0.3,-0.2,1,50])

【问题讨论】:

  • 嗨,您可以编辑以澄清您的问题吗? (看起来底部已经有两个测试用例了。)
  • @KevinChen: jasmine 测试用例我需要写..谢谢你的回复..

标签: javascript unit-testing testing automated-tests jasmine


【解决方案1】:

我真的不知道你的测试名称或类应该是什么,但这里是你在 Jasmine 中用来编写你指定的两个测试用例的基本大纲。

describe("my tests", function () {

    it("case 1", function () {
        var low = lowestEpsilon([1, 2, -0.5]);
        expect(low).toBe(0.5);
    });

    it("case 2", function () {
        var low = lowestEpsilon([50, 0.3, -0.2, 1, 50])
        expect(low).toBe(0.2);
    });
});

【讨论】:

    猜你喜欢
    • 2014-05-27
    • 2015-05-25
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    相关资源
    最近更新 更多