//
//  TestJSONDecoding.java
//  xal
//
//  Created by Tom Pelaia on 2/17/2011.
//  Copyright 2011 Oak Ridge National Lab. All rights reserved.
//

package xal.tools.json;

import org.junit.*;
import java.util.*;
import java.io.*;


/** test the complex number class */
public class TestJSONDecoding {
    @Test
    public void testNullDecoding() {
        Assert.assertTrue( null == JSONDecoder.decode( "null" ) );
    }
    
    
    @Test
    public void testDoubleDecoding() {
        checkValueEquality( 5.3 );
        checkValueEquality( 0.0 );
        checkValueEquality( -100.0 );
        checkValueEquality( -17.2976 );
        checkValueEquality( -32.698E53 );
        checkValueEquality( 7.5E-102 );
    }
    
    
    @Test
    public void testBooleanDecoding() {
        checkValueEquality( true );
        checkValueEquality( false );
    }
    
    
    @Test
    public void testStringDecoding() {
        checkStringEquality( "Hello, World", "\"Hello, World\"" );
        checkStringEquality( "String with an \"internal\" string.", "\"String with an \\\"internal\\\" string.\"" );
    }
    
    
    /** check whether the decoder can decode values */
    static private <DataType> void checkValueEquality( final DataType controlValue ) {
        final Object testValue = JSONDecoder.decode( String.valueOf( controlValue ) );
        assertEquality( controlValue, testValue );
    }
    
    
    /** check whether the decoder can decode strings */
    static private void checkStringEquality( final String controlValue, final String testCoding ) {
        final Object testValue = JSONDecoder.decode( testCoding );
        assertEquality( controlValue, testValue );
    }
    
    
    /** Assert whether the control value equals the test value */
    static private void assertEquality( final Object controlValue, final Object testValue ) {
        Assert.assertTrue( controlValue.equals( testValue ) );
    }
}
@@ -1100,32 +1100,920 @@
     %7D%0A    %0A    %0A
+    @Test%0A    public void testCodingDecoding() %7B%0A        checkCodingDecoding( null );%0A        checkCodingDecoding( 56.4 );%0A        checkCodingDecoding( %22Hello, World%22 );%0A        %0A        final List simpleList = new ArrayList();%0A        simpleList.add( %22Hello%22 );%0A        simpleList.add( %22World%22 );%0A        simpleList.add( %22String with %5C%22embedded%5C%22 string.%22 );%0A        simpleList.add( new Double( -32.7 )  );%0A        checkCodingDecoding( simpleList );%0A        %0A        final Map simpleMap = new HashMap();%0A        simpleMap.put( %22x%22, 41.8 );%0A        simpleMap.put( %22y%22, -2.6 );%0A        simpleMap.put( %22comment%22, %22Just a point%22 );%0A        checkCodingDecoding( simpleMap );%0A        %0A        final Map compoundMap = new HashMap();%0A        compoundMap.put( %22z%22, 23.6 ); %0A        compoundMap.put( %22simple map%22, simpleMap );%0A        compoundMap.put( %22simple list%22, simpleList );%0A    %7D%0A    %0A    %0A
     /** check wh
@@ -2047,24 +2047,24 @@
 e values */%0A
-
     static p
@@ -2574,32 +2574,372 @@
     %7D%0A    %0A    %0A
+    /** check whether a decoded encoding matches the original value */%0A    static private void checkCodingDecoding( final Object controlValue ) %7B%0A        final String coding = JSONCoder.encode( controlValue );%0A        final Object testValue = JSONDecoder.decode( coding );%0A        assertEquality( controlValue, testValue );%0A    %7D%0A    %0A    %0A
     /** Assert w
@@ -3074,32 +3074,32 @@
 t testValue ) %7B%0A
-
         Assert.a
@@ -3108,16 +3108,45 @@
 ertTrue(
+ controlValue == testValue %7C%7C
  control

Add coding/decoding test case.