示例#1
0
        public void Rank2Test()
        {
            AType expected = AArray.Create(ATypes.AFloat,
                                           AArray.Create(ATypes.AFloat, AFloat.Create(1), AFloat.Create(-1)),
                                           AArray.Create(ATypes.AFloat, AFloat.Create(-0.5), AFloat.Create(1))
                                           );
            AType result = this.engine.Execute <AType>("mdiv 2 2 rho 2 2 1 2");

            Assert.AreEqual(expected, result);
        }
示例#2
0
        public void ReplicateInteger2Null()
        {
            AType expected = AArray.Create(
                ATypes.ANull
                );
            AType result = this.engine.Execute <AType>("3 / ()");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#3
0
        public void NegateMatrix()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AArray.Create(ATypes.AInteger, AInteger.Create(0), AInteger.Create(-1)),
                                           AArray.Create(ATypes.AInteger, AInteger.Create(-2), AInteger.Create(-3))
                                           );
            AType result = this.engine.Execute <AType>(" - iota 2 2");

            Assert.AreEqual(expected, result);
        }
示例#4
0
        public void DropInteger2FloatList()
        {
            AType expected = AArray.Create(
                ATypes.AFloat
                );
            AType result = this.engine.Execute <AType>("6 drop 2.5 4 5");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#5
0
        public void IntervalFloatTolerablyInteger()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AInteger.Create(0), AInteger.Create(1), AInteger.Create(2), AInteger.Create(3)
                                           );
            AType result = this.engine.Execute <AType>("iota 4.0");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#6
0
        public void DropInteger2FunctionList()
        {
            AType expected = AArray.Create(
                ATypes.ANull
                );
            AType result = this.engine.Execute <AType>(" 3 drop (+;-)");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#7
0
        public void Serialize(AObject serializer)
        {
            serializer.Write(KEY_NAME, Name);
            AArray queries = serializer.WriteArray(KEY_QUERIES);

            for (int x = 0; x < Queries.Count; x++)
            {
                queries.Write(Queries[x]);
            }
        }
示例#8
0
        public void EqualToMatrix2Matrix()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(1)),
                                           AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(1))
                                           );
            AType result = this.engine.Execute <AType>("(iota 2 2) = iota 2 2");

            Assert.AreEqual(expected, result);
        }
示例#9
0
        public void EqualToInteger2Strand()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AInteger.Create(0), AInteger.Create(0)
                                           );

            AType result = this.engine.Execute <AType>("1 = (1;3)");

            Assert.AreEqual(expected, result);
        }
示例#10
0
        public void ExpandNull2Float()
        {
            AType expected = AArray.Create(
                ATypes.AFloat
                );
            AType result = this.engine.Execute <AType>("() \\ 3.4");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#11
0
        public void MultipleSimpleIndexing()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AInteger.Create(1), AInteger.Create(2)
                                           );

            AType result = this.engine.Execute <AType>("(0 1 2 3)[1 2]");

            Assert.AreEqual(expected, result, "Incorrect value assigned");
        }
示例#12
0
        public void DivideMatrix2Matrix()
        {
            AType expected = AArray.Create(ATypes.AFloat,
                                           AArray.Create(ATypes.AFloat, AFloat.Create(0), AFloat.Create(1 / 2.0)),
                                           AArray.Create(ATypes.AFloat, AFloat.Create(2 / 3.0), AFloat.Create(3 / 4.0))
                                           );
            AType result = this.engine.Execute <AType>("(iota 2 2) % 2 2 rho 1 2 3 4");

            Assert.AreEqual(expected, result);
        }
