示例#1
0
        public void TestMinusZero()
        {
            //arrange
            string     entryNum = "-0";
            string     expected = "Minus Zero";
            ConvertNum cn       = new ConvertNum();

            // act
            Trace.WriteLine(cn.Convert(entryNum));

            // assert
            string result = cn.Convert(entryNum);

            Assert.AreEqual(expected, result);
        }
示例#2
0
        public void TestTenThous()
        {
            //arrange
            string     entryNum = "10001";
            string     expected = "Ten Thousand and One";
            ConvertNum cn       = new ConvertNum();

            // act
            Trace.WriteLine(cn.Convert(entryNum));

            // assert
            string result = cn.Convert(entryNum);

            Assert.AreEqual(expected, result);
        }
示例#3
0
        public void TestMilHundThous()
        {
            //arrange
            string     entryNum = "1100000";
            string     expected = "One Million One Hundred Thousand";
            ConvertNum cn       = new ConvertNum();

            // act
            Trace.WriteLine(cn.Convert(entryNum));

            // assert
            string result = cn.Convert(entryNum);

            Assert.AreEqual(expected, result);
        }
示例#4
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.ToString() == "Binary" && comboBox2.Text.ToString() == "Decimal")
            {
                ConvertNum.Clear();
                int binaryNum = int.Parse(enterNum.Text);
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("^[0-1]+$");
                int decimalNum = 0;
                int initialNum = 1;
                int temp       = binaryNum;
                while (temp > 0 && r.Match(binaryNum.ToString()).Success)
                {
                    int last_digit = temp % 10;
                    temp = temp / 10;

                    decimalNum += last_digit * initialNum;

                    initialNum = initialNum * 2;
                }
                ConvertNum.Text = decimalNum.ToString();
                enterNum.Clear();
            }

            else if (comboBox1.Text.ToString() == "Decimal" && comboBox2.Text.ToString() == "Binary")
            {
                ConvertNum.Clear();
                int    num = Convert.ToInt32(enterNum.Text);
                int    val;
                string result = "";
                while (num != 0)
                {
                    val     = num / 2;
                    result += (num % 2).ToString();
                    num     = val;
                }
                string binValue = Convert.ToString(num, 2);
                for (int i = result.Length - 1; i >= 0; i--)
                {
                    binValue = binValue + result[i];
                }
                ConvertNum.Text = binValue.ToString();
                enterNum.Clear();
            }
            else
            {
                MessageBox.Show("Please Select Correct Fields!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }