Ejemplo n.º 1
0
        public JsonResult Index(int value)
        {
            var random = new Random();
            var randomNumbers = new RandomNumbers();
            if (value != 0)
            {
                for (int i = 0; i < value; i++)
                {
                    randomNumbers.Numbers.Add(random.Next(1, 100));
                    //randomNumbers.Numbers.Add(" ");
                    //Thread.Sleep(1000);
                }
            }
            var numbers = new Numbers(randomNumbers);
            var jsonResult = new JsonResult() {
                Data = numbers,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
            };

            return Json(jsonResult.Data);
            //Numbers numbers = new Numbers();
            //Random random = new Random();
            //if (value != 0)
            //{
            //    for (int i = 0; i < value; i++)
            //    {
            //        numbers.randomNumbers.Numbers.Add(random.Next(1,100));
            //        Thread.Sleep(1000);
            //    }
            //}
            //return View(numbers);
            //return Json(numbers, JsonRequestBehavior.AllowGet);
        }
 private static void Sample5()
 {
     const string src = "This is the first number #{Num[0]}";
     var nums = new Numbers { Num = new string[] { "1", "2", "3" } };
     var interpolated = nums.InterpolateThis(src);
     Print(src, interpolated);
 }
 public generateSequences(Numbers numbers)
 {
     string[] nums = numbers.getArray();
     string[] signs = {"+","-","*","/" };
     for (int a = 0; a < 6; a++)
     {
         for (int i = 0; i < 4; i++)
         {
             for (int b = 0; b < 6; b++)
             {
                 if (b != a)
                 {
                     sequences.Add(nums[a]+signs[i]+nums[b]);
                     for (int ii = 0; ii < 4; ii++)
                     {
                         for (int c = 0; c < 6; c++)
                         {
                             if (c != b && c !=a)
                             {
                                 sequences.Add(nums[a] + signs[i] + nums[b]+signs[ii]+nums[c]);
                                 for (int iii = 0; iii < 4; iii++)
                                 {
                                     for (int d = 0; d < 6; d++)
                                     {
                                         if (d != c && d != b && d != a)
                                         {
                                             sequences.Add(nums[a] + signs[i] + nums[b] + signs[ii] + nums[c]+ signs[iii]+nums[d]);
                                             for (int iiii = 0; iiii < 4; iiii++)
                                             {
                                                 for (int e = 0; e < 6; e++)
                                                 {
                                                     if (e != d && e != c && e != b && e != a)
                                                     {
                                                         sequences.Add(nums[a] + signs[i] + nums[b] + signs[ii] + nums[c] + signs[iii] + nums[d]+signs[iiii]+nums[e]);
                                                         for (int iiiii = 0; iiiii < 4; iiiii++)
                                                         {
                                                             for (int f = 0; f < 6; f++)
                                                             {
                                                                 if (f != e && f != d && f != c && f != b && f != a)
                                                                 {
                                                                     //this will have the number
                                                                     string temp = nums[a] + signs[i] + nums[b] + signs[ii] + nums[c] + signs[iii] + nums[d] + signs[iiii] + nums[e] + signs[iiiii] + nums[f];
                                                                     sequences.Add(temp);
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 private static void Sample8()
 {
     const string src = "NumA + NumB = #{NumA+NumB}";
     var nums = new Numbers { Num = new[] { "1", "2" }, NumA = 1, NumB = 2 };
     var interpolatables = nums.InterpolateThis(src);
     Print(src, interpolatables);
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // Here I define all of the objects in the chain

            IChain chainCalc1 = new AddNumbers();
            IChain chainCalc2 = new SubtractNumbers();
            IChain chainCalc3 = new MultiNumbers();
            IChain chainCalc4 = new DivideNumbers();

            // Here I tell each object where to forward the
            // data if it can't process the request

            chainCalc1.setNextChain(chainCalc2);
            chainCalc2.setNextChain(chainCalc3);
            chainCalc3.setNextChain(chainCalc4);

            // Define the data in the Numbers Object
            // and send it to the first Object in the chain
            Console.WriteLine("What do you want to do (add, sub, mult, div): ");
            string typeOfCalc = Console.ReadLine();
            Console.WriteLine("Type in the first number: ");
            int firstNumber = int.Parse(Console.ReadLine());
            Console.WriteLine("Type in the second number: ");
            int secondNumber = int.Parse(Console.ReadLine());
            Numbers request = new Numbers(firstNumber, secondNumber, typeOfCalc);

            chainCalc1.calculate(request);
            Console.ReadLine();
        }
Ejemplo n.º 6
0
 private RandomGenR()
 {
     this.dateModule = new Dates();
     this.numberModule = new Numbers();
     this.collectionsModule = new Collections();
     this.stringsModule = new Strings();
 }
 public void PartialClassesTest()
 {
     Numbers n = new Numbers();
     Assert.AreEqual(1, n.ReturnOne());
     Assert.AreEqual(2, n.ReturnTwo());
     Assert.AreEqual(3, Numbers.Nested.ReturnThree());
     Assert.AreEqual(4, Numbers.Nested.ReturnFour());
 }
        public void InitSwitchBlockExecuteTest()
        {
            this.m_mathOperationEnamParam = new MathOperationEnamParam();
              this.m_mathOperationController = new ValidationController<Numbers>();
              this.m_mathOperationController.RegisterValidator(typeof(AddBlock), () => this.m_mathOperationEnamParam);
              this.m_mathOperationController.RegisterValidator(typeof(SubtractBlock), () => this.m_mathOperationEnamParam);
              this.m_mathOperationController.RegisterValidator(typeof(MultiplyBlock), () => this.m_mathOperationEnamParam);
              this.m_mathOperationController.RegisterValidator(typeof(DivisionBlock), () => this.m_mathOperationEnamParam);

              this.m_numbers = new Numbers { Number1 = 9, Number2 = 7 };
        }
Ejemplo n.º 9
0
 // Tries to calculate the data, or passes it
 // to the Object defined in method setNextChain()
 public void calculate(Numbers request)
 {
     if (request.getCalcWanted()=="add")
     {
         Console.WriteLine(request.getNumber1() + " + " + request.getNumber2() + " = "+(request.getNumber1()+request.getNumber2()));
     }
     else
     {
         nextInChain.calculate(request);
     }
 }
        public void InitSwitchBlockExecuteTest()
        {
            this.m_mathOperationEnamParam = new MathOperationEnamParam();
              this.m_mathOperationSwitchValidators = new ValidatorList<Numbers>
                                               {
                                                 { typeof(AddBlock), () => this.m_mathOperationEnamParam },
                                                 { typeof(SubtractBlock), () => this.m_mathOperationEnamParam },
                                                 { typeof(MultiplyBlock), () => this.m_mathOperationEnamParam }
                                               };

              this.m_numbers = new Numbers { Number1 = 9, Number2 = 7 };
        }
 public void CanCreateASubListOfInterpolatablesWithAnExpression()
 {
     const string src = "Sum of #{NumA + NumB} is stored in C";
     var nums = new Numbers { Num = new[] { "1", "2" }, NumA = 1, NumB = 2 };
     var interpolatables = nums.InterpolatablesOf(src);
     Assert.IsNotNull(interpolatables);
     Assert.AreEqual(1, interpolatables.Count);
     var interpolatable = interpolatables.First();
     var subList = interpolatable.InterpolatablesOfExpr(nums, src);
     Assert.IsNotNull(subList);
     Assert.AreEqual(2, subList.Count);
 }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please, set a limit for the sum");
            int limit = Convert.ToInt32(Console.ReadLine());

            SumOfNumbersDelegate callback = new SumOfNumbersDelegate(PrintSumOfNumbers);

            Numbers numbers = new Numbers(limit, callback);
            Thread t1 = new Thread(new ThreadStart(numbers.SumNumbers));
            t1.Start();

            Console.ReadKey();
        }
 public void CanCreateAListOfInterpolatablesWithAnArray()
 {
     const string src = "This is the first number #{Num[0]}";
     var nums = new Numbers { Num = new string[] { "1", "2", "3" } };
     var interpolatables = nums.InterpolatablesOf(src);
     Assert.IsNotNull(interpolatables);
     Assert.AreEqual(1, interpolatables.Count);
     var interpolatable = interpolatables.First();
     Assert.AreEqual("Num[0]", interpolatable.Item);
     Assert.AreEqual(nums, interpolatable.Instance);
     Assert.AreEqual(InterpolatableType.Array, interpolatable.Type);
     Assert.AreEqual("1", interpolatable.Value);
 }
 public void CanCreateAListOfInterpolatablesWithAnExpression()
 {
     const string src = "Sum of #{NumA + NumB} is stored in C";
     var nums = new Numbers { Num = new[] { "1", "2" }, NumA = 1, NumB = 2 };
     var interpolatables = nums.InterpolatablesOf(src);
     Assert.IsNotNull(interpolatables);
     Assert.AreEqual(1, interpolatables.Count);
     var interpolatable = interpolatables.First();
     Assert.AreEqual("NumA + NumB", interpolatable.Item);
     Assert.AreEqual(nums, interpolatable.Instance);
     Assert.AreEqual(InterpolatableType.Expression, interpolatable.Type);
     Assert.AreEqual("3", interpolatable.Value);
 }
Ejemplo n.º 15
0
        public void TestResultsOf1To200()
        {
            Numbers n = new Numbers();
            n.SendOutputEvent += new Numbers.SendOutputEventHandler(n_SendOutputEvent);

            n.printNumbers(1, 200);

            System.IO.FileStream fs = new System.IO.FileStream("C:\\Temp\\knownresults.txt", System.IO.FileMode.Open);
            byte[] array = new byte[fs.Length];
            fs.Read(array, 0, (int)fs.Length);
            fs.Close();

            Assert.IsFalse(System.Text.ASCIIEncoding.ASCII.GetString(array) != _output.ToString());
        }
Ejemplo n.º 16
0
        private static void Start()
        {
            const string exitCommand = "exit";
            do
            {
                double temp;
                var numbers = new Numbers();
                Console.WriteLine("First number: ");

                if (double.TryParse(Console.ReadLine(), out temp))
                {
                    numbers.X = temp;
                }
                else
                {
                    Console.WriteLine("Is not a valid number.");
                    continue;
                }

                Console.WriteLine("Second number: ");
                if (double.TryParse(Console.ReadLine(), out temp))
                {
                    numbers.Y = temp;
                }
                else
                {
                    Console.WriteLine("Is not a valid number.");
                    continue;
                }

                Console.WriteLine("Introduce the operation between numbers(the operation should be one of +, -, * and /.): ");
                string op = Console.ReadLine();

                var controller = new CalculatorController();
                ViewBase view;
                try
                {
                    view = controller.Calc(op, numbers);
                }
                catch (ArgumentException)
                {
                    Console.WriteLine("Not valid operation.");
                    continue;
                }

                view.ExecuteResult();

                Console.WriteLine("For exit type \"exit\".");
            } while (!exitCommand.Equals(Console.ReadLine()));
        }
Ejemplo n.º 17
0
 public List<int> createList()
 {
     List<int> numbers = new List<int> { };
     RandomNumber rand = new RandomNumber();
     int i = 0;
     Numbers cube = new Numbers();
     int eachcube = cube.cubeint;
     while (i <= eachcube)
     {
         i++;
         int number = rand.getNewRandom();
         numbers.Add(number);
     }
     return numbers;
 }
Ejemplo n.º 18
0
        public Grid()
        {
            this.BackColor = Color.FromArgb(0, Color.White);
             _numbers = new Numbers(this);

             this.Restore();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                ControlStyles.UserPaint |
                ControlStyles.OptimizedDoubleBuffer,
                true);

            _propEv = new PropertyChangedEventHandler(PropertyChanged);
            AppEvents.NewGame += new EventHandler(AppEvents_NewGame);
            this.WatchProps();
        }
Ejemplo n.º 19
0
        public ActionResult GetNumberSeries(Numbers numbers)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ViewBag.Message = _noSeqCalculatorService.NumericSeqResult(numbers.Number);
                }
                return View("index");

            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return View("Index");
            }
        }
Ejemplo n.º 20
0
        static void Main(string[] args)
        {
            Numbers n = new Numbers();
            n.SendOutputEvent += new Numbers.SendOutputEventHandler(n_SendOutputEvent);

            n.printNumbers(1, 200);

            //Console.WriteLine(s);
            //printNumbers(1, 20);
            //System.IO.FileStream fs = new System.IO.FileStream("C:\\Temp\\knownresults.txt", System.IO.FileMode.CreateNew);

            //byte[] array = System.Text.ASCIIEncoding.ASCII.GetBytes(_output.ToString());

            //fs.Write(array, 0, array.Length);

            //fs.Close();
            Console.ReadLine();
        }
Ejemplo n.º 21
0
 static void Main(string[] args)
 {
     while (true)
     {
         Console.WriteLine("Enter 6 numers pressing enter after each\n");
         string[] numbers = new string[6];
         for (int i = 0; i < 6; i++)
         {
             numbers[i] = Console.ReadLine();
         }
         Console.WriteLine("Enter the target and then press enter\n");
         int target = Convert.ToInt32(Console.ReadLine());
         Numbers num = new Numbers(numbers[0],numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]);
         generateSequences gen = new generateSequences(num);
         solver solve = new solver(gen.getSequences(), target);
         foreach (string s in solve.analyseResults())
         {
             Console.WriteLine(s);
         }
     }
 }
Ejemplo n.º 22
0
        static void Main()
        {
            try
            {
                Numbers oneNumber = new Numbers(300);
            }
            catch (InvalidRangeException<int> ex)
            {
                Console.WriteLine("{0} \nmin:{1} \nmax:{2}",ex.Message,ex.Min,ex.Max);
            }

            Console.WriteLine();

            try
            {
                Dates aDate = new Dates(new DateTime(2014,3,31));
            }
            catch (InvalidRangeException<DateTime> ex)
            {
                Console.WriteLine("{0} \nmin:{1} \nmax:{2}", ex.Message, ex.Min, ex.Max);
            }
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            // Way 1
            Thread t1 = new Thread(new ThreadStart(Numbers.printNumbers));

            // Way 2
            Thread t2 = new Thread( delegate() { Numbers.printNumbers();} );

            // Way 3
            Thread t3 = new Thread(() => Numbers.printNumbers() );

            t1.Start();

            // ParameterizedThreadStart way
            Console.Write("Please, Enter the target numbers");
            object target = Console.ReadLine();

            Numbers number = new Numbers();
            ParameterizedThreadStart parameterizedThreadStart = new ParameterizedThreadStart(number.printNumbers3);
            Thread t4 = new Thread(parameterizedThreadStart);
            t4.Start(target);

            Console.ReadKey();
        }
Ejemplo n.º 24
0
        public static void Main()
        {
            Numbers mylist = new Numbers();
            Console.WriteLine("Please insert your first list of numbers:");
            string input1 = Console.ReadLine();
            var firstvalues = mylist.CreateList(input1);

            //Console.WriteLine("The elements in the list are:");
            //mylist.Display(firstvalues);

            Console.WriteLine("Please insert your second list of numbers:");
            string input2 = Console.ReadLine();
            var secondvalues = mylist.CreateList(input2);
            //Console.WriteLine("The elements in your second list are:");
            //mylist.Display(secondvalues);

            var count = firstvalues.Size();
            Console.WriteLine("the size of first list is:{0}", count);

            var secondcount = secondvalues.Size();
            Console.WriteLine("the size of second list is:{0}", secondcount);

            SingleyLinkedList addResult = mylist.AddLists(firstvalues, secondvalues);
            Console.WriteLine("The addition result is:");
            mylist.Display(addResult);

            SingleyLinkedList subtracLists = mylist.Subtrac(firstvalues, secondvalues);
            Console.WriteLine("The Subtraction result is:");
            mylist.Display(subtracLists);

             SingleyLinkedList multipliedLists = mylist.Multiply(firstvalues, secondvalues);
             Console.WriteLine("the Multiplication bufflist result is:");
             mylist.Display(multipliedLists);

               Console.ReadLine();
        }
Ejemplo n.º 25
0
 public void GoldenRatio()
 {
     Assert.Equal(1.61803398875, NMath.Round(Numbers.GoldenRatio(), 11));
 }
Ejemplo n.º 26
0
 // GET: Home
 public ActionResult Index()
 {
     Numbers numbers = new Numbers();
     return View(numbers);
 }
Ejemplo n.º 27
0
        public object Evaluate(IDictionary <string, object> variables)
        {
            if (_leftHandSide == null)
            {
                throw new MissingParticipantException("The left hand side of the operation is missing.");
            }
            else if (_rightHandSide == null)
            {
                throw new MissingParticipantException("The right hand side of the operation is missing.");
            }

            // We will evaluate the left hand side but hold off on the right hand side as it may not be necessary
            var lhsResult = _leftHandSide.Evaluate(variables);

            var ignoreCase = ((_options & ExpressiveOptions.IgnoreCase) == ExpressiveOptions.IgnoreCase);

            switch (_expressionType)
            {
            case BinaryExpressionType.Unknown:
                break;

            case BinaryExpressionType.And:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToBoolean(l) && Convert.ToBoolean(r)));

            case BinaryExpressionType.Or:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToBoolean(l) || Convert.ToBoolean(r)));

            case BinaryExpressionType.NotEqual:
            {
                object rhsResult = null;

                // Use the type of the left operand to make the comparison
                if (lhsResult == null)
                {
                    rhsResult = _rightHandSide.Evaluate(variables);
                    if (rhsResult != null)
                    {
                        // 2 nulls make a match!
                        return(true);
                    }

                    return(false);
                }
                else
                {
                    rhsResult = _rightHandSide.Evaluate(variables);

                    // If we got here then the lhsResult is not null.
                    if (rhsResult == null)
                    {
                        return(true);
                    }
                }

                return(Comparison.CompareUsingMostPreciseType(lhsResult, rhsResult, ignoreCase) != 0);
            }

            case BinaryExpressionType.LessThanOrEqual:
            {
                // Use the type of the left operand to make the comparison
                if (lhsResult == null)
                {
                    return(null);
                }

                var rhsResult = _rightHandSide.Evaluate(variables);
                if (rhsResult == null)
                {
                    return(null);
                }

                return(Comparison.CompareUsingMostPreciseType(lhsResult, rhsResult, ignoreCase) <= 0);
            }

            case BinaryExpressionType.GreaterThanOrEqual:
            {
                // Use the type of the left operand to make the comparison
                if (lhsResult == null)
                {
                    return(null);
                }

                var rhsResult = _rightHandSide.Evaluate(variables);
                if (rhsResult == null)
                {
                    return(null);
                }

                return(Comparison.CompareUsingMostPreciseType(lhsResult, rhsResult, ignoreCase) >= 0);
            }

            case BinaryExpressionType.LessThan:
            {
                // Use the type of the left operand to make the comparison
                if (lhsResult == null)
                {
                    return(null);
                }

                var rhsResult = _rightHandSide.Evaluate(variables);
                if (rhsResult == null)
                {
                    return(null);
                }

                return(Comparison.CompareUsingMostPreciseType(lhsResult, rhsResult, ignoreCase) < 0);
            }

            case BinaryExpressionType.GreaterThan:
            {
                // Use the type of the left operand to make the comparison
                if (lhsResult == null)
                {
                    return(null);
                }

                var rhsResult = _rightHandSide.Evaluate(variables);
                if (rhsResult == null)
                {
                    return(null);
                }

                return(Comparison.CompareUsingMostPreciseType(lhsResult, rhsResult, ignoreCase) > 0);
            }

            case BinaryExpressionType.Equal:
            {
                object rhsResult = null;

                // Use the type of the left operand to make the comparison
                if (lhsResult == null)
                {
                    rhsResult = _rightHandSide.Evaluate(variables);
                    if (rhsResult == null)
                    {
                        // 2 nulls make a match!
                        return(true);
                    }

                    return(false);
                }
                else
                {
                    rhsResult = _rightHandSide.Evaluate(variables);

                    // If we got here then the lhsResult is not null.
                    if (rhsResult == null)
                    {
                        return(false);
                    }
                }

                return(Comparison.CompareUsingMostPreciseType(lhsResult, rhsResult, ignoreCase) == 0);
            }

            case BinaryExpressionType.Subtract:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Numbers.Subtract(l, r)));

            case BinaryExpressionType.Add:
                if (lhsResult is string)
                {
                    return(((string)lhsResult) + _rightHandSide.Evaluate(variables) as string);
                }

                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Numbers.Add(l, r)));

            case BinaryExpressionType.Modulus:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Numbers.Modulus(l, r)));

            case BinaryExpressionType.Divide:
            {
                var rhsResult = _rightHandSide.Evaluate(variables);

                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) =>
                    {
                        return (l == null || r == null || IsReal(l) || IsReal(r))
                                     ? Numbers.Divide(l, r)
                                     : Numbers.Divide(Convert.ToDouble(l), r);
                    }));
            }

            case BinaryExpressionType.Multiply:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Numbers.Multiply(l, r)));

            case BinaryExpressionType.BitwiseOr:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToUInt16(l) | Convert.ToUInt16(r)));

            case BinaryExpressionType.BitwiseAnd:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToUInt16(l) & Convert.ToUInt16(r)));

            case BinaryExpressionType.BitwiseXOr:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToUInt16(l) ^ Convert.ToUInt16(r)));

            case BinaryExpressionType.LeftShift:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToUInt16(l) << Convert.ToUInt16(r)));

            case BinaryExpressionType.RightShift:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => Convert.ToUInt16(l) >> Convert.ToUInt16(r)));

            case BinaryExpressionType.NullCoalescing:
                return(this.Evaluate(lhsResult, _rightHandSide, variables, (l, r) => l ?? r));

            default:
                break;
            }

            return(null);
        }
Ejemplo n.º 28
0
 public Benchmarks() : this(Numbers.Distinct(), Start.A.Selection.Of.Type <int>()
                            .As.Sequence.Array.By.Self.Query()
                            .Distinct()
                            .Out())
 {
 }
 public void ThrowsAnExceptionForUnsupportedInterpolatableTypes()
 {
     const string src = "This is the first number #{Num[0]}";
     var nums = new Numbers { Num = new string[] { "1", "2", "3" } };
     var interpolatables = nums.InterpolatablesOf(src);
     Assert.IsNotNull(interpolatables);
     Assert.AreEqual(1, interpolatables.Count);
     var interpolatable = interpolatables.First();
     var subList = interpolatable.InterpolatablesOfExpr(nums, src);
 }
Ejemplo n.º 30
0
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double v = (double)value;

        return(Numbers.FormatNumberWithGroupingSeparators(v));
    }
Ejemplo n.º 31
0
        public Numbers processNumbers(string message, string type)
        {

            if (string.IsNullOrEmpty(message))
            {
                return null;
            }
            Numbers tmpPhoneNumbers = new Numbers();

            char splitChar = ';';
            string[] tempArr = message.Split(splitChar);
            for (int i = 0; i < tempArr.Length; i++)
            {
                //userInfo = dbManager.GetUser("", tempArr[i], "", "", "", "");
                USER_INFO userInfo = new USER_INFO();
                userInfo.phone = tempArr[i];
                USER_INFO[] userInfoArr = myGlobals.dbManager.GetUser(userInfo);
                if (userInfoArr.Length > 0)
                {
                    tmpPhoneNumbers.addNumber(userInfoArr[0].type, tempArr[i]);
                }
                else
                {
                    //dbManager.AddUser("", tempArr[i], "", "", "", type);
                    userInfo.type = type;
                    if (myGlobals.pocTypes.Contains(type))
                        myGlobals.dbManager.AddUser(userInfo);
                    tmpPhoneNumbers.addNumber(type, tempArr[i]);
                }
            }
            return tmpPhoneNumbers;
        }
 // Use this for initialization
 void Start()
 {
     BroadcastMessage("TestBroadCast");
     numbers += Sing;
     numbers += SingPartTwo;
 }
