Exemple #1
0
        public void Ctor_EmptyParameters_ObjectCreatedIsZero()
        {
            var actual = new Fixed8();

            Asserting
            .That(actual)
            .IsZero();
        }
Exemple #2
0
        public void SmallerThan_OperatorOneIsSmallerOperatorTwo_ReturnTrue()
        {
            var operatorOne = new Fixed8(5);
            var operatorTwo = new Fixed8(10);

            Asserting
            .That(operatorOne)
            .IsSmallerThan(operatorTwo);
        }
Exemple #3
0
        public void Abs_ProvidePositiveFixed8_ReturnTheSameValue()
        {
            var positiveFixed8 = new Fixed8(1);

            var resultAbsoluteFixed8 = positiveFixed8.Abs();

            Asserting
            .That(resultAbsoluteFixed8)
            .IsEqual(positiveFixed8);
        }
Exemple #4
0
        public void Ceilling_Provide100000000Fixed8Object_NoCellingNeeded()
        {
            var actual = new Fixed8(100000000);

            var cellingValue = actual.Ceiling();

            Asserting
            .That(cellingValue)
            .IsEqual(actual);
        }
Exemple #5
0
        public void OperatorUnaryNagation_ReturnNegativeFixed8()
        {
            var operatorOne = new Fixed8(1);

            var actual = -operatorOne;

            Asserting
            .That(actual)
            .AsLongValue(-1);
        }
Exemple #6
0
        public void Equal_Fixed8AndNull_NotEqual()
        {
            const long expectedLongValue = long.MaxValue;

            var firstOperator = new Fixed8(expectedLongValue);

            Asserting
            .That(firstOperator)
            .IsNotEqual(null);
        }
Exemple #7
0
        public void Ctor_WithLongMaxValue_ObjectCreateWithLongMaxValue()
        {
            const long expectedLongValue = long.MaxValue;

            var actual = new Fixed8(expectedLongValue);

            Asserting
            .That(actual)
            .AsLongValue(expectedLongValue);
        }
Exemple #8
0
        public void Min_ReturnFixed8ObjectWithLongMinValue()
        {
            const long expectedLongValue = long.MinValue;

            var minFixed8 = Fixed8.MinValue;

            Asserting
            .That(minFixed8)
            .AsLongValue(expectedLongValue);
        }
Exemple #9
0
        public void Equal_TwoFixed8FieldWithDifferentValues_NotEqual()
        {
            const long expectedLongValue = long.MaxValue;

            var firstOperator  = new Fixed8(expectedLongValue);
            var secondOperator = new Fixed8();

            Asserting
            .That(firstOperator)
            .IsNotEqual(secondOperator);
        }
Exemple #10
0
        public void OperatorAddition_ReturnSumOfValues()
        {
            var operatorOne = new Fixed8(10);
            var operatorTwo = new Fixed8(5);

            var actual = operatorOne + operatorTwo;

            Asserting
            .That(actual)
            .AsLongValue(15);
        }
Exemple #11
0
        public void OperatorSubtraction_ReturnDifferenceBetweenValues()
        {
            var operatorOne = new Fixed8(10);
            var operatorTwo = new Fixed8(5);

            var actual = operatorOne - operatorTwo;

            Asserting
            .That(actual)
            .AsLongValue(5);
        }
Exemple #12
0
        public void Equal_TwoFixed8FieldsWithSameValue_IsEqual()
        {
            const long expectedLongValue = long.MaxValue;

            var firstOperator  = new Fixed8(expectedLongValue);
            var secondOperator = new Fixed8(expectedLongValue);

            Asserting
            .That(firstOperator)
            .IsEqual(secondOperator);
        }
Exemple #13
0
        public void Ceilling_Provide100500000Fixed8Object_RemaiderLessThanZeroLogic()
        {
            var actual = new Fixed8(-100500000);
            var expectedCeillingFixed8 = new Fixed8(-100000000);

            var cellingValue = actual.Ceiling();

            Asserting
            .That(cellingValue)
            .IsEqual(expectedCeillingFixed8);
        }