示例#13
0
        public void TakeZeroCount()
        {
            AType expected = AArray.Create(
                ATypes.AInteger
                );
            AType result = this.engine.Execute <AType>("0 take 1 2 3");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#14
0
        public void ReadAndLocalWriteIntegerArray()
        {
            AType expected = AArray.Create(
                ATypes.AInteger,
                AArray.Create(
                    ATypes.AInteger,
                    AInteger.Create(5),
                    AInteger.Create(6),
                    AInteger.Create(7)
                    ),
                AArray.Create(
                    ATypes.AInteger,
                    AInteger.Create(8),
                    AInteger.Create(2),
                    AInteger.Create(7)
                    )
                );

            ScriptScope scope = this.engine.CreateScope();
            string      value = string.Format("1 beam `{0}", MappedFiles.IntegerMatrix.GetFileName());

            this.engine.Execute <AType>(string.Format("a := {0}", value), scope);
            this.engine.Execute <AType>(string.Format("b := {0}", value), scope);

            this.engine.Execute <AType>("(1 drop a) := 1 3 rho 8 2 7", scope);

            Assert.AreEqual(InfoResult.OK, scope.GetVariable <AType>(".a").CompareInfos(expected));
            Assert.AreEqual(expected, scope.GetVariable <AType>(".a"));
            Assert.AreEqual(InfoResult.OK, scope.GetVariable <AType>(".b").CompareInfos(expected));
            Assert.AreEqual(expected, scope.GetVariable <AType>(".b"));

            this.engine.Execute <AType>("((1;0) # b) := 45", scope);

            expected = AArray.Create(
                ATypes.AInteger,
                AArray.Create(
                    ATypes.AInteger,
                    AInteger.Create(5),
                    AInteger.Create(6),
                    AInteger.Create(7)
                    ),
                AArray.Create(
                    ATypes.AInteger,
                    AInteger.Create(45),
                    AInteger.Create(2),
                    AInteger.Create(7)
                    )
                );

            Assert.AreEqual(InfoResult.OK, scope.GetVariable <AType>(".a").CompareInfos(expected));
            Assert.AreEqual(expected, scope.GetVariable <AType>(".a"));

            Assert.AreEqual(InfoResult.OK, scope.GetVariable <AType>(".b").CompareInfos(expected));
            Assert.AreEqual(expected, scope.GetVariable <AType>(".b"));
        }
示例#15
0
        public void TakeInteger2Integer()
        {
            AType expected = AArray.Create(
                ATypes.AInteger,
                AInteger.Create(5)
                );
            AType result = this.engine.Execute <AType>("1 take 5");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#16
0
        public void CorrectCase1()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(1)),
                                           AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(1))
                                           );

            AType result = this.engine.Execute <AType>("_index{2 2 rho 1; 1 1; 1}");

            Assert.AreEqual(expected, result);
        }
示例#17
0
        public void RazeStrandFirstFloatNull()
        {
            AType expected = AArray.Create(ATypes.AFloat,
                                           AFloat.Create(3.3), AFloat.Create(4)
                                           );

            AType result = this.engine.Execute <AType>("pick (0 rho 3.5;3.3;4;)");

            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
            Assert.AreEqual(expected, result);
        }
示例#18
0
        public void ExpandOne2CharacterConstant()
        {
            AType expected = AArray.Create(
                ATypes.AChar,
                AChar.Create('a')
                );
            AType result = this.engine.Execute <AType>("1 \\ 'a'");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#19
0
        public void DivideVector2Vector()
        {
            AType expected = AArray.Create(ATypes.AFloat,
                                           AFloat.Create(0 / 10.0),
                                           AFloat.Create(12 / -7.0),
                                           AFloat.Create(-4 / 4.0)
                                           );
            AType result = this.engine.Execute <AType>("0 12 -4 % 10.0 -7 4.0");

            Assert.AreEqual(expected, result);
        }
示例#20
0
        public void BitwiseNotEqualVector()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AInteger.Create(9), AInteger.Create(96), AInteger.Create(1005)
                                           );

            AType result = this.engine.Execute <AType>("10 100 1000 bwne 3 4 5");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#21
