const { parse, getByPid, dec2hex, hex2dec} = require('.');

// test('adds 1 + 2 to equal 3', () => {
//   expect(parse(1, 2)).toBe(3);
// });

describe("#_dec2hex()", () => {
    it( "Testing convert DEC to HEX number", () => {
        expect( dec2hex( 0 )).toBe( "00" );
        expect( dec2hex( 1 )).toBe( "01" );
        expect( dec2hex( 10 )).toBe("0A" );
        expect( dec2hex( 32 )).toBe("20" );
        expect( dec2hex( 255 )).toBe("FF" );
    });
});

describe("#_hex2dec()", () =>
	{
		it( "Testing convert HEX to DEC number", () =>
		{
			expect( hex2dec( "0" )).toBe(0);
			expect( hex2dec( "1" )).toBe(1);
			expect( hex2dec( "F" )).toBe(15);

			expect( hex2dec( "00" )).toBe(0 );
			expect( hex2dec( "01" )).toBe(1 );
			expect( hex2dec( "0A" )).toBe(10);
			expect( hex2dec( "20" )).toBe(32);
			expect( hex2dec( "FF" )).toBe(255);
		});
});

describe("#getByPid()", () =>
	{
		it( "Testing get PID details by pid number", () =>
		{
			var detailsRPM = getByPid( "0C" );
			var detailsVSS = getByPid( "0D", "01" );
			expect( detailsRPM.name).toBe( "rpm" );
			expect( detailsVSS.name).toBe( "vss" );
		});
});

// describe("#parse()", () =>
// 	{
// 		it( "Testing parse CAN data", () =>
// 		{
// 			var reply = parse( "03 41 0D 00 00 00 00 00" );
//             expect(reply.value).toBe(13)
//             expect(reply.name).toBe('vss')
//             expect(reply.mode).toBe('41')
//             expect(reply.pid).toBe('0D')
//             expect(reply.min).toBe(0)
//             expect(reply.max).toBe(255)
//             expect(reply.unit).toBe('km/h')
// 		});
// });

describe("#parse()", () =>
	{
		it( "Testing parse CAN data", () =>
		{
			var reply = parse( "0x04 0x41 0x0C 0x01 0xE6 0x00 0x00 0x00" );
            expect(reply.value).toBe(13)
            expect(reply.name).toBe('vss')
            expect(reply.mode).toBe('41')
            expect(reply.pid).toBe('0D')
            expect(reply.min).toBe(0)
            expect(reply.max).toBe(255)
            expect(reply.unit).toBe('km/h')
		});
});