summaryrefslogtreecommitdiff
path: root/Examples/test-suite/csharp/csharp_lib_arrays_bool_runme.cs
blob: 3b19b576fae441319b05a11cf5973f39792543c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using csharp_lib_arrays_boolNamespace;

public class runme
{
  static void Main() 
  {
    {
      bool[] source = { true, false, false, true, false, true, true, false };
      bool[] target = new bool[ source.Length ];

      csharp_lib_arrays_bool.myArrayCopyUsingFixedArraysBool( source, target, target.Length );
      CompareArrays(source, target, "bool[] INPUT/OUTPUT Fixed");
    }
    
    {
      bool[] source = { true, false, false, true, false, true, true, false };
      bool[] target = { false, true, true, false, true, false, false, true };

      csharp_lib_arrays_bool.myArraySwapUsingFixedArraysBool( source, target, target.Length );

      for (int i=0; i<target.Length; ++i)
        target[i] = !target[i];

      CompareArrays(source, target, "bool[] INOUT");
    }

    if( runtimeIsMono() )
    {
//      Console.Error.WriteLine("Tests are running on mono, failing bool[] tests skipped");
//      See Mono bug report https://github.com/mono/mono/issues/15592
      return;
    }

    {
      bool[] source = { true, false, false, true, false, true, true, false };
      bool[] target = new bool[ source.Length ];

      if( !csharp_lib_arrays_bool.checkBoolArrayCorrect( source, source.Length ) )
      {
        throw new Exception("bool[] INPUT incorrect");
      }

      csharp_lib_arrays_bool.myArrayCopyBool( source, target, target.Length );
      CompareArrays(source, target, "bool[] INPUT/OUTPUT");
    }

    {
      bool[] source = { true, false, false, true, false, true, true, false };
      bool[] target = { false, true, true, false, true, false, false, true };

      csharp_lib_arrays_bool.myArraySwapBool( source, target, target.Length );

      for (int i=0; i<target.Length; ++i)
        target[i] = !target[i];

      CompareArrays(source, target, "bool[] INOUT");
    }
  }
  
  static void CompareArrays<T>( T[] a, T[] b, string testName ) 
  {
    if (a.Length != b.Length)
      throw new Exception("size mismatch");

    for(int i=0; i<a.Length; ++i) {
      if (a[i].Equals(b[i]) == false) {
        Console.Error.WriteLine("C# Array mismatch: " + testName);
        Console.Error.WriteLine("a:");
        PrintArray(a);
        Console.Error.WriteLine("b:");
        PrintArray(b);
        throw new Exception("element mismatch");
      }
    }
  }

  static void PrintArray<T>( T[] a )
  {
    foreach ( T i in a )
      Console.Error.Write( "{0} ", i );
    Console.Error.WriteLine();
  }

  static bool runtimeIsMono()
  {
    return Type.GetType ("Mono.Runtime") != null;
  }
}