コード例 #1
0
ファイル: CSVRead.cs プロジェクト: scarbunkle/spnmario
 //reads csv into an int16, also supports bool-based legacy levels.
 public static Int16[,] getLevel(string s)
 {
     String[,] raw = readCSV(s);
     Int16[,] ints = new Int16[raw.GetLength(0), raw.GetLength(1)];
     for (int i = 0; i < ints.GetLength(0); i++)
     {
         for (int j = 0; j < ints.GetLength(1); j++)
         {
             try
             {
                 ints[i, j] = Convert.ToInt16(raw[i, j]);
             }
             catch
             {
                 if (raw[i, j] == "true")
                 {
                     ints[i, j] = 1;
                 }
                 else
                 {
                     ints[i, j] = 0;
                 }
             }
         }
     }
     return ints;
 }
コード例 #2
0
ファイル: Level.cs プロジェクト: scarbunkle/spnmario
 //advanced constructor
 public Level(Texture2D dirt, Int16[,] vals)
 {
     height = vals.GetLength(0);
     length = vals.GetLength(1);
     tL = new Tile[height, length];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < length; j++)
         {
             tL[i, j] = new Tile(new Rectangle(tileSide * j, tileSide * i, tileSide, tileSide), dirt, vals[i, j]);
         }
     }
 }
コード例 #3
0
        public static void CompareArray( Int16[] expected, Int16[] actual )
        {
            Assert.AreEqual(expected.Length, actual.Length, "The array should have the correct number of elements.");

            for ( Int32 rowIndex = 0; rowIndex < expected.GetLength(0); rowIndex++ ) {
                Assert.AreEqual(expected[rowIndex], actual[rowIndex], "The element at index ({0}) (zero-based) should be correct.", rowIndex);
            }
        }
コード例 #4
0
 public void EqualsTest()
 {
     var data = new Int16[,] { { 0, 0 }, { -1, -1 }, { 1, 1 } };
     var length = data.GetLength(0);
     for (var i = 0; i < length; i++)
     {
         InteropInt16 interopInt16 = data[i, 0];
         InteropInt16 interopInt162 = data[i, 1];
         Assert.IsTrue(interopInt16.Equals(interopInt162));
     }
 }
コード例 #5
0
ファイル: co5127getlength_int.cs プロジェクト: ArildF/masters
 public Boolean runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strBaseLoc;
   short[] in2Arr = new Int16[10]; 
   int[] in4Arr = new Int32[5]; 
   long[] in8Arr = new Int64[0]; 
   String[] strArr = new String[6]; 
   Boolean[] boArr = new Boolean[3]; 
   Double[] dblArr = new Double[2]; 
   Single[] snglArr = new Single[32000]; 
   Char[] chArr = new Char[10000]; 
   int rank;
   try {
   LABEL_860_GENERAL:
   do
     {
     strLoc = "Loc_819yt";
     rank = -1;
     in2Arr = new Int16[5];
     iCountTestcases++;
     try {
     in2Arr.GetLength(rank);
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_499ws! , GetLength=="+in2Arr.Length);
     } catch (IndexOutOfRangeException ioorExc) {}
     catch (Exception exc) {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_758! exc=="+exc);
     }
     strLoc = "Loc_819ee";
     rank = 1;
     in2Arr = new Int16[5];
     iCountTestcases++;
     try {
     in2Arr.GetLength(rank);
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_500ws! , GetLength=="+in2Arr.Length);
     } catch (IndexOutOfRangeException ioorExc) {}
     catch (Exception exc) {
     iCountErrors++;
     Console.WriteLine( s_strTFAbbrev+ "Err_750! exc=="+exc);
     }
     strLoc = "Loc_482wu";
     rank = 0;
     in2Arr = new Int16[10];
     iCountTestcases++;
     if(in2Arr.GetLength(rank) != 10)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_481ua! , GetLength=="+in2Arr.Length);
       }
     strLoc = "Loc_471ay";
     in4Arr = new Int32[5];
     iCountTestcases++;
     if(in4Arr.GetLength(rank) != 5)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_29qaq! , GetLength=="+in4Arr.Length);
       }
     strLoc = "Loc_982uq";
     in8Arr = new Int64[0];
     iCountTestcases++;
     if(in8Arr.GetLength(rank) != 0)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_237sy! , GetLength=="+in8Arr.Length);
       }
     strLoc = "Loc_172ms";
     boArr = new Boolean[3];
     iCountTestcases++;
     if(boArr.GetLength(rank) != 3)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_382! , GetLength=="+boArr.Length);
       }
     strLoc = "Loc_49su";
     dblArr = new Double[2];
     iCountTestcases++;
     if(dblArr.GetLength(rank) != 2)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_200su! , GetLength=="+dblArr.Length);
       }
     strLoc = "Loc_371su";
     snglArr = new Single[32000];
     iCountTestcases++;
     if(snglArr.GetLength(rank) != 32000)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_319aw! , GetLength=="+snglArr.Length);
       }
     strLoc = "Loc_129wi";
     strArr = new String[5];
     strArr[2] = null;
     iCountTestcases++;
     if(strArr.GetLength(rank) != 5)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ "Err_71ahw! , GetLength=="+strArr.Length);
       }
     } while (false);
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
コード例 #6
0
        public static bool IsEqual(this Int32[,] a, Int16[][] b, Int32 atol = 0, Double rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            if (rtol > 0)
            {
                for (int i = 0; i < b.Length; i++)
                    for (int j = 0; j < b[i].Length; j++)
{
    var A = a[i, j];
    var B = b[i][j];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

            }
            else if (atol > 0)
            {
                for (int i = 0; i < b.Length; i++)
                    for (int j = 0; j < b[i].Length; j++)
{
    var A = a[i, j];
    var B = b[i][j];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

            }
            else
            {
                for (int i = 0; i < b.Length; i++)
                    for (int j = 0; j < b[i].Length; j++)
{
    var A = a[i, j];
    var B = b[i][j];
    if (A != B)
        return false;
}

            }

            return true;
        }
コード例 #7
0
        public static bool IsEqual(this Int16[,] a, Int16[,] b, Int16 atol = 0, Double rtol = 0)
        {
    if (a == b)
        return true;
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            unsafe
            {
                fixed (Int16* ptrA = a)
                fixed (Int16* ptrB = b)
                {
                    if (rtol > 0)
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

                    }
                    else if (atol > 0)
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    if (A == B)
        continue;
    var C = A;
    var D = B;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

                    }
                    else
                    {
                        for (int i = 0; i < a.Length; i++)
{
    var A = ptrA[i];
    var B = ptrB[i];
    if (A != B)
        return false;
}

                    }
                }
            }

            return true;
        }