0
        /// <summary>
        /// Execute 'dyadic' Each algorithm.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="environment"></param>
        /// <param name="isNull"></param>
        /// <param name="function"></param>
        /// <returns></returns>
        private AType Walker(AType left, AType right, Aplus environment, bool isNull, AFunc function)
        {
            if (left.IsArray)
            {
                AType result = AArray.Create(ATypes.AArray);

                AType rightArray = right.IsArray ? right : AArray.Create(right.Type, right);

                for (int i = 0; i < left.Length; i++)
                {
                    result.AddWithNoUpdate(Walker(left[i], rightArray[right.IsArray ? i : 0], environment, isNull, function));
                }

                result.Type   = isNull ? ATypes.ANull : ATypes.ABox;
                result.Length = left.Length;
                result.Shape  = new List <int>(left.Shape);
                result.Rank   = left.Rank;

                return(result);
            }
            else
            {
                if (right.IsArray)
                {
                    AType result = AArray.Create(ATypes.AArray);

                    for (int i = 0; i < right.Length; i++)
                    {
                        result.AddWithNoUpdate(Walker(left, right[i], environment, isNull, function));
                    }

                    result.Type   = isNull ? ATypes.ANull : ATypes.ABox;
                    result.Length = right.Length;
                    result.Shape  = new List <int>(right.Shape);
                    result.Rank   = right.Rank;

                    return(result);
                }
                else
                {
                    //Disclose left and right scalar argument.
                    AType disclosedRight = MonadicFunctionInstance.Disclose.Execute(right, environment);
                    AType disclosedLeft  = MonadicFunctionInstance.Disclose.Execute(left, environment);

                    var method = (Func <Aplus, AType, AType, AType>)function.Method;

                    //Execute the holden function and enclose the result.
                    AType result = method(environment, disclosedRight, disclosedLeft);
                    result = MonadicFunctionInstance.Enclose.Execute(result);

                    return(result);
                }
            }
        }
示例#22
0
        internal static AType PermissiveIndexing(Aplus environment, AType defaultItem, AType array, AType index)
        {
            PermissiveIndexingErrorCheck(index, array, defaultItem);

            if (index.Type == ATypes.ANull)
            {
                return(AArray.Create(ATypes.ANull));
            }

            return(PermissiveIndexingSubIndex(index, array, defaultItem, environment));
        }
示例#23
0
        public void DivideVector2Integer()
        {
            AType expected = AArray.Create(ATypes.AFloat,
                                           AFloat.Create(0),
                                           AFloat.Create(2 / 3.0),
                                           AFloat.Create(4 / 3.0)
                                           );
            AType result = this.engine.Execute <AType>("0 2 4 % 3");

            Assert.AreEqual(expected, result);
        }
示例#24
0
        public void DivideInteger2Vector()
        {
            AType expected = AArray.Create(ATypes.AFloat,
                                           AFloat.Create(double.PositiveInfinity),
                                           AFloat.Create(1),
                                           AFloat.Create(2 / 4.0)
                                           );
            AType result = this.engine.Execute <AType>("2 % 0 2 4");

            Assert.AreEqual(expected, result);
        }
示例#25
0
        protected override void Serialize(AObject serializer)
        {
            base.Serialize(serializer);

            AArray entries = serializer.WriteArray(KEY_HISTORY);

            for (int x = 0; x < m_ExecutionHistory.Count; x++)
            {
                entries.Write(m_ExecutionHistory[x]);
            }
        }
示例#26
0
        public void SymbolArgument()
        {
            AType expected = AArray.Create(ATypes.ABox,
                                           ABox.Create(ASymbol.Create("symbol")),
                                           ABox.Create(ABox.Create(Utils.ANull()))
                                           );

            AType result = this.engine.Execute <AType>("_alsf{`symbol}");

            Assert.AreEqual(expected, result);
        }
示例#27
0
        public void ExpandNull2SymbolConstant()
        {
            AType expected = AArray.Create(
                ATypes.ASymbol,
                ASymbol.Create("")
                );
            AType result = this.engine.Execute <AType>("0 \\ `test");

            Assert.AreEqual(expected, result);
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#28
0
        public void AppendTypeError()
        {
            ScriptScope scope = this.engine.CreateScope();

            scope.SetVariable(
                ".a",
                AArray.Create(ATypes.AInteger, AInteger.Create(1), AInteger.Create(2))
                );

            this.engine.Execute <AType>("a[,] := 'd'", scope);
        }
示例#29
0
        public void IntegerVectorMember()
        {
            AType expected = AArray.Create(ATypes.AInteger,
                                           AInteger.Create(1), AInteger.Create(0)
                                           );

            AType result = this.engine.Execute <AType>("1 0 in 1");

            Assert.AreEqual <AType>(expected, result, "Invalid value produced");
            Assert.AreEqual(InfoResult.OK, result.CompareInfos(expected));
        }
示例#30
0
        public void BoxArgument()
        {
            AType expected = AArray.Create(ATypes.ABox,
                                           ABox.Create(AArray.Create(ATypes.ANull)),
                                           ABox.Create(AArray.Create(ATypes.ANull))
                                           );

            AType result = this.engine.Execute <AType>("_alsf{<()}");

            Assert.AreEqual(expected, result);
        }