Exemple #1
0
 private void CheckBounded(System.Func <NumberValue> supplier)
 {
     for (int i = 0; i < ITERATIONS; i++)
     {
         NumberValue value = supplier();
         assertThat(value, notNullValue());
         assertThat(value.CompareTo(ZERO_INT), greaterThanOrEqualTo(0));
         assertThat(value.CompareTo(_upper), lessThan(0));
     }
 }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void nextNumberValue()
        public virtual void NextNumberValue()
        {
            HashSet <Type> seen = new HashSet <Type>(_numberTypes);

            for (int i = 0; i < ITERATIONS; i++)
            {
                NumberValue numberValue = RandomValues.nextNumberValue();
                assertThat(_numberTypes, hasItem(numberValue.GetType()));
                seen.remove(numberValue.GetType());
            }
            assertThat(seen, empty());
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldMultiplySimpleIntegers()
        internal virtual void ShouldMultiplySimpleIntegers()
        {
            NumberValue[] integers = new NumberValue[] { byteValue(( sbyte )42), shortValue(( short )42), intValue(42), longValue(42) };

            foreach (NumberValue a in integers)
            {
                foreach (NumberValue b in integers)
                {
                    assertThat(a.Times(b), equalTo(longValue(42 * 42)));
                    assertThat(b.Times(a), equalTo(longValue(42 * 42)));
                }
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSubtractSimpleIntegers()
        internal virtual void ShouldSubtractSimpleIntegers()
        {
            NumberValue[] integers = new NumberValue[] { byteValue(( sbyte )42), shortValue(( short )42), intValue(42), longValue(42) };

            foreach (NumberValue a in integers)
            {
                foreach (NumberValue b in integers)
                {
                    assertThat(a.Minus(b), equalTo(longValue(0)));
                    assertThat(b.Minus(a), equalTo(longValue(0)));
                }
            }
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDivideSimpleIntegers()
        internal virtual void ShouldDivideSimpleIntegers()
        {
            NumberValue[] integers = new NumberValue[] { byteValue(( sbyte )42), shortValue(( short )42), intValue(42), longValue(42) };

            foreach (NumberValue a in integers)
            {
                foreach (NumberValue b in integers)
                {
                    assertThat(a.DivideBy(b), equalTo(longValue(1)));
                    assertThat(b.DivideBy(a), equalTo(longValue(1)));
                }
            }
        }
Exemple #6
0
        public DurationValue Div(NumberValue number)
        {
            double divisor = number.DoubleValue();

            try
            {
                return(Approximate(_months / divisor, _days / divisor, _seconds / divisor, _nanos / divisor));
            }
            catch (ArithmeticException e)
            {
                throw InvalidDurationDivision(this, number, e);
            }
        }
Exemple #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldAddSimpleFloats()
        internal virtual void ShouldAddSimpleFloats()
        {
            NumberValue[] integers = new NumberValue[] { byteValue(( sbyte )42), shortValue(( short )42), intValue(42), longValue(42) };
            NumberValue[] floats   = new NumberValue[] { floatValue(42), doubleValue(42) };

            foreach (NumberValue a in integers)
            {
                foreach (NumberValue b in floats)
                {
                    assertThat(a.Plus(b), equalTo(doubleValue(84)));
                    assertThat(b.Plus(a), equalTo(doubleValue(84)));
                }
            }
        }
Exemple #8
0
 public DurationValue Mul(NumberValue number)
 {
     try
     {
         if (number is IntegralValue)
         {
             long factor = number.LongValue();
             return(Duration(Math.multiplyExact(_months, factor), Math.multiplyExact(_days, factor), Math.multiplyExact(_seconds, factor), Math.multiplyExact(_nanos, factor)));
         }
         if (number is FloatingPointValue)
         {
             double factor = number.DoubleValue();
             return(Approximate(_months * factor, _days * factor, _seconds * factor, _nanos * factor));
         }
     }
     catch (ArithmeticException e)
     {
         throw InvalidDurationMultiply(this, number, e);
     }
     throw new InvalidValuesArgumentException("Factor must be either integer of floating point number.");
 }
Exemple #9
0
 private InvalidValuesArgumentException InvalidDurationDivision(DurationValue o1, NumberValue numberValue, ArithmeticException e)
 {
     return(new InvalidValuesArgumentException(string.Format("Can not divide duration {0} with {1} without causing overflow.", o1.ToString(), numberValue.ToString()), e));
 }