PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/csharp/csharp_lib_arrays_runme.cs

#
C# | 70 lines | 56 code | 14 blank | 0 comment | 7 complexity | 2b7c8f400f4d9f80634f4f805e7bd4fa MD5 | raw file
 1using System;
 2using csharp_lib_arraysNamespace;
 3
 4public class runme
 5{
 6  static void Main() 
 7  {
 8    {
 9      int[] source = { 1, 2, 3, 4, 5 };
10      int[] target = new int[ source.Length ];
11
12      csharp_lib_arrays.myArrayCopy( source, target, target.Length );
13      CompareArrays(source, target);
14    }
15
16    {
17      int[] source = { 1, 2, 3, 4, 5 };
18      int[] target = new int[ source.Length ];
19
20      csharp_lib_arrays.myArrayCopyUsingFixedArrays( source, target, target.Length );
21      CompareArrays(source, target);
22    }
23
24    {
25      int[] source = { 1, 2, 3, 4, 5 };
26      int[] target = new int[] { 6, 7, 8, 9, 10 };
27
28      csharp_lib_arrays.myArraySwap( source, target, target.Length );
29
30      for (int i=0; i<target.Length; ++i)
31        target[i] += 5;
32      CompareArrays(source, target);
33    }
34
35    {
36      int[] source = { 1, 2, 3, 4, 5 };
37      int[] target = new int[] { 6, 7, 8, 9, 10 };
38
39      csharp_lib_arrays.myArraySwapUsingFixedArrays( source, target, target.Length );
40
41      for (int i=0; i<target.Length; ++i)
42        target[i] += 5;
43      CompareArrays(source, target);
44    }
45  }
46  
47  static void CompareArrays( int[] a, int[] b ) 
48  {
49    if (a.Length != b.Length)
50      throw new Exception("size mismatch");
51
52    for(int i=0; i<a.Length; ++i) {
53      if (a[i] != b[i]) {
54        Console.Error.WriteLine("a:");
55        PrintArray(a);
56        Console.Error.WriteLine("b:");
57        PrintArray(b);
58        throw new Exception("element mismatch");
59      }
60    }
61  }
62
63  static void PrintArray( int[] a ) 
64  {
65    foreach ( int i in a ) 
66      Console.Error.Write( "{0} ", i );
67    Console.Error.WriteLine();
68  }
69}
70