Ejemplo n.º 1
0
        private static void TestCompleteParse(string input, double expected)
        {
            int    position = 0;
            double parsed   = CharsParser.Parse(input.ToCharArray(), 0, input.Length, out position);

            Assert.That(parsed, Is.EqualTo(expected));
            Assert.That(position, Is.EqualTo(input.Length)); // Make sure it read everything
        }
Ejemplo n.º 2
0
        public void TestInvalidStartIndex()
        {
            int end = 1;

            Assert.That(() => CharsParser.Parse(Empty, 1, 0, out end),
                        Throws.TypeOf <ArgumentOutOfRangeException>());
            Assert.That(end, Is.EqualTo(1)); // Make sure end wasn't touched

            Assert.That(() => CharsParser.Parse(Empty, -1, 0, out end),
                        Throws.TypeOf <ArgumentOutOfRangeException>());
            Assert.That(end, Is.EqualTo(1)); // Make sure end wasn't touched
        }
Ejemplo n.º 3
0
        public void TestEmptyAndNullStrings()
        {
            int end = 1;

            Assert.That(() => CharsParser.Parse(null, 0, 0, out end),
                        Throws.TypeOf <ArgumentNullException>());
            Assert.That(end, Is.EqualTo(1)); // Make sure end wasn't touched

            //Assert.That(CharsToDouble.Parse(string.Empty, 0, out end), Is.EqualTo(default(double)));
            Assert.That(() => CharsParser.Parse(Empty, 0, 0, out end),
                        Throws.TypeOf <ArgumentOutOfRangeException>());
            //Assert.That(end, Is.EqualTo(0));
        }
Ejemplo n.º 4
0
        public void TestInvalidFormats()
        {
            // Put the spaces at the start to make sure it doesn't skip anything.
            var formats = new[]
            {
                " .",
                " ++0",
                " +"
            };

            foreach (var format in formats)
            {
                int    position;
                var    formatArray = format.ToCharArray();
                double value       = CharsParser.Parse(formatArray, 0, formatArray.Length, out position);
                Assert.That(value, Is.EqualTo(default(double)));
                Assert.That(position, Is.EqualTo(0)); // Make sure it read nothing
            }
        }
Ejemplo n.º 5
0
        public void TestPartiallyValid()
        {
            var formats = new[]
            {
                " 1e",
                " 1e.0",
                "1.e",
                " 1e++0",
                " 1ee0"
            };

            foreach (var format in formats)
            {
                int    position;
                var    formatArray = format.ToCharArray();
                double value       = CharsParser.Parse(formatArray, 0, formatArray.Length, out position);
                Assert.That(value, Is.EqualTo(1.0));
                Assert.That(position, Is.EqualTo(2)); // Make sure it read as much as it could
            }
        }
Ejemplo n.º 6
0
        public void TestStartIndex()
        {
            var formats = new[]
            {
                "###0.00###",
                "###+0.0###",
                "###-0.0###",
                "###+0e0###",
                "###-0e0###",
                "###0e-0###",
                "###.0e0.##",
            };

            foreach (var format in formats)
            {
                int    position;
                var    formatArray = format.ToCharArray();
                double value       = CharsParser.Parse(formatArray, 3, formatArray.Length, out position);
                Assert.That(value, Is.EqualTo(0.0));
                Assert.That(position, Is.EqualTo(7)); // Make sure it read as much as it could
            }
        }