예제 #1
0
        public void GetAttributeAccessTest()
        {
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name   = "TestField";
            fieldElement.Access = CodeAccess.Protected;

            string attribute = ElementUtilities.GetAttribute(ElementAttributeType.Access, fieldElement);

            Assert.AreEqual("Protected", attribute, "Unexpected attribute.");
        }
예제 #2
0
        public void equality_check()
        {
            var a    = FieldElement.from_bytes(A_BYTES);
            var ainv = FieldElement.from_bytes(AINV_BYTES);

            // ReSharper disable once EqualExpressionComparison
            #pragma warning disable CS1718 // Comparison made to same variable
            Assert.True(a == a);
            #pragma warning restore CS1718 // Comparison made to same variable
            Assert.True(a != ainv);
        }
예제 #3
0
        public void TestAdd()
        {
            var a = new FieldElement(new BigInteger(2), new BigInteger(31));
            var b = new FieldElement(new BigInteger(15), new BigInteger(31));

            Assert.AreEqual(new FieldElement(new BigInteger(17), new BigInteger(31)), a + b);

            a = new FieldElement(new BigInteger(17), new BigInteger(31));
            b = new FieldElement(new BigInteger(21), new BigInteger(31));
            Assert.AreEqual(new FieldElement(new BigInteger(7), new BigInteger(31)), a + b);
        }
예제 #4
0
        public void TestSubtract()
        {
            var a = new FieldElement(new BigInteger(29), new BigInteger(31));
            var b = new FieldElement(new BigInteger(4), new BigInteger(31));

            Assert.AreEqual(new FieldElement(new BigInteger(25), new BigInteger(31)), a - b);

            a = new FieldElement(new BigInteger(15), new BigInteger(31));
            b = new FieldElement(new BigInteger(30), new BigInteger(31));
            Assert.AreEqual(new FieldElement(new BigInteger(16), new BigInteger(31)), a - b);
        }
예제 #5
0
 public TemplateManager CreateTemplate(FieldElement field)
 {
     return(new TemplateManager()
     {
         SelectedCollection = Model.Reader.Model.Databases,
         SelectedDatabase = field.Parent.Parent,
         SelectedTable = field.Parent,
         SelectedField = field,
         SelectedTemplate = (TableTemplate)cbTemplateGroups.SelectedItem,
     });
 }
예제 #6
0
        public void TestPow()
        {
            var a = new FieldElement(new BigInteger(17), new BigInteger(31));

            Assert.AreEqual(new FieldElement(new BigInteger(15), new BigInteger(31)), a.Pow(3));

            a = new FieldElement(new BigInteger(5), new BigInteger(31));
            var b = new FieldElement(new BigInteger(18), new BigInteger(31));

            Assert.AreEqual(new FieldElement(new BigInteger(16), new BigInteger(31)), a.Pow(5) * b);
        }
예제 #7
0
 public FieldElement Divide(FieldElement val1, FieldElement val2)
 {
     if (!(val1 is Complex) || (!(val2 is Complex)))
     {
         throw new ArgumentException("The inputs must be Complex numbers");
     }
     if (((Complex)val2).IsZero())
     {
         throw new ArgumentException("Divide by Zero");
     }
     return(((Complex)val1).Divide((Complex)val2));
 }
예제 #8
0
 public FieldElement Inverse(FieldElement val)
 {
     if (!(val is Complex))
     {
         throw new ArgumentException("The input must be a Complex number");
     }
     if (((Complex)val).IsZero())
     {
         throw new ArgumentException("Zero cannot be inversed");
     }
     return(((Complex)val).Inverse());
 }
