PageRenderTime 32ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. using System;
  2. using csharp_lib_arraysNamespace;
  3. public class runme
  4. {
  5. static void Main()
  6. {
  7. {
  8. int[] source = { 1, 2, 3, 4, 5 };
  9. int[] target = new int[ source.Length ];
  10. csharp_lib_arrays.myArrayCopy( source, target, target.Length );
  11. CompareArrays(source, target);
  12. }
  13. {
  14. int[] source = { 1, 2, 3, 4, 5 };
  15. int[] target = new int[ source.Length ];
  16. csharp_lib_arrays.myArrayCopyUsingFixedArrays( source, target, target.Length );
  17. CompareArrays(source, target);
  18. }
  19. {
  20. int[] source = { 1, 2, 3, 4, 5 };
  21. int[] target = new int[] { 6, 7, 8, 9, 10 };
  22. csharp_lib_arrays.myArraySwap( source, target, target.Length );
  23. for (int i=0; i<target.Length; ++i)
  24. target[i] += 5;
  25. CompareArrays(source, target);
  26. }
  27. {
  28. int[] source = { 1, 2, 3, 4, 5 };
  29. int[] target = new int[] { 6, 7, 8, 9, 10 };
  30. csharp_lib_arrays.myArraySwapUsingFixedArrays( source, target, target.Length );
  31. for (int i=0; i<target.Length; ++i)
  32. target[i] += 5;
  33. CompareArrays(source, target);
  34. }
  35. }
  36. static void CompareArrays( int[] a, int[] b )
  37. {
  38. if (a.Length != b.Length)
  39. throw new Exception("size mismatch");
  40. for(int i=0; i<a.Length; ++i) {
  41. if (a[i] != b[i]) {
  42. Console.Error.WriteLine("a:");
  43. PrintArray(a);
  44. Console.Error.WriteLine("b:");
  45. PrintArray(b);
  46. throw new Exception("element mismatch");
  47. }
  48. }
  49. }
  50. static void PrintArray( int[] a )
  51. {
  52. foreach ( int i in a )
  53. Console.Error.Write( "{0} ", i );
  54. Console.Error.WriteLine();
  55. }
  56. }