コード例 #8
0
        public static bool IsEqual(this Decimal[][] a, Int16[][] b, Decimal atol = 0, Decimal rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            if (rtol > 0)
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i][j];
    decimal C = (decimal)A;
    decimal D = (decimal)B;
    if (C == D)
        continue;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

            }
            else if (atol > 0)
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = a[i][j];
    var B = b[i][j];
    decimal C = (decimal)A;
    decimal D = (decimal)B;
    if (C == D)
        continue;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

            }
            else
            {
                for (int i = 0; i < a.Length; i++)
                    for (int j = 0; j < a[i].Length; j++)
{
    var A = (decimal)a[i][j];
    var B = (decimal)b[i][j];
    if (A != B)
        return false;
}

            }

            return true;
        }
コード例 #9
0
        public static bool IsEqual(this Single[] a, Int16[] b, Single atol = 0, Double rtol = 0)
        {
    if (a == null && b == null)
        return true;
    if (a == null ^ b == null)
        return false;
    int[] la = a.GetLength(true);
    int[] lb = b.GetLength(true);
    if (la.Length != lb.Length)
        return false;
    for (int i = 0; i < la.Length; i++)
        if (la[i] != lb[i])
            return false;

            if (rtol > 0)
            {
                for (int i = 0; i < a.Length; i++)
{
    var A = a[i];
    var B = b[i];
    if (A == B)
        continue;
    if (Single.IsNaN(A))
        return false;
    if (Single.IsInfinity(A))
        return false;
    var C = A;
    var D = B;
    var delta = Math.Abs(C - D);
    if (C == 0)
    {
        if (delta <= rtol)
            continue;
    }
    else if (D == 0)
    {
        if (delta <= rtol)
            continue;
    }

    if (delta <= Math.Abs(C) * rtol)
        continue;
    return false;
}

            }
            else if (atol > 0)
            {
                for (int i = 0; i < a.Length; i++)
{
    var A = a[i];
    var B = b[i];
    if (A == B)
        continue;
    if (Single.IsNaN(A))
        return false;
    if (Single.IsInfinity(A))
        return false;
    var C = A;
    var D = B;
    if (Math.Abs(C - D) <= atol)
        continue;
    return false;
}

            }
            else
            {
                for (int i = 0; i < a.Length; i++)
{
    var A = a[i];
    var B = b[i];
    if (Single.IsNaN(A))
        return false;
    if (Single.IsInfinity(A))
        return false;
    if (A != B)
        return false;
}

            }

            return true;
        }