public void T0008_Spells_0_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(0);
            string expectedResult = "Zero";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0010_Spells_100_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(100);
            string expectedResult = "One Hundred";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0006_Spells_25212423_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(25212423);
            string expectedResult = "Twenty-five million, two hundred and twelve thousand, four hundred and twenty-three";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0007_Spells_315121810_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(315121810);
            string expectedResult = "Three hundred and fifteen million, one hundred and twenty-one thousand, eight hundred and ten";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0004_Spells_325402_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(325402);
            string expectedResult = "Three hundred and twenty-five thousand, four hundred and two";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0005_Spells_4132316_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(4132316);
            string expectedResult = "Four million, one hundred and thirty-two thousand, three hundred and sixteen";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0003_Spells_22511_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(22511);
            string expectedResult = "Twenty-two thousand, five hundred and eleven";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0002_Spells_5220_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(5220);
            string expectedResult = "five thousand, two hundred and twenty";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0013_Spells_Negative_Number_In_International_Numbering_System()
        {
            string actualResult   = NumberToWords.Convert(-1234);
            string expectedResult = "Minus One Thousand, Two Hundred and Thirty-Four";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        public void T0001_BasicTest()
        {
            string actualResult   = NumberToWords.Convert(1234);
            string expectedResult = "One Thousand, Two Hundred and Thirty-Four";

            Assert.AreEqual(expectedResult, actualResult, true);
        }
        private static int GetAnswer()
        {
            var count = 0;

            for (var i = start; i <= finish; i++)
            {
                string words;
                try
                {
                    words = NumberToWords.Convert(i);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Error converting number to words: {0}", ex.Message);
                    return(-1);
                }

                var letters = LetterCounter.Count(words);
                count += letters;

                if (verbose)
                {
                    Console.WriteLine("{0} : {1} : {2}", words, letters, count);
                    Thread.Sleep(step);
                }
            }

            return(count);
        }
Exemple #12
0
        public override void Setup()
        {
            var frame = new FrameView("Dialog Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the Dialog will size to 80% of container.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(titleEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            void Top_Loaded()
            {
                frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit)
                               + Dim.Height(numButtonsEdit) + 2;
                Top.Loaded -= Top_Loaded;
            }

            Top.Loaded += Top_Loaded;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 4,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label(" ")
            {
                X           = Pos.Center(),
                Y           = Pos.Bottom(frame) + 5,
                Width       = 25,
                Height      = 1,
                ColorScheme = Colors.Error,
            };

            //var btnText = new [] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
            var showDialogButton = new Button("Show Dialog")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
            };

            showDialogButton.Clicked += () => {
                try {
                    int width      = int.Parse(widthEdit.Text.ToString());
                    int height     = int.Parse(heightEdit.Text.ToString());
                    int numButtons = int.Parse(numButtonsEdit.Text.ToString());

                    var buttons = new List <Button> ();
                    var clicked = -1;
                    for (int i = 0; i < numButtons; i++)
                    {
                        var buttonId = i;
                        //var button = new Button (btnText [buttonId % 10],
                        //	is_default: buttonId == 0);
                        var button = new Button(NumberToWords.Convert(buttonId),
                                                is_default: buttonId == 0);
                        button.Clicked += () => {
                            clicked = buttonId;
                            Application.RequestStop();
                        };
                        buttons.Add(button);
                    }

                    // This tests dynamically adding buttons; ensuring the dialog resizes if needed and
                    // the buttons are laid out correctly
                    var dialog = new Dialog(titleEdit.Text, width, height,
                                            buttons.ToArray());
                    var add = new Button("Add a button")
                    {
                        X = Pos.Center(),
                        Y = Pos.Center()
                    };
                    add.Clicked += () => {
                        var buttonId = buttons.Count;
                        //var button = new Button (btnText [buttonId % 10],
                        //	is_default: buttonId == 0);
                        var button = new Button(NumberToWords.Convert(buttonId),
                                                is_default: buttonId == 0);
                        button.Clicked += () => {
                            clicked = buttonId;
                            Application.RequestStop();
                        };
                        buttons.Add(button);
                        dialog.AddButton(button);
                        button.TabIndex = buttons [buttons.Count - 2].TabIndex + 1;
                    };
                    dialog.Add(add);

                    Application.Run(dialog);
                    buttonPressedLabel.Text = $"{clicked}";
                } catch (FormatException) {
                    buttonPressedLabel.Text = "Invalid Options";
                }
            };
            Win.Add(showDialogButton);

            Win.Add(buttonPressedLabel);
        }
 public void Convert_Returns_Expected_String_Successfully(long number, string expected)
 {
     Assert.Equal(expected, NumberToWords.Convert(number));
 }
