Esempio n. 1
0
        /// <summary>
        /// Test the random number generation
        /// </summary>
        [Test] public void Test01_Random()
        {
            try
            {
                int    rannum;
                string strrndnum;
                int    lopcnt;
                int    lopcnt1;
                bool   usebase10;

                usebase10 = false;
                for (lopcnt1 = 0; lopcnt1 < 10; lopcnt1++)
                {
                    for (lopcnt = 1; lopcnt < 7; lopcnt++)
                    {
                        rnd.SetMaxLength(lopcnt);

                        rannum    = rnd.GetRandomNumber();
                        strrndnum = NumberDisplay.CreateNumberString((uint)rannum, lopcnt, usebase10);
                        if (strrndnum.Length != lopcnt)
                        {
                            throw new Exception("Strings not the correct length");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Assert.AreEqual(66, 1, "UnExpected Failure. " + e.Message);
            }
        }
Esempio n. 2
0
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            int  rannum;
            int  length;
            bool useBase10;

            // determine the base that we want to work in.
            if (rdobtn10.Checked)
            {
                useBase10 = true;
            }
            else
            {
                useBase10 = false;
            }

            if (txtRanlen.Text.Length == 0)
            {
                MessageBox.Show("Please Enter a valid Number", "Layout");
                txtRanlen.Focus();
                return;
            }

            try
            {
                length = Convert.ToInt32(txtRanlen.Text);
                rnd.SetMaxLength(length);
            }
            catch
            {
                MessageBox.Show("Please Enter a valid Number", "Layout");
                txtRanlen.Focus();
                return;
            }

            // get the random number
            rannum = rnd.GetRandomNumber();

            if (rdobtn10.Checked)
            {
                txtRanNumber.Text = rannum.ToString("D");
            }
            else
            {
                txtRanNumber.Text = rannum.ToString("X");
            }
            txtRanNumStr.Text = NumberDisplay.CreateNumberString((uint)rannum, length, useBase10);
        }
Esempio n. 3
0
        private void btnOK_Click(object sender, System.EventArgs e)
        {
            Checksum chk;
            string   istr;
            int      slen;
            uint     csum;
            bool     useBase10;
            int      numberLength;

            chk = new Checksum();
            // check the length
            if (txtLength.Text.Length == 0)
            {
                MessageBox.Show("Enter a valid length", "Checksum");
                txtLength.Focus();
                return;
            }
            slen = Convert.ToInt32(txtLength.Text);

            // see what base we are to use
            if (rdobtn10.Checked)
            {
                useBase10 = true;
            }
            else
            {
                useBase10 = false;
            }

            //
            // See what type of checksum is requested.
            //
            if (rdoBtnChksum1.Checked)
            {
                chk.ChecksumAlgorithm = Checksum.ChecksumType.Type1;
            }
            if (rdoBtnChksum2.Checked)
            {
                chk.ChecksumAlgorithm = Checksum.ChecksumType.Type2;
            }

            istr         = txtInput.Text;
            numberLength = Convert.ToInt32(txtLength.Text);
            chk.CalculateChecksum(istr);
            csum           = chk.ChecksumNumber;
            txtchksum.Text = NumberDisplay.CreateNumberString(csum, numberLength, useBase10);
        }