swig/Examples/test-suite/csharp/complextest_runme.cs
Vadim Zeitlin ec565f74cf Extend C# complex support to member variables of this type
Define csvar{in,out} typemaps needed to support properties of complex type and
apply the existing cstype and csin ones to them as well.

Add unit test verifying that this works as expected in C# and, also, in
Python, even though no changes were needed there.
2017-04-01 23:51:45 +02:00

34 lines
1 KiB
C#

// This is the complex runtime testcase. It checks that the C++ std::complex type works.
// It requires .NET 4.0 as the previous versions didn't have System.Numerics.Complex type.
using System;
using System.Numerics;
using complextestNamespace;
public class complextest_runme {
public static void Main() {
var a = new Complex(-1, 2);
if ( complextest.Conj(a) != Complex.Conjugate(a) )
throw new Exception("std::complex<double> test failed");
if ( complextest.Conjf(a) != Complex.Conjugate(a) )
throw new Exception("std::complex<float> test failed");
var vec = new VectorStdCplx();
vec.Add(new Complex(1, 2));
vec.Add(new Complex(2, 3));
vec.Add(new Complex(4, 3));
vec.Add(new Complex(1, 0));
if ( complextest.Copy_h(vec).Count != 2 )
throw new Exception("vector<complex> test failed");
var p = new ComplexPair();
p.z1 = new Complex(0, 1);
p.z2 = new Complex(0, -1);
if ( Complex.Conjugate(p.z2) != p.z1 )
throw new Exception("vector<complex> test failed");
}
}