Ejemplo n.º 33
0
 public override object Evaluate(IDictionary <string, object> variables) =>
 Numbers.Subtract(0, this.expression.Evaluate(variables));
Ejemplo n.º 34
0
        private LiveryIconEditor(CarSkinObject skin, bool quickMode, bool randomMode)
        {
            _quickMode = quickMode;
            Skin       = skin;

            DataContext = this;
            InitializeComponent();

            if (randomMode)
            {
                SelectedShape = Shapes.RandomElement();
            }
            else
            {
                SelectedShape = Shapes.GetByIdOrDefault(ValuesStorage.GetString(KeyShape)) ?? Shapes.FirstOrDefault();
            }
            SelectedStyle   = Styles.GetByIdOrDefault(ValuesStorage.GetString(KeyStyle)) ?? Styles.FirstOrDefault();
            SelectedNumbers = string.IsNullOrWhiteSpace(skin.SkinNumber) || skin.SkinNumber == @"0"
                    ? Numbers.FirstOrDefault() : Numbers.GetByIdOrDefault(ValuesStorage.GetString(KeyNumbers)) ?? Numbers.FirstOrDefault();

            Buttons              = new[] { OkButton, CancelButton };
            Model.Value          = string.IsNullOrWhiteSpace(skin.SkinNumber) ? @"0" : skin.SkinNumber;
            Model.TextColorValue = Colors.White;

            try {
                using (var bitmap = Image.FromFile(skin.PreviewImage)) {
                    var colors = ImageUtils.GetBaseColors((Bitmap)bitmap);
                    Model.ColorValue          = colors.Select(x => (System.Drawing.Color?)x).FirstOrDefault()?.ToColor() ?? Colors.White;
                    Model.SecondaryColorValue = colors.Select(x => (System.Drawing.Color?)x).ElementAtOrDefault(1)?.ToColor() ?? Colors.Black;
                    Model.TertiaryColorValue  = colors.Select(x => (System.Drawing.Color?)x).ElementAtOrDefault(2)?.ToColor() ?? Colors.Black;
                }
            } catch (Exception e) {
                Logging.Warning("Can’t find base colors: " + e);
                Model.ColorValue          = Colors.White;
                Model.SecondaryColorValue = Colors.Black;
                Model.TertiaryColorValue  = Colors.Black;
            }
        }