예제 #9
0
        public void InsertByElementTypeTest()
        {
            SortBy sortBy = new SortBy();

            sortBy.By        = ElementAttributeType.ElementType;
            sortBy.Direction = SortDirection.Ascending;

            SortedInserter sortedInserter = new SortedInserter(ElementType.NotSpecified, sortBy);

            //
            // Create a parent element
            //
            RegionElement regionElement = new RegionElement();

            Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children.");

            //
            // Insert an element with a middle access.
            //
            ConstructorElement constructor = new ConstructorElement();

            constructor.Name   = "SomeClass";
            constructor.Access = CodeAccess.Public;
            sortedInserter.InsertElement(regionElement, constructor);
            Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(constructor), "Element was not inserted at the correct index.");

            //
            // Insert an element that should be sorted toward the end
            //
            MethodElement methodElement = new MethodElement();

            methodElement.Name   = "SomeMethod";
            methodElement.Access = CodeAccess.Public;
            sortedInserter.InsertElement(regionElement, methodElement);
            Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(constructor), "Element is not at the correct index.");
            Assert.AreEqual(1, regionElement.Children.IndexOf(methodElement), "Element is not at the correct index.");

            //
            // Insert an element that should be sorted toward the beginning
            //
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name   = "someField";
            fieldElement.Access = CodeAccess.Private;
            sortedInserter.InsertElement(regionElement, fieldElement);
            Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(fieldElement), "Element is not at the correct index.");
            Assert.AreEqual(1, regionElement.Children.IndexOf(constructor), "Element is not at the correct index.");
            Assert.AreEqual(2, regionElement.Children.IndexOf(methodElement), "Element is not at the correct index.");
        }
        protected virtual void HandleBackOfficeNode(string nodeName, string nodeValue, FieldElementSection rawDataFields, SqlCommand insertCommand)
        {
            try
            {
                if (nodeName == String.Empty ||
                    nodeName == null)
                {
                    throw new ArgumentException("Invalid node name. Cannot be null or empty.");
                }

                FieldElement fe = rawDataFields.Fields[nodeName];
                //if (fe != null)
                //    insertCommand.Parameters["@" + fe.DBFieldName].Value =
                //        Convert.ChangeType(nodeValue, Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));


                if (fe == null || !fe.InsertToDB || !fe.Enabled)
                {
                    return;
                }

                if (!String.IsNullOrEmpty(nodeValue))
                {
                    insertCommand.Parameters["@" + fe.DBFieldName].Value =
                        Convert.ChangeType(nodeValue, Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));

                    // Initalize Gateway_GK
                    if (rawDataFields.Fields[nodeName].DBFieldName.ToLower() == "gateway_id")
                    {
                        insertCommand.Parameters["@Gateway_GK"].Value =
                            GkManager.GetGatewayGK(_accountID, Convert.ToInt64(nodeValue));
                    }
                }
                else
                {
                    // Initalize field with null value.
                    if (fe.DBDefaultValue == null)
                    {
                        insertCommand.Parameters["@" + fe.DBFieldName].Value = DBNull.Value;
                    }
                    else
                    {
                        insertCommand.Parameters["@" + fe.DBFieldName].Value =
                            Convert.ChangeType(fe.DBDefaultValue, Type.GetType(_tableTypeMappings[fe.DBFieldType.ToLower()]));
                    }
                }
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
        }
        public void ShouldSetCoefficients(int coefficientValueRepresentation)
        {
            // Given
            var polynomial       = new BiVariablePolynomial(Gf5);
            var monomial         = new Tuple <int, int>(1, 1);
            var coefficientValue = new FieldElement(Gf5, coefficientValueRepresentation);

            // When
            polynomial[monomial] = coefficientValue;

            // Then
            Assert.Equal(coefficientValue, polynomial[monomial]);
        }
