/*******************************************************************************
 * Copyright (c) 2015-2018 Skymind, Inc.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Apache License, Version 2.0 which is available at
 * https://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 ******************************************************************************/

package org.datavec.python;

import org.datavec.api.transform.Transform;
import org.datavec.api.transform.schema.Schema;
import org.datavec.api.transform.serde.JsonSerializer;
import org.datavec.api.transform.serde.YamlSerializer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

public class TestSerde {

    public static YamlSerializer y = new YamlSerializer();
    public static JsonSerializer j = new JsonSerializer();

    @Test @Timeout(60)
    public void testBasicSerde(){
        Schema schema = new Schema.Builder()
                .addColumnInteger("col1")
                .addColumnFloat("col2")
                .addColumnString("col3")
                .addColumnDouble("col4")
                .build();

        Transform t = PythonTransform.builder().code(
                "col1+=3\ncol2+=2\ncol3+='a'\ncol4+=2.0"
        ).inputSchema(schema).outputSchema(schema).build();

        String yaml = y.serialize(t);
        String json = j.serialize(t);

        Transform t2 = y.deserializeTransform(yaml);
        Transform t3 = j.deserializeTransform(json);
        assertEquals(t, t2);
        assertEquals(t, t3);
    }

}