Ejemplo n.º 35
0
 public Sabores()
 {
     Number = new Numbers();
 }
Ejemplo n.º 36
0
        private string WtDisplay(double weightKg)
        {
            var factor = elem.WeightUnitCBox.SelectedIndex == 0 ? 1.0 : Constants.KgLbRatio;

            return(Numbers.RoundToInt(weightKg * factor).ToString());
        }
Ejemplo n.º 37
0
 public void GetWord_GetOneNumberFromUser_Word()
 {
     Assert.AreEqual("One", Numbers.GetWord("1"));
 }
Ejemplo n.º 38
0
 public void GetWord_GetTwoNumbersFromUser_Word()
 {
     Assert.AreEqual("Nineteen", Numbers.GetWord("19"));
 }
Ejemplo n.º 39
0
 private int LengthConvertUnit(double lengthMeter, LengthUnit unit)
 {
     return(Numbers.RoundToInt(unit == LengthUnit.Feet ?
                               lengthMeter * MeterFtRatio : lengthMeter));
 }
Ejemplo n.º 40
0
 private int TempConvertUnit(double tempCelsuis, TemperatureUnit tempUnit)
 {
     return(Numbers.RoundToInt(tempUnit == TemperatureUnit.Fahrenheit ?
                               ConversionTools.ToFahrenheit(tempCelsuis) : tempCelsuis));
 }
