Exemple #1
0
        public void summing_all_doubles_in_a_json()
        {
            string data = @"
{
    ""v"": 9.87e2, 
    ""a"": [ 8.65, true, {}, {""x"" : 45.98, ""y"":12.786}, 874.6324 ]
}";
            var    v    = new JSONDoubleSum(data);

            v.Visit();
            Assert.That(v.Sum, Is.EqualTo(9.87e2 + 8.65 + 45.98 + 12.786 + 874.6324));
        }
Exemple #2
0
        public void summing_all_doubles_in_a_json()
        {
            string data = @"
{
    ""v"": 9.87e2, 
    ""a"": [ 8.65, true, {}, {""x"" : 45.98, ""y"":12.786}, 874.6324 ]
}";
            var    v    = new JSONDoubleSum(data);

            v.Visit();
            v.Sum.Should().Be(9.87e2 + 8.65 + 45.98 + 12.786 + 874.6324);
        }
Exemple #3
0
        public void using_JSONVisitor_to_transform_all_doubles_in_it()
        {
            string data = @"
{
    ""v"": 9.87e2, 
    ""a"": [ 8.65, true, {}, {""x"" : 45.98, ""y"":12.786}, 874.6324 ]
}";
            var    v    = new JSONDoubleRewriter(data, d =>
            {
                Console.WriteLine("{0} => {1}", d, Math.Floor(d).ToString());
                return(Math.Floor(d).ToString());
            });

            string rewritten = v.Rewrite();

            var summer = new JSONDoubleSum(rewritten);

            summer.Visit();
            Assert.That(summer.Sum, Is.EqualTo(987 + 8 + 45 + 12 + 874));
        }
        public void summing_all_doubles_in_a_json()
        {
            string data = @"
{
    ""v"": 9.87e2, 
    ""a"": [ 8.65, true, {}, {""x"" : 45.98, ""y"":12.786}, 874.6324 ]
}";
            var v = new JSONDoubleSum( data );
            v.Visit();
            Assert.That( v.Sum, Is.EqualTo( 9.87e2 + 8.65 + 45.98 + 12.786 + 874.6324 ) );
        }
        public void using_JSONVisitor_to_transform_all_doubles_in_it()
        {
            string data = @"
{
    ""v"": 9.87e2, 
    ""a"": [ 8.65, true, {}, {""x"" : 45.98, ""y"":12.786}, 874.6324 ]
}";
            var v = new JSONDoubleRewriter( data, d =>
            {
                Console.WriteLine( "{0} => {1}", d, Math.Floor( d ).ToString() );
                return Math.Floor( d ).ToString();
            } );
          
            string rewritten = v.Rewrite();

            var summer = new JSONDoubleSum( rewritten );
            summer.Visit();
            Assert.That( summer.Sum, Is.EqualTo( 987 + 8 + 45 + 12 + 874 ) );
        }