小编Pho*_*int的帖子

理解C#中的方法机制?

i当我将它传递给方法时为什么不改变?i方法调用之后的值是0,但方法仍然返回101.

class Program
{
    static void Main(string[] args)
    {
        int i = 0;
        Console.WriteLine("Before static method running i={0}", i);
        int c=   SampleClass.ExampleMethod( i);
        Console.WriteLine("i={0} - Static method return c={1}",i,c);
    }
}

class SampleClass
{
    public static int ExampleMethod(int i)
    { 
    i= 101;
    Console.WriteLine("Inside static method i={0}",i);
    return i;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# methods

0
推荐指数
1
解决办法
89
查看次数

JUnit的assertArrayEquals()如何工作?

这是使用junit4的测试类.

public class TestArrayUtilities {
 static final int[] ONE_D_MATRIX = { 12, 34, 45, 6, 7, 85, 67, 43 };
 static final int[] ONE_D_MATRIX_REMOVED_ONE= {12, 34, 45, 6, 85, 67, 43};
Run Code Online (Sandbox Code Playgroud)

removeItemWithIndex()从给定索引和返回数组的数组中删除元素.此测试非常有效.

 @Test
public void testRemoveItemWithIndex(){
assertArrayEquals(ArrayUtilities.removeItemWithIndex(ONE_D_MATRIX, 4),ONE_D_MATRIX_REMOVED_ONE);}
Run Code Online (Sandbox Code Playgroud)

removeSpecifiedElementInArray()从具有指定值的数组中删除元素并返回数组.此测试仅在写入expilicitly时才有效.所以在这个例子中只有第二个有效.

assertArrayEquals(ArrayUtilities.removeSpecifiedElementInArray(ONE_D_MATRIX, 7), ONE_D_MATRIX_REMOVED_ONE);
assertArrayEquals(ArrayUtilities.removeSpecifiedElementInArray(new int[]  { 12, 34, 45, 6, 7, 85, 67, 43 }, 7), new int[] {12, 34, 45, 6, 85, 67, 43});
Run Code Online (Sandbox Code Playgroud)

JUnit说:

java.lang.AssertionError:数组长度不同,expected.length = 8 actual.length = 7

这是一个错误吗?第一种方法为什么第二种方法不起作用呢?

java junit unit-testing

0
推荐指数
1
解决办法
690
查看次数

标签 统计

c# ×1

java ×1

junit ×1

methods ×1

unit-testing ×1