예제 #1
0
        public void DoNotCrashOnBadInput()
        {
            // For error recovery, do not throw exceptions on bad inputs.
            var ctors = new IValueSetFactory[]
            {
                ForByte,
                ForSByte,
                ForChar,
                ForShort,
                ForUShort,
                ForInt,
                ForUInt,
                ForLong,
                ForULong,
                ForBool,
                ForFloat,
                ForDouble,
                ForString,
                ForDecimal,
                ForNint,
                ForNuint
            };
            ConstantValue badConstant = ConstantValue.Bad;

            foreach (IValueSetFactory fac in ctors)
            {
                foreach (BinaryOperatorKind relation in new[] { LessThan, Equal, NotEqual })
                {
                    IValueSet set = fac.Related(relation, badConstant);
                    _ = set.All(relation, badConstant);
                    _ = set.Any(relation, badConstant);
                }
            }
        }
예제 #2
0
            public bool Any(BinaryOperatorKind relation, TFloating value)
            {
                TFloatingTC tc = default;

                return
                    (_hasNaN && tc.Related(relation, tc.NaN, value) ||
                     _numbers.Any(relation, value));
            }
예제 #3
0
 public void TestAny_01()
 {
     for (int i = 0; i < 100; i++)
     {
         int i1 = Random.Next(int.MinValue, int.MaxValue);
         int i2 = Random.Next(int.MinValue, int.MaxValue);
         if (i1 > i2)
         {
             (i1, i2) = (i2, i1);
         }
         IValueSet <int> values = ForInt
                                  .Related(GreaterThanOrEqual, i1)
                                  .Intersect(ForInt.Related(LessThanOrEqual, i2));
         Assert.Equal($"[{i1}..{i2}]", values.ToString());
         test(int.MinValue);
         if (i1 != int.MinValue)
         {
             test(i1 - 1);
         }
         test(i1);
         test(i1 + 1);
         test(int.MaxValue);
         if (i2 != int.MinValue)
         {
             test(i2 - 1);
         }
         test(i2);
         test(i2 + 1);
         void test(int val)
         {
             Assert.Equal(val >= i1 && val <= i2, values.Any(Equal, val));
             Assert.Equal(val >= i1, values.Any(LessThanOrEqual, val));
             Assert.Equal(val > i1, values.Any(LessThan, val));
             Assert.Equal(val <= i2, values.Any(GreaterThanOrEqual, val));
             Assert.Equal(i2 > val, values.Any(GreaterThan, val));
         }
     }
 }