Exemple #14
0
        public void Abs_ProvideNegativeFixed8_ReturnPositiveVersionOfTheFixed8()
        {
            var negativeFixed8            = new Fixed8(-1);
            var expectedPositiveLongValue = negativeFixed8.Value * -1;

            var resultAbsoluteFixed8 = negativeFixed8.Abs();

            Asserting
            .That(resultAbsoluteFixed8)
            .AsLongValue(expectedPositiveLongValue);
        }
Exemple #15
0
        public void OperatorMultiply_Fixed8ValueAndLongValue_ReturnMultiplicationOfValues()
        {
            var        operatorOne = new Fixed8(500000000);
            const long operatorTwo = 5;

            var actual = operatorOne * operatorTwo;

            Asserting
            .That(actual)
            .AsLongValue(2500000000);
        }
Exemple #16
0
        public void TryParse_MinLongValueAsString_ParseReturnZero()
        {
            var minLongString = long.MinValue.ToString();

            var tryParseResult = Fixed8.TryParse(minLongString, out var fixed8Result);

            tryParseResult.Should().BeFalse();
            Asserting
            .That(fixed8Result)
            .IsZero();                      // TODO #411 [AboimPinto]: Don't know if ZERO is the correct value when the TryParse fail.
        }
Exemple #17
0
        public void TryParse_InvalidLongValueAsString_ParseReturnFormatException()
        {
            const string invalidString = "xxx";

            var tryParseResult = Fixed8.TryParse(invalidString, out var fixed8Result);

            tryParseResult.Should().BeFalse();
            Asserting
            .That(fixed8Result)
            .IsZero();                      // TODO #411 [AboimPinto]: Don't know if ZERO is the correct value when the TryParse fail.
        }
Exemple #18
0
        public void Parse_ValidLongValueAsString_ParseIsOk()
        {
            const long longValue = 1;
            const int  expectedFixed8LongValue = 100000000;

            var actual = Fixed8.Parse(longValue.ToString());

            Asserting
            .That(actual)
            .AsLongValue(expectedFixed8LongValue);
        }
Exemple #19
0
        public void TryParse_MaxLongValueAsString_ParseReturnZero()
        {
            var maxLongString = long.MaxValue.ToString();

            var tryParseResult = Fixed8.TryParse(maxLongString, out var fixed8Result);

            Assert.IsFalse(tryParseResult);
            Asserting
            .That(fixed8Result)
            .IsZero();                      // TODO [AboimPinto]: Don't know if ZERO is the correct value when the TryParse fail.
        }
Exemple #20
0
        public void OperatorDivision_TwoFixed8Values_ReturnDivisionOfValues()
        {
            var        operatorOne = new Fixed8(500000000);
            const long operatorTwo = 5;

            var actual = operatorOne / operatorTwo;

            Asserting
            .That(actual)
            .AsLongValue(100000000);
        }
Exemple #21
0
        public void TryParse_ValidLongValueAsString_ParseIsOk()
        {
            const long longValue = 1;
            const int  expectedFixed8LongValue = 100000000;

            var tryParseResult = Fixed8.TryParse(longValue.ToString(), out var fixed8Result);

            tryParseResult.Should().BeTrue();
            Asserting
            .That(fixed8Result)
            .AsLongValue(expectedFixed8LongValue);
        }
Exemple #22
0
        public void Min_ProvideSeveralFixed8Objects_ReturnObjectWithMinLongValue()
        {
            var zeroFixed8 = new Fixed8();
            var maxFixed8  = Fixed8.MaxValue;
            var minFixed8  = Fixed8.MinValue;

            var min = new[] { zeroFixed8, maxFixed8, minFixed8 }.Min();

            Asserting
            .That(minFixed8)
            .IsEqual(min);
        }
Exemple #23
0
        public void SerializeDeserialize_SerializeAndDeserializeFixed8AsTheSameValue()
        {
            var memoryByteArray = new byte[255];
            var actual          = new Fixed8(1000);
            var afterReadFixed8 = new Fixed8();

            using (var writer = new BinaryWriter(new MemoryStream(memoryByteArray)))
            {
                actual.Serialize(writer);
            }

            using (var reader = new BinaryReader(new MemoryStream(memoryByteArray)))
            {
                afterReadFixed8.Deserialize(reader);
            }

            Asserting
            .That(actual)
            .IsEqual(afterReadFixed8);
        }