Ejemplo n.º 41
0
 public void IsPositiveSign_Double_Custom_Tolerance(double number, double tolerance, bool expected)
 {
     Assert.Equal(expected, Numbers.IsPositiveSign(number, tolerance));
 }
Ejemplo n.º 42
0
        public override void Visit(BinaryExpression expression)
        {
            // simulate Lazy<Func<>> behavior for late evaluation
            object        leftValue = null;
            Func <object> left      = () =>
            {
                if (leftValue == null)
                {
                    expression.LeftExpression.Accept(this);
                    leftValue = Result;
                }
                return(leftValue);
            };

            // simulate Lazy<Func<>> behavior for late evaluation
            object        rightValue = null;
            Func <object> right      = () =>
            {
                if (rightValue == null)
                {
                    expression.RightExpression.Accept(this);
                    rightValue = Result;
                }
                return(rightValue);
            };

            switch (expression.Type)
            {
            case BinaryExpressionType.And:
                Result = Convert.ToBoolean(left()) && Convert.ToBoolean(right());
                break;

            case BinaryExpressionType.Or:
                Result = Convert.ToBoolean(left()) || Convert.ToBoolean(right());
                break;

            case BinaryExpressionType.Div:
                Result = IsReal(left()) || IsReal(right())
                                 ? Numbers.Divide(left(), right())
                                 : Numbers.Divide(Convert.ToDouble(left()), right());
                break;

            case BinaryExpressionType.Equal:
                // Use the type of the left operand to make the comparison
                Result = CompareUsingMostPreciseType(left(), right()) == 0;
                break;

            case BinaryExpressionType.Greater:
                // Use the type of the left operand to make the comparison
                Result = CompareUsingMostPreciseType(left(), right()) > 0;
                break;

            case BinaryExpressionType.GreaterOrEqual:
                // Use the type of the left operand to make the comparison
                Result = CompareUsingMostPreciseType(left(), right()) >= 0;
                break;

            case BinaryExpressionType.Lesser:
                // Use the type of the left operand to make the comparison
                Result = CompareUsingMostPreciseType(left(), right()) < 0;
                break;

            case BinaryExpressionType.LesserOrEqual:
                // Use the type of the left operand to make the comparison
                Result = CompareUsingMostPreciseType(left(), right()) <= 0;
                break;

            case BinaryExpressionType.Minus:
                Result = Numbers.Soustract(left(), right());
                break;

            case BinaryExpressionType.Modulo:
                Result = Numbers.Modulo(left(), right());
                break;

            case BinaryExpressionType.NotEqual:
                // Use the type of the left operand to make the comparison
                Result = CompareUsingMostPreciseType(left(), right()) != 0;
                break;

            case BinaryExpressionType.Plus:
                if (left() is string)
                {
                    Result = String.Concat(left(), right());
                }
                else
                {
                    Result = Numbers.Add(left(), right());
                }

                break;

            case BinaryExpressionType.Times:
                Result = Numbers.Multiply(left(), right());
                break;

            case BinaryExpressionType.BitwiseAnd:
                Result = Convert.ToUInt16(left()) & Convert.ToUInt16(right());
                break;


            case BinaryExpressionType.BitwiseOr:
                Result = Convert.ToUInt16(left()) | Convert.ToUInt16(right());
                break;


            case BinaryExpressionType.BitwiseXOr:
                Result = Convert.ToUInt16(left()) ^ Convert.ToUInt16(right());
                break;


            case BinaryExpressionType.LeftShift:
                Result = Convert.ToUInt16(left()) << Convert.ToUInt16(right());
                break;


            case BinaryExpressionType.RightShift:
                Result = Convert.ToUInt16(left()) >> Convert.ToUInt16(right());
                break;
            }
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Returns true if x is zero, otherwise false.
 /// </summary>
 /// <param name="n">Object to test.</param>
 /// <returns>
 /// Returns true if x is zero, otherwise false.
 /// </returns>
 public object Invoke(object n) => Numbers.IsZero(n);
Ejemplo n.º 44
0
 public override int Calculate() => Numbers.Where(x => x % 2 == 0).Sum();
Ejemplo n.º 45
0
 public IActionResult Post([FromBody] Numbers numbers)
 {
     return(Ok(new { sum = numbers.Values.Sum() }));
 }
Ejemplo n.º 46
0
 public void Can_serialize_date_to_unix_timestamp()
 {
     var target = new Numbers(new DateTime(2012, 5, 26, 0, 0, 0, DateTimeKind.Utc));
     target.Timestamp.Should().HaveValue();
     target.Timestamp.Should().Be(1337990400);
 }
Ejemplo n.º 47
0
 private static ulong Solution()
 {
     return(Numbers.FindLargestPalindromeMadeFromProductOf(3));
 }
Ejemplo n.º 48
0
        public void Can_set_date_which_sets_timestamp()
        {
            var target = new Numbers { Date = new DateTime(2012, 5, 26, 0, 0, 0, DateTimeKind.Utc), Value = 3 };
            target.Timestamp.Should().HaveValue();
            target.Timestamp.Should().Be(1337990400);

            string result = Serializer.Serialize(target);
            result.Should().NotBeNull();
        }
Ejemplo n.º 49
0
 public void NumbersTests(string firstNum, string secondNum, string strExpected)
 {
     Assert.AreEqual(Numbers.Sum(firstNum, secondNum), strExpected);
 }
Ejemplo n.º 50
0
 public void TestForExample()
 {
     Assert.AreEqual(55, Numbers.GetStringValue("SKY"));
     Assert.IsTrue(Numbers.IsTriangleNumber(55));
 }
Ejemplo n.º 51
0
 public void Can_serialize_value_properly()
 {
     var target = new Numbers { Value = 3.5m };
     string result = Serializer.Serialize(target);
     result.Should().NotBeNullOrEmpty();
 }
Ejemplo n.º 52
0
        public override void Visit(Function function)
        {
            var args = new FunctionArgs
            {
                Parameters = new Expression[function.Expressions.Length]
            };

            // Don't call parameters right now, instead let the function do it as needed.
            // Some parameters shouldn't be called, for instance, in a if(), the "not" value might be a division by zero
            // Evaluating every value could produce unexpected behaviour
            for (int i = 0; i < function.Expressions.Length; i++)
            {
                args.Parameters[i] = new Expression(function.Expressions[i], options);
                args.Parameters[i].EvaluateFunction  += EvaluateFunction;
                args.Parameters[i].EvaluateParameter += EvaluateParameter;

                // Assign the parameters of the Expression to the arguments so that custom Functions and Parameters can use them
                args.Parameters[i].Parameters = Parameters;
            }

            // Calls external implementation
            OnEvaluateFunction(options.IgnoreCase() ? function.Identifier.Name.ToLower() : function.Identifier.Name, args);

            // If an external implementation was found get the result back
            if (args.HasResult)
            {
                Result = args.Result;
                return;
            }

            switch (function.Identifier.Name.ToLower())
            {
                #region Abs

            case "abs":

                CheckCase("Abs", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Abs() takes exactly 1 argument");
                }

                Result = Math.Abs(Convert.ToDecimal(
                                      Evaluate(function.Expressions[0]))
                                  );

                break;

                #endregion Abs

                #region Acos

            case "acos":

                CheckCase("Acos", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Acos() takes exactly 1 argument");
                }

                Result = Math.Acos(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Acos

                #region Asin

            case "asin":

                CheckCase("Asin", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Asin() takes exactly 1 argument");
                }

                Result = Math.Asin(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Asin

                #region Atan

            case "atan":

                CheckCase("Atan", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Atan() takes exactly 1 argument");
                }

                Result = Math.Atan(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Atan

                #region Ceiling

            case "ceiling":

                CheckCase("Ceiling", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Ceiling() takes exactly 1 argument");
                }

                Result = Math.Ceiling(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Ceiling

                #region Cos

            case "cos":

                CheckCase("Cos", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Cos() takes exactly 1 argument");
                }

                Result = Math.Cos(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Cos

                #region Exp

            case "exp":

                CheckCase("Exp", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Exp() takes exactly 1 argument");
                }

                Result = Math.Exp(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Exp

                #region Floor

            case "floor":

                CheckCase("Floor", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Floor() takes exactly 1 argument");
                }

                Result = Math.Floor(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Floor

                #region IEEERemainder

            case "ieeeremainder":

                CheckCase("IEEERemainder", function.Identifier.Name);

                if (function.Expressions.Length != 2)
                {
                    throw new ArgumentException("IEEERemainder() takes exactly 2 arguments");
                }

                Result = Math.IEEERemainder(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToDouble(Evaluate(function.Expressions[1])));

                break;

                #endregion IEEERemainder

                #region Log

            case "log":

                CheckCase("Log", function.Identifier.Name);

                if (function.Expressions.Length != 2)
                {
                    throw new ArgumentException("Log() takes exactly 2 arguments");
                }

                Result = Math.Log(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToDouble(Evaluate(function.Expressions[1])));

                break;

                #endregion Log

                #region Log10

            case "log10":

                CheckCase("Log10", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Log10() takes exactly 1 argument");
                }

                Result = Math.Log10(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Log10

                #region Pow

            case "pow":

                CheckCase("Pow", function.Identifier.Name);

                if (function.Expressions.Length != 2)
                {
                    throw new ArgumentException("Pow() takes exactly 2 arguments");
                }

                Result = Math.Pow(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToDouble(Evaluate(function.Expressions[1])));

                break;

                #endregion Pow

                #region Round

            case "round":

                CheckCase("Round", function.Identifier.Name);

                if (function.Expressions.Length != 2)
                {
                    throw new ArgumentException("Round() takes exactly 2 arguments");
                }

                MidpointRounding rounding = options.RoundAwayFromZero() ? MidpointRounding.AwayFromZero : MidpointRounding.ToEven;

                Result = Math.Round(Convert.ToDouble(Evaluate(function.Expressions[0])), Convert.ToInt16(Evaluate(function.Expressions[1])), rounding);

                break;

                #endregion Round

                #region Sign

            case "sign":

                CheckCase("Sign", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Sign() takes exactly 1 argument");
                }

                Result = Math.Sign(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Sign

                #region Sin

            case "sin":

                CheckCase("Sin", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Sin() takes exactly 1 argument");
                }

                Result = Math.Sin(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Sin

                #region Sqrt

            case "sqrt":

                CheckCase("Sqrt", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Sqrt() takes exactly 1 argument");
                }

                Result = Math.Sqrt(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Sqrt

                #region Tan

            case "tan":

                CheckCase("Tan", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Tan() takes exactly 1 argument");
                }

                Result = Math.Tan(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Tan

                #region Truncate

            case "truncate":

                CheckCase("Truncate", function.Identifier.Name);

                if (function.Expressions.Length != 1)
                {
                    throw new ArgumentException("Truncate() takes exactly 1 argument");
                }

                Result = Math.Truncate(Convert.ToDouble(Evaluate(function.Expressions[0])));

                break;

                #endregion Truncate

                #region Max

            case "max":

                CheckCase("Max", function.Identifier.Name);

                if (function.Expressions.Length != 2)
                {
                    throw new ArgumentException("Max() takes exactly 2 arguments");
                }

                object maxleft  = Evaluate(function.Expressions[0]);
                object maxright = Evaluate(function.Expressions[1]);

                Result = Numbers.Max(maxleft, maxright);
                break;

                #endregion Max

                #region Min

            case "min":

                CheckCase("Min", function.Identifier.Name);

                if (function.Expressions.Length != 2)
                {
                    throw new ArgumentException("Min() takes exactly 2 arguments");
                }

                object minleft  = Evaluate(function.Expressions[0]);
                object minright = Evaluate(function.Expressions[1]);

                Result = Numbers.Min(minleft, minright);
                break;

                #endregion Min

                #region if

            case "if":

                CheckCase("if", function.Identifier.Name);

                if (function.Expressions.Length != 3)
                {
                    throw new ArgumentException("if() takes exactly 3 arguments");
                }

                bool cond = Convert.ToBoolean(Evaluate(function.Expressions[0]));

                Result = cond ? Evaluate(function.Expressions[1]) : Evaluate(function.Expressions[2]);
                break;

                #endregion if

                #region in

            case "in":

                CheckCase("in", function.Identifier.Name);

                if (function.Expressions.Length < 2)
                {
                    throw new ArgumentException("in() takes at least 2 arguments");
                }

                object parameter = Evaluate(function.Expressions[0]);

                bool evaluation = false;

                // Goes through any values, and stop whe one is found
                for (int i = 1; i < function.Expressions.Length; i++)
                {
                    object argument = Evaluate(function.Expressions[i]);
                    if (CompareUsingMostPreciseType(parameter, argument) == 0)
                    {
                        evaluation = true;
                        break;
                    }
                }

                Result = evaluation;
                break;

                #endregion in

            default:
                throw new ArgumentException("Function not found",
                                            function.Identifier.Name);
            }
        }
Ejemplo n.º 53
0
        public void convert()
        {
            LogicValuesNumbersConverter converter = new LogicValuesNumbersConverter();

            ILineCollection lines = BaseLineCollection.createLineCollection(3);

            // 000

            int linesCount = lines.Size;

            for (int i = 0; i < linesCount; ++i)
            {
                lines[i] = new Line();
            }

            //000
            lines[0].Value = LogicValue.Enum.Low;
            lines[1].Value = LogicValue.Enum.Low;
            lines[2].Value = LogicValue.Enum.Low;

            Numbers result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[0], 0);

            // 111
            lines[0].Value = LogicValue.Enum.High;
            lines[1].Value = LogicValue.Enum.High;
            lines[2].Value = LogicValue.Enum.High;

            result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[0], 7);

            // 00X
            lines[0].Value = LogicValue.Enum.DontCare;
            lines[1].Value = LogicValue.Enum.Low;
            lines[2].Value = LogicValue.Enum.Low;

            result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 2);

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(1));

            // 0X0
            lines[0].Value = LogicValue.Enum.Low;
            lines[1].Value = LogicValue.Enum.DontCare;

            result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 2);

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(2));

            // X00
            lines[1].Value = LogicValue.Enum.Low;
            lines[2].Value = LogicValue.Enum.DontCare;

            result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 2);

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(4));

            // XX0
            lines[1].Value = LogicValue.Enum.DontCare;

            result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 4);

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(2));
            Assert.IsTrue(result.Contains(4));
            Assert.IsTrue(result.Contains(6));

            // XXX
            lines[0].Value = LogicValue.Enum.DontCare;

            result = converter.toNumbers(lines, 0, 2);

            Assert.AreEqual(result.Count, 8);

            Assert.IsTrue(result.Contains(0));
            Assert.IsTrue(result.Contains(1));
            Assert.IsTrue(result.Contains(2));
            Assert.IsTrue(result.Contains(3));
            Assert.IsTrue(result.Contains(4));
            Assert.IsTrue(result.Contains(5));
            Assert.IsTrue(result.Contains(6));
            Assert.IsTrue(result.Contains(7));
        }
        public static string GeneratePassword(int length = 10)
        {
            const string NonAlphanumericCharacters = "#!%$";
            const string Numbers = "1234567890";
            const string AlphanumericCharactersLowercase = "abcdefghijklmnopqrstuvwxyz";
            const string AlphanumericCharactersUppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            const string Valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

            bool hasUppercase       = false;
            bool hasLowercase       = false;
            bool hasNumbers         = false;
            bool hasNonAlphanumeric = false;

            var stringBuilder = new StringBuilder();

            while (0 < length--)
            {
                var character = Valid[_cryptoRandom.Next(Valid.Length)];
                stringBuilder.Append(character);

                if (NonAlphanumericCharacters.Contains(character))
                {
                    hasNonAlphanumeric = true;
                }

                if (AlphanumericCharactersLowercase.Contains(character))
                {
                    hasLowercase = true;
                }

                if (AlphanumericCharactersUppercase.Contains(character))
                {
                    hasUppercase = true;
                }

                if (Numbers.Contains(character))
                {
                    hasNumbers = true;
                }
            }

            if (!hasLowercase)
            {
                stringBuilder.Append(AlphanumericCharactersLowercase[_cryptoRandom.Next(AlphanumericCharactersLowercase.Length)]);
            }

            if (!hasUppercase)
            {
                stringBuilder.Append(AlphanumericCharactersUppercase[_cryptoRandom.Next(AlphanumericCharactersUppercase.Length)]);
            }

            if (!hasNonAlphanumeric)
            {
                stringBuilder.Append(NonAlphanumericCharacters[_cryptoRandom.Next(NonAlphanumericCharacters.Length)]);
            }

            if (!hasNumbers)
            {
                stringBuilder.Append(Numbers[_cryptoRandom.Next(Numbers.Length)]);
            }

            return(stringBuilder.ToString());
        }