// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. // using System; using System.Numerics; internal partial class VectorTest { private const int Pass = 100; private const int Fail = -1; private class VectorRelopTest where T : struct, IComparable, IEquatable { public static int VectorRelOp(T larger, T smaller) { const int Pass = 100; const int Fail = -1; int returnVal = Pass; Vector A = new Vector(larger); Vector B = new Vector(smaller); Vector C = new Vector(larger); Vector D; // less than Vector condition = Vector.LessThan(A, B); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(B[i])) { Console.WriteLine("Less than condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } condition = Vector.LessThan(B, A); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(A[i])) { Console.WriteLine("Less than condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } // greater than condition = Vector.GreaterThan(A, B); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(A[i])) { Console.WriteLine("Greater than condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } condition = Vector.GreaterThan(B, A); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(B[i])) { Console.WriteLine("Greater than condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } // less than or equal condition = Vector.LessThanOrEqual(A, C); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(A[i])) { Console.WriteLine("Less than or equal condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } condition = Vector.LessThanOrEqual(A, B); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(B[i])) { Console.WriteLine("Less than or equal condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } // greater than or equal condition = Vector.GreaterThanOrEqual(A, C); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(A[i])) { Console.WriteLine("Greater than or equal condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } condition = Vector.GreaterThanOrEqual(B, C); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(B[i])) { Console.WriteLine("Greater than or equal condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } // equal condition = Vector.Equals(A, C); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(A[i])) { Console.WriteLine("Equal condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } condition = Vector.Equals(B, C); D = Vector.ConditionalSelect(condition, A, B); for (int i = 0; i < Vector.Count; i++) { if (!D[i].Equals(B[i])) { Console.WriteLine("Equal condition failed for type " + typeof(T).Name + " at index " + i); returnVal = Fail; } } return returnVal; } } private static int Main() { int returnVal = Pass; if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3, 2) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(-2, -3) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(-2, -3) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3u, 2u) != Pass) returnVal = Fail; if (VectorRelopTest.VectorRelOp(3ul, 2ul) != Pass) returnVal = Fail; return returnVal; } }