Exemple #14
0
        public override void Setup()
        {
            var frame = new FrameView("MessageBox Options")
            {
                X      = Pos.Center(),
                Y      = 1,
                Width  = Dim.Percent(75),
                Height = 10
            };

            Win.Add(frame);

            var label = new Label("width:")
            {
                X             = 0,
                Y             = 0,
                Width         = 15,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };

            frame.Add(label);
            var widthEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(widthEdit);

            label = new Label("height:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var heightEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(heightEdit);

            frame.Add(new Label("If height & width are both 0,")
            {
                X = Pos.Right(widthEdit) + 2,
                Y = Pos.Top(widthEdit),
            });
            frame.Add(new Label("the MessageBox will be sized automatically.")
            {
                X = Pos.Right(heightEdit) + 2,
                Y = Pos.Top(heightEdit),
            });

            label = new Label("Title:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var titleEdit = new TextField("Title")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = Dim.Fill(),
                Height = 1
            };

            frame.Add(titleEdit);

            label = new Label("Message:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var messageEdit = new TextView()
            {
                Text        = "Message",
                X           = Pos.Right(label) + 1,
                Y           = Pos.Top(label),
                Width       = Dim.Fill(),
                Height      = 5,
                ColorScheme = Colors.Dialog,
            };

            frame.Add(messageEdit);

            label = new Label("Num Buttons:")
            {
                X             = 0,
                Y             = Pos.Bottom(messageEdit),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var numButtonsEdit = new TextField("3")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(numButtonsEdit);

            label = new Label("Default Button:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var defaultButtonEdit = new TextField("0")
            {
                X      = Pos.Right(label) + 1,
                Y      = Pos.Top(label),
                Width  = 5,
                Height = 1
            };

            frame.Add(defaultButtonEdit);

            label = new Label("Style:")
            {
                X             = 0,
                Y             = Pos.Bottom(label),
                Width         = Dim.Width(label),
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            frame.Add(label);
            var styleRadioGroup = new RadioGroup(new ustring [] { "_Query", "_Error" })
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label),
            };

            frame.Add(styleRadioGroup);

            var border = new Border()
            {
                Effect3D    = true,
                BorderStyle = BorderStyle.Single
            };
            var ckbEffect3D = new CheckBox("Effect3D", true)
            {
                X = Pos.Right(label) + 1,
                Y = Pos.Top(label) + 2
            };

            ckbEffect3D.Toggled += (e) => {
                border.Effect3D = !e;
            };
            frame.Add(ckbEffect3D);

            void Top_Loaded()
            {
                frame.Height = Dim.Height(widthEdit) + Dim.Height(heightEdit) + Dim.Height(titleEdit) + Dim.Height(messageEdit)
                               + Dim.Height(numButtonsEdit) + Dim.Height(defaultButtonEdit) + Dim.Height(styleRadioGroup) + 2 + Dim.Height(ckbEffect3D);
                Top.Loaded -= Top_Loaded;
            }

            Top.Loaded += Top_Loaded;

            label = new Label("Button Pressed:")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 4,
                Height        = 1,
                TextAlignment = Terminal.Gui.TextAlignment.Right,
            };
            Win.Add(label);
            var buttonPressedLabel = new Label(" ")
            {
                X             = Pos.Center(),
                Y             = Pos.Bottom(frame) + 5,
                Width         = 25,
                Height        = 1,
                ColorScheme   = Colors.Error,
                TextAlignment = Terminal.Gui.TextAlignment.Centered
            };

            //var btnText = new [] { "_Zero", "_One", "T_wo", "_Three", "_Four", "Fi_ve", "Si_x", "_Seven", "_Eight", "_Nine" };

            var showMessageBoxButton = new Button("Show MessageBox")
            {
                X         = Pos.Center(),
                Y         = Pos.Bottom(frame) + 2,
                IsDefault = true,
            };

            showMessageBoxButton.Clicked += () => {
                try {
                    int width         = int.Parse(widthEdit.Text.ToString());
                    int height        = int.Parse(heightEdit.Text.ToString());
                    int numButtons    = int.Parse(numButtonsEdit.Text.ToString());
                    int defaultButton = int.Parse(defaultButtonEdit.Text.ToString());

                    var btns = new List <ustring> ();
                    for (int i = 0; i < numButtons; i++)
                    {
                        //btns.Add(btnText[i % 10]);
                        btns.Add(NumberToWords.Convert(i));
                    }
                    if (styleRadioGroup.SelectedItem == 0)
                    {
                        buttonPressedLabel.Text = $"{MessageBox.Query (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}";
                    }
                    else
                    {
                        buttonPressedLabel.Text = $"{MessageBox.ErrorQuery (width, height, titleEdit.Text.ToString (), messageEdit.Text.ToString (), defaultButton, border, btns.ToArray ())}";
                    }
                } catch (FormatException) {
                    buttonPressedLabel.Text = "Invalid Options";
                }
            };
            Win.Add(showMessageBoxButton);

            Win.Add(buttonPressedLabel);
        }