예제 #12
0
        public void TypeTest()
        {
            FieldElement target = new FieldElement();

            string val = null; // TODO: Assign to an appropriate value for the property

            target.Type = val;


            Assert.AreEqual(val, target.Type, "Composestar.StarLight.Entities.LanguageModel.FieldElement.Type was not set correc" +
                            "tly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
예제 #13
0
        public void conditional_negate()
        {
            var one      = FieldElement.one();
            var minusOne = FieldElement.minus_one();
            var x        = one;

            x.conditional_negate(true);
            Assert.Equal(x, minusOne);
            x.conditional_negate(false);
            Assert.Equal(x, minusOne);
            x.conditional_negate(true);
            Assert.Equal(x, one);
        }
예제 #14
0
        /// <summary>
        /// Method for calculating bivariate polynomial value for variable x value <paramref name="xValue"/> and variable y value <paramref name="yValue"/>
        /// </summary>
        /// <param name="xValue">x variable value</param>
        /// <param name="yValue">y variable value</param>
        /// <returns>Bivariate polynomial value</returns>
        public FieldElement Evaluate(FieldElement xValue, FieldElement yValue)
        {
            var result = Field.Zero();

            foreach (var coefficient in _coefficients)
            {
                result += coefficient.Value
                          * FieldElement.Pow(xValue, coefficient.Key.Item1)
                          * FieldElement.Pow(yValue, coefficient.Key.Item2);
            }

            return(result);
        }
 /// <summary>
 /// h = f - g
 /// Can overlap h with f or g.
 ///
 /// Preconditions:
 /// |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
 /// |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
 ///
 /// Postconditions:
 /// |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
 /// </summary>
 /// <param name="h"></param>
 /// <param name="f"></param>
 /// <param name="g"></param>
 internal static FieldElement Sub(ref FieldElement f, ref FieldElement g) => new FieldElement
 {
     X0 = f.X0 - g.X0,
     X1 = f.X1 - g.X1,
     X2 = f.X2 - g.X2,
     X3 = f.X3 - g.X3,
     X4 = f.X4 - g.X4,
     X5 = f.X5 - g.X5,
     X6 = f.X6 - g.X6,
     X7 = f.X7 - g.X7,
     X8 = f.X8 - g.X8,
     X9 = f.X9 - g.X9
 };
예제 #16
0
파일: GameBoard.cs 프로젝트: Szaya/HIVE
        private bool checkQueen(FieldElement element)
        {
            List <FieldElement> neighbours = getNeighbours(element);

            for (int j = 0; j < neighbours.Count; j++)
            {
                if (neighbours[j].Type == ElementType.VOID)
                {
                    return(false);
                }
            }
            return(true);
        }
 /// <summary>
 /// h = f + g
 /// Can overlap h with f or g.
 ///
 /// Preconditions:
 /// |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
 /// |g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
 ///
 /// Postconditions:
 /// |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="g"></param>
 internal static FieldElement Add(ref FieldElement f, ref FieldElement g) => new FieldElement
 {
     X0 = f.X0 + g.X0,
     X1 = f.X1 + g.X1,
     X2 = f.X2 + g.X2,
     X3 = f.X3 + g.X3,
     X4 = f.X4 + g.X4,
     X5 = f.X5 + g.X5,
     X6 = f.X6 + g.X6,
     X7 = f.X7 + g.X7,
     X8 = f.X8 + g.X8,
     X9 = f.X9 + g.X9
 };
        public void EvaluateInvalidOperatorTest()
        {
            IConditionExpression expression = new BinaryOperatorExpression(
                (BinaryExpressionOperator)int.MinValue,
                new ElementAttributeExpression(ElementAttributeType.Name),
                new StringExpression("Test"));

            FieldElement element = new FieldElement();

            element.Name = "Test";

            Assert.Throws(typeof(ArgumentOutOfRangeException), () => { bool result = ConditionExpressionEvaluator.Instance.Evaluate(expression, element); });
        }
예제 #19
0
        protected override void OnExecute(object parameter)
        {
            var field = parameter as FieldElement;

            if (field == null)
            {
                ModernDialog.ShowMessage("no field detected.", "error", MessageBoxButton.OK);
                return;
            }
            var parent = field.Parent;

            View.Model.ClipboardItem = FieldElement.Clone(field);
        }
예제 #20
0
        public void IsPublicTest()
        {
            FieldElement target = new FieldElement();

            bool val = false; // TODO: Assign to an appropriate value for the property

            target.IsPublic = val;


            Assert.AreEqual(val, target.IsPublic, "Composestar.StarLight.Entities.LanguageModel.FieldElement.IsPublic was not set co" +
                            "rrectly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
예제 #21
0
 /// <summary>
 /// Clear the cells of the grid from a specific element
 /// </summary>
 /// <param name="element">The element to be cleared</param>
 public void ClearCells(FieldElement element)
 {
     for (int r = 0; r < mGrid.GetLength(0); r++)
     {
         for (int c = 0; c < mGrid.GetLength(1); c++)
         {
             if (mGrid[r, c] == element)
             {
                 mGrid[r, c] = FieldElement.Empty;
             }
         }
     }
 }
예제 #22
0
 public Field(int sizeByY, int sizeByX, int startY, int startx,
              int finishY, int finishX)
 {
     SizeByY                       = sizeByY;
     SizeByX                       = sizeByX;
     GamingField                   = new FieldElement[sizeByY, sizeByX];
     CurrentUserPosition           = new UserPosition();
     EndLevel                      = new UserPosition();
     CurrentUserPosition.PositionY = startY;
     CurrentUserPosition.PositionX = startx;
     EndLevel.PositionY            = finishY;
     EndLevel.PositionX            = finishX;
 }
 /// <summary>
 /// h = -f
 ///
 /// Preconditions:
 /// |f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
 ///
 /// Postconditions:
 /// |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
 /// </summary>
 /// <param name="h"></param>
 /// <param name="f"></param>
 internal static FieldElement Negate(ref FieldElement f) => new FieldElement
 {
     X0 = -f.X0,
     X1 = -f.X1,
     X2 = -f.X2,
     X3 = -f.X3,
     X4 = -f.X4,
     X5 = -f.X5,
     X6 = -f.X6,
     X7 = -f.X7,
     X8 = -f.X8,
     X9 = -f.X9
 };
예제 #24
0
        public void a_invert_vs_inverse_of_a_constant()
        {
            var a = FieldElement.from_bytes(A_BYTES);

            var ainv = FieldElement.from_bytes(AINV_BYTES);

            var shouldBeInverse = a.invert();

            var feo = FieldElement.one();

            Assert.Equal(ainv, shouldBeInverse);

            Assert.Equal(feo, a * shouldBeInverse);
        }
예제 #25
0
파일: GameBoard.cs 프로젝트: Szaya/HIVE
        private void markHoppStepableFields(FieldElement target, Func <FieldElement, FieldElement> nextElement)
        {
            FieldElement elementToCheck = target;

            do
            {
                elementToCheck = nextElement(elementToCheck);
            } while (elementToCheck.Type != ElementType.VOID);

            if (!elementToCheck.Equals(nextElement(target)))
            {
                markElement(elementToCheck, Marktypes.ACCESSIBLE);
            }
        }
 /// <summary>
 /// Replace (f,g) with (g,g) if b == 1;
 /// Replace (f,g) with (f,g) if b == 0.
 ///
 /// Preconditions: b in {0,1}.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="g"></param>
 /// <param name="b"></param>
 internal static void Mov(ref FieldElement f, ref FieldElement g, int b)
 {
     b    = -b;
     f.X0 = f.X0 ^ ((f.X0 ^ g.X0) & b);
     f.X1 = f.X1 ^ ((f.X1 ^ g.X1) & b);
     f.X2 = f.X2 ^ ((f.X2 ^ g.X2) & b);
     f.X3 = f.X3 ^ ((f.X3 ^ g.X3) & b);
     f.X4 = f.X4 ^ ((f.X4 ^ g.X4) & b);
     f.X5 = f.X5 ^ ((f.X5 ^ g.X5) & b);
     f.X6 = f.X6 ^ ((f.X6 ^ g.X6) & b);
     f.X7 = f.X7 ^ ((f.X7 ^ g.X7) & b);
     f.X8 = f.X8 ^ ((f.X8 ^ g.X8) & b);
     f.X9 = f.X9 ^ ((f.X9 ^ g.X9) & b);
 }
예제 #27
0
파일: Fp.cs 프로젝트: tagoro9/nfc
        public FieldElement Multiply(FieldElement val, int val2)
        {
            if (!(val is BigInt))
            {
                throw new ArgumentException("The first input must be a BigInt");
            }
            if (val2 < 0)
            {
                throw new ArgumentException("oprand must not be negative");
            }
            BigInt result = ((BigInt)val).Multiply(BigInt.ValueOf(val2));

            return((result).Mod(r));
        }
        public void EvaluateInvalidOperatorTest()
        {
            IConditionExpression expression = new BinaryOperatorExpression(
                (BinaryExpressionOperator)int.MinValue,
                new ElementAttributeExpression(ElementAttributeType.Name),
                new StringExpression("Test"));

            FieldElement element = new FieldElement();

            element.Name = "Test";

            bool result = ConditionExpressionEvaluator.Instance.Evaluate(
                expression, element);
        }
예제 #29
0
        public override List <Field> GetFieldsForLucene()
        {
            FieldElement fieldElement = (FieldElement)programElement;
            List <Field> fields       = new List <Field>();

            fields.Add(new Field(SandoField.AccessLevel.ToString(), fieldElement.AccessLevel.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            fields.Add(new Field(SandoField.DataType.ToString(), fieldElement.FieldType.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED));
            AddBodyField(fields, new Field(SandoField.Body.ToString(), fieldElement.RawSource.ToSandoSearchable(), Field.Store.NO, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.ClassId.ToString(), fieldElement.ClassId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            fields.Add(new Field(SandoField.ClassName.ToString(), fieldElement.ClassName.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.Modifiers.ToString(), fieldElement.Modifiers, Field.Store.YES, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.InitialValue.ToString(), fieldElement.InitialValue.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED));
            return(fields);
        }
예제 #30
0
        public void chi_on_square_and_nonsquare()
        {
            var a = FieldElement.from_bytes(A_BYTES);

            // a is square
            Assert.Equal(a.chi(), FieldElement.one());
            var twoBytes = new byte[32];

            twoBytes[0] = 2;
            var two = FieldElement.from_bytes(twoBytes);

            // 2 is non-square
            Assert.Equal(two.chi(), FieldElement.minus_one());
        }
예제 #31
0
        /// <summary>
        /// Creates a clone of this instance.
        /// </summary>
        /// <returns>Clone of the element with the member element state copied.</returns>
        protected override MemberElement DoMemberClone()
        {
            FieldElement fieldElement = new FieldElement();

            //
            // Copy state
            //
            fieldElement._initialValue = _initialValue;
            fieldElement._isVolatile = _isVolatile;
            if (_trailingComment != null)
            {
                fieldElement._trailingComment = _trailingComment.Clone() as ICommentElement;
            }

            return fieldElement;
        }