简体   繁体   English

如何对二进制方法进行单元测试?

[英]How to do a Unit Test for the binary method?

I need at least three unit tests for the binary method.对于二进制方法,我至少需要三个单元测试。 So far, this is what I have.到目前为止,这就是我所拥有的。

public class Test {
    int[] a = {1, 2, 3, 4, 5};

    @Test
    public void testBinarySearch(){
        assertEquals(0, Arrays.binarySearch(a, 1));
    }
}

You can add 2 checks for non available values, one for higher and lower.您可以为不可用的值添加 2 个检查,一个检查更高和更低。 Binary search gives expected place for given element but in -ve sign.二分搜索给出给定元素的预期位置,但在 -ve 符号中。

assertEquals(-6, Arrays.binarySearch(a, 555));
assertEquals(-1, Arrays.binarySearch(a, 0));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM