示例#1
0
        public void MultiplyFloat2FloatUni()
        {
            AType expected = AFloat.Create(1.2 * 3.4);
            AType result   = this.engineUni.Execute <AType>("1.2 * 3.4");

            Assert.AreEqual(expected, result);
        }
示例#2
0
        public void LogXGreaterThan0AndYEqualToPositiveInf()
        {
            AType expected = AFloat.Create(0);
            AType result   = this.engine.Execute <AType>("Inf log 4");

            Assert.AreEqual(expected, result);
        }
示例#3
0
        public void IPMinAddTest()
        {
            AType expected =
                AArray.Create(
                    ATypes.AFloat,
                    AArray.Create(
                        ATypes.AFloat,
                        AFloat.Create(0),
                        AFloat.Create(1),
                        AFloat.Create(2),
                        AFloat.Create(3)
                        ),
                    AArray.Create(
                        ATypes.AFloat,
                        AFloat.Create(3),
                        AFloat.Create(4),
                        AFloat.Create(5),
                        AFloat.Create(6)
                        )
                    );

            AType result = this.engine.Execute <AType>("(iota 2 3) min.+ (iota 3 4)");

            Assert.AreEqual(expected.CompareInfos(result), InfoResult.OK);
            Assert.AreEqual(expected, result);
        }
示例#4
0
        public void LogXGreaterThanOrEqualTo0AndXLessThan1AndYEqualTo1()
        {
            AType expected = AFloat.Create(Double.NegativeInfinity);
            AType result   = this.engine.Execute <AType>("1 log .7");

            Assert.AreEqual(expected, result);
        }
示例#5
0
        public void LogXGreaterThan0AndYGreaterThan0()
        {
            AType expected = AFloat.Create(3);
            AType result   = this.engine.Execute <AType>("2 log 8");

            Assert.AreEqual(expected, result);
        }
示例#6
0
        public void SubtractInteger2IntegerResultFloat()
        {
            AType expected = AFloat.Create(Int32.MinValue - 1.0);
            AType result   = this.engine.Execute <AType>(String.Format("{0} - 1", Int32.MinValue));

            Assert.AreEqual(expected, result);
        }
示例#7
0
        public void LogYGreaterThan0AndYLessThan1AndXGreaterThan0()
        {
            AType expected = AFloat.Create(Math.Log(6, .7));
            AType result   = this.engine.Execute <AType>("0.7 log 6");

            Assert.AreEqual(expected, result);
        }
示例#8
0
        public void DecodeFloatList2IntegerArray()
        {
            AType expected = AArray.Create(
                ATypes.AFloat,
                AArray.Create(
                    ATypes.AFloat,
                    AArray.Create(ATypes.AFloat, AFloat.Create(64), AFloat.Create(76)),
                    AArray.Create(ATypes.AFloat, AFloat.Create(88), AFloat.Create(100)),
                    AArray.Create(ATypes.AFloat, AFloat.Create(112), AFloat.Create(124)),
                    AArray.Create(ATypes.AFloat, AFloat.Create(136), AFloat.Create(148))
                    ),
                AArray.Create(
                    ATypes.AFloat,
                    AArray.Create(ATypes.AFloat, AFloat.Create(160), AFloat.Create(172)),
                    AArray.Create(ATypes.AFloat, AFloat.Create(184), AFloat.Create(196)),
                    AArray.Create(ATypes.AFloat, AFloat.Create(208), AFloat.Create(220)),
                    AArray.Create(ATypes.AFloat, AFloat.Create(232), AFloat.Create(244))
                    )
                );

            AType result = this.engine.Execute <AType>("3 4.5 2 pack iota 3 2 4 2");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
示例#9
0
        public void DivisonOfNegativeNumberByZero()
        {
            AType expected = AFloat.Create(Double.NegativeInfinity);
            AType result   = this.engine.Execute <AType>("-6 % 0");

            Assert.AreEqual(expected, result);
        }
示例#10
0
        /// <summary>
        /// Tester method which returns different typed results.
        /// </summary>
        /// <param name="env"><see cref="Aplus"/> environemnt.</param>
        /// <param name="number">Input number.</param>
        /// <remarks>
        /// The resulting type of the value is determined by the input number's value.
        /// If the value is:
        /// <list type="bullet">
        ///  <item><description>0: returns 1.1 as a AFloat.</description></item>
        ///  <item><description>1: returns 0 as a AInteger.</description></item>
        ///  <item><description>2: returns `a as a ASymbol.</description></item>
        ///  <item><description>3: returns 'a' as a AFChar.</description></item>
        ///  <item><description>otherwise: returns empty array.</description></item>
        /// </list>
        /// </remarks>
        /// <returns>Different typed ATypes.</returns>
        public static AType MonadicTypeAlternate(Aplus env, AType number)
        {
            AType result;

            switch (number.asInteger)
            {
            case 0:
                result = AFloat.Create(1.1);
                break;

            case 1:
                result = AInteger.Create(0);
                break;

            case 2:
                result = ASymbol.Create("a");
                break;

            case 3:
                result = AChar.Create('a');
                break;

            default:
                result = Utils.ANull();
                break;
            }

            return(result);
        }
示例#11
0
        public void AbsoluteValueFloatUni()
        {
            AType expected = AFloat.Create(3.1);
            AType result   = this.engineUni.Execute <AType>("M.| -3.1");

            Assert.AreEqual(expected, result);
        }
示例#12
0
        public void DomainErrorMaxInt()
        {
            ScriptScope scope = this.engine.CreateScope();

            scope.SetVariable(".a", AFloat.Create(Int32.MaxValue));
            this.engine.Execute <AType>("while a { a:=a + 1.0 }", scope);
        }
示例#13
0
        public void MultiplyInteger2IntegerResultFloat()
        {
            AType expected = AFloat.Create(Int32.MaxValue * 2.0);
            AType result   = this.engine.Execute <AType>(String.Format("{0} * 2", Int32.MaxValue));

            Assert.AreEqual(expected, result);
        }
示例#14
0
        public void MultiplyInteger2Float()
        {
            AType expected = AFloat.Create(3.1);
            AType result   = this.engine.Execute <AType>("1 * 3.1");

            Assert.AreEqual(expected, result);
        }
示例#15
0
        public void SubtractInteger2Float()
        {
            AType expected = AFloat.Create(-2.1);
            AType result   = this.engine.Execute <AType>("1 - 3.1");

            Assert.AreEqual(expected, result);
        }
示例#16
0
        public void DivideFloat2FloatUni()
        {
            AType expected = AFloat.Create(3.4 / 1.2);
            AType result   = this.engineUni.Execute <AType>("3.4 % 1.2");

            Assert.AreEqual(expected, result);
        }
示例#17
0
        public void SubtractFloat2Integer()
        {
            AType expected = AFloat.Create(-1.4);
            AType result   = this.engine.Execute <AType>("2.6 - 4");

            Assert.AreEqual(expected, result);
        }
示例#18
0
        public void DivideInteger2Float()
        {
            AType expected = AFloat.Create(1 / 3.1);
            AType result   = this.engine.Execute <AType>("1 % 3.1");

            Assert.AreEqual(expected, result);
        }
示例#19
0
        private void ErrorCheck(AType argument)
        {
            if (argument.Type != ATypes.AInteger && argument.Type != ATypes.AFloat)
            {
                throw new Error.Type(TypeErrorText);
            }

            switch (argument.Rank)
            {
            case 0:
            case 1:
                AType sumValue = (argument.Rank == 0)
                        ? argument                                           // a simple scalar
                        : AFloat.Create(argument.Sum(item => item.asFloat)); // we have a vector

                if (sumValue.IsTolerablyWholeNumber && sumValue.asInteger == 0)
                {
                    throw new Error.Domain(DomainErrorText);
                }
                break;

            case 2:
                if (argument.Shape[1] > argument.Shape[0])
                {
                    throw new Error.Domain(DomainErrorText);
                }
                break;

            default:
                throw new Error.Rank(RankErrorText);
            }
        }
示例#20
0
        public void DivideFloat2Integer()
        {
            AType expected = AFloat.Create(2.6 / 4);
            AType result   = this.engine.Execute <AType>("2.6 % 4");

            Assert.AreEqual(expected, result);
        }
示例#21
0
        public void LogYGreaterThan0AndYLessThan1AndXEqualToPositiveInf()
        {
            AType expected = AFloat.Create(Double.NegativeInfinity);
            AType result   = this.engine.Execute <AType>("0.2 log Inf");

            Assert.AreEqual(expected, result);
        }
示例#22
0
        public void DivideIntegerWithZero()
        {
            AType expected = AFloat.Create(double.PositiveInfinity);
            AType result   = this.engine.Execute <AType>("1 % 0");

            Assert.AreEqual(expected, result);
        }
示例#23
0
        public void LogXEqualTo0AndYGreaterThan1()
        {
            AType expected = AFloat.Create(Double.NegativeInfinity);
            AType result   = this.engine.Execute <AType>("6 log 0");

            Assert.AreEqual(expected, result);
        }
示例#24
0
        public void ReplaceAllMappedFloatArray()
        {
            AType expected = AArray.Create(
                ATypes.AFloat,
                AArray.Create(
                    ATypes.AFloat,
                    AFloat.Create(6.4),
                    AFloat.Create(6.4)
                ),
                AArray.Create(
                    ATypes.AFloat,
                    AFloat.Create(6.4),
                    AFloat.Create(6.4)
                )
            );

            ScriptScope scope = this.engine.CreateScope();
            string executable = string.Format("a := 1 beam `{0}", MappedFiles.FloatMatrix.GetFileName());

            this.engine.Execute<AType>(executable, scope);
            this.engine.Execute<AType>("a[] := 6.4", scope);

            executable = string.Format("1 beam `{0}", MappedFiles.FloatMatrix.GetFileName());
            AType result = this.engine.Execute<AType>(executable, scope);

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
示例#25
0
        public void LogXEqualToPositiveInf0AndYGreaterThan0()
        {
            AType expected = AFloat.Create(Double.PositiveInfinity);
            AType result   = this.engine.Execute <AType>("8 log Inf");

            Assert.AreEqual(expected, result);
        }
示例#26
0
        public void InvokeUserDefinedFunctionWithMappedFloatArray()
        {
            AType expected = AArray.Create(
                ATypes.AFloat,
                AArray.Create(
                    ATypes.AFloat,
                    AFloat.Create(3.4),
                    AFloat.Create(1.4)
                ),
                AArray.Create(
                    ATypes.AFloat,
                    AFloat.Create(7.6),
                    AFloat.Create(34)
                )
            );

            ScriptScope scope = this.engine.CreateScope();
            string functionDefinition = string.Format("f{{}} : {{ 1 beam `{0}}}", MappedFiles.FloatMatrix.GetFileName());
            this.engine.Execute<AType>(functionDefinition, scope);

            this.engine.Execute<AType>("a := f{}", scope);
            this.engine.Execute<AType>("a[1;1] := 34", scope);

            string executable = string.Format("1 beam `{0}", MappedFiles.FloatMatrix.GetFileName());
            AType result = this.engine.Execute<AType>(executable, scope);

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
示例#27
0
        public void LogYEqualTo0AndXGreaterThan0Uni()
        {
            AType expected = AFloat.Create(0);
            AType result   = this.engineUni.Execute <AType>("0 M.& 3");

            Assert.AreEqual(expected, result);
        }
示例#28
0
        public void SubtractFloat2FloatUni()
        {
            AType expected = AFloat.Create(3.2 - 3.1);
            AType result   = this.engineUni.Execute <AType>("3.2 - 3.1");

            Assert.AreEqual(expected, result);
        }
示例#29
0
        private AType CalculateResidue(AType right, AType left)
        {
            double result;
            double x = right.asFloat;
            double y = left.asFloat;

            if (y == 0)
            {
                result = x;
            }
            else if (y == Double.PositiveInfinity || y == Double.NegativeInfinity)
            {
                result = 0;
            }
            else
            {
                double roundedx;
                if (Utils.TryComprasionTolarence(x, out roundedx))
                {
                    result = ModularArithmetic(roundedx, y);
                }
                else
                {
                    result = ModularArithmetic(x, y);;
                }
            }
            return(AFloat.Create(result));
        }
示例#30
0
        public void EachUseUserDefinedFunctionScalard2IntegerMatrix()
        {
            AType expected = AArray.Create(
                ATypes.ABox,
                Helpers.BuildStrand(
                    new AType[] {
                AFloat.Create(3),
                AFloat.Create(2.5),
                AFloat.Create(2)
            }
                    ),
                Helpers.BuildStrand(
                    new AType[] {
                AFloat.Create(4.5),
                AFloat.Create(4),
                AFloat.Create(3.5)
            }
                    )
                );

            ScriptScope scope = this.engine.CreateScope();

            this.engine.Execute <AType>("a{b;c} : (b+c)%2", scope);
            AType result = this.engine.Execute <AType>("4 a each iota 2 3", scope);

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }