import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import in.brame.Brame;
import sensor.DefSensor;
import sensor.Value1;
import sensor.Value2;

import static org.junit.Assert.*;

/*
 * This Java source file was auto generated by running 'gradle init --type java-library'
 * by 'rami' at '13/09/17 17:59' with Gradle 2.14
 *
 * @author rami, @date 13/09/17 17:59
 */
public class BrameTest {
    @Test public void testBrameMethod() {

        Map<Short,Class> sensorFrames =new HashMap<>();
        sensorFrames.put((short)10000,Value1.class);
        sensorFrames.put((short)-1,Value2.class);

        Brame.load(DefSensor.class,sensorFrames);


        int value1sent=5;
        byte[] value2sent= new byte[]{1,2,3,4,5,6,7,8,9,10};

        Brame enbrame = new Brame(new DefSensor(value1sent,value2sent));
        //enbrame.addDef(new DefSensor(value1,value2)); // you can add/remove defs later on as well

        byte[] inbytes= enbrame.getBytes(); // bytes can be sent over or stored

        for (byte b:inbytes) System.out.print(b+"|");
        // 0|0|0|26|39|16|0|0|0|5|-1|-1|0|0|0|10|1|2|3|4|5|6|7|8|9|10|

        Brame debrame= new Brame(inbytes);

        System.out.println(" Num of defs inside debrame:" + debrame.getDefs().size());

        DefSensor defSensor=debrame.getDef(DefSensor.class);

        assertNotNull(defSensor);

        if(defSensor!=null) {
           int value1recv=defSensor.value1.getValue();
            byte[] value2recv=defSensor.value2.getValue();

            assertEquals(value1sent,value1recv);
            assertEquals(value2sent.length,value2recv.length);
        }



    }


}
