"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const serialize_1 = require("../serialize");
const chai_1 = require("chai");
describe('binary serialization >', () => {
    beforeEach(() => __awaiter(void 0, void 0, void 0, function* () { }));
    it('deserialize/serialize number arrays', () => __awaiter(void 0, void 0, void 0, function* () {
        const x = {
            dtype: 'float32',
            value: new DataView(new Float32Array([0, 0.5, 1]).buffer),
            shape: [3],
            type: null,
        };
        const deserialized_x = serialize_1.array_or_json_serializer.deserialize(x, null);
        chai_1.expect([...deserialized_x]).to.deep.equal([0, 0.5, 1.0]);
        const serialized_x = serialize_1.array_or_json_serializer.serialize(deserialized_x, null);
        chai_1.expect(serialized_x).to.deep.equal(x);
    }));
    it('deserialize/serialize date arrays', () => __awaiter(void 0, void 0, void 0, function* () {
        // 2005-02-25 and 2 days after:
        const x = {
            dtype: 'float64',
            value: new DataView(new Float64Array([1109289600000, 1109376000000, 1109462400000]).buffer),
            shape: [3],
            type: 'date',
        };
        const deserialized_x = serialize_1.array_or_json_serializer.deserialize(x, null);
        chai_1.expect(deserialized_x.type).to.equal('date');
        chai_1.expect([...deserialized_x]).to.deep.equal([
            1109289600000, 1109376000000, 1109462400000,
        ]);
        const serialized_x = serialize_1.array_or_json_serializer.serialize(deserialized_x, null);
        chai_1.expect(serialized_x).to.deep.equal(x);
    }));
    it('deserialize/serialize string arrays', () => __awaiter(void 0, void 0, void 0, function* () {
        // String arrays are not sent using binary buffers from the Python side
        const strlist = ['H', 'E', 'L', 'L', 'O'];
        const deserialized_strlist = serialize_1.array_or_json_serializer.deserialize(strlist, null);
        chai_1.expect(deserialized_strlist).to.deep.equal(strlist);
        const serialized_strlist = serialize_1.array_or_json_serializer.serialize(deserialized_strlist, null);
        chai_1.expect(serialized_strlist).to.deep.equal(strlist);
    }));
    it('deserialize/serialize nested arrays', () => __awaiter(void 0, void 0, void 0, function* () {
        const x = [
            {
                dtype: 'float32',
                value: new DataView(new Float32Array([0, 0.5, 1]).buffer),
                shape: [3],
                type: null,
            },
            {
                dtype: 'float32',
                value: new DataView(new Float32Array([0, 0.5]).buffer),
                shape: [2],
                type: null,
            },
            {
                dtype: 'float32',
                value: new DataView(new Float32Array([0, 0.5, 2, 3]).buffer),
                shape: [4],
                type: null,
            },
        ];
        const deserialized_x = serialize_1.array_or_json_serializer.deserialize(x, null);
        chai_1.expect(deserialized_x.length).to.equal(3);
        chai_1.expect([...deserialized_x[0]]).to.deep.equal([0, 0.5, 1.0]);
        chai_1.expect([...deserialized_x[1]]).to.deep.equal([0, 0.5]);
        chai_1.expect([...deserialized_x[2]]).to.deep.equal([0, 0.5, 2, 3]);
        const serialized_x = serialize_1.array_or_json_serializer.serialize(deserialized_x, null);
        chai_1.expect(serialized_x).to.deep.equal(x);
    }));
});
//# sourceMappingURL=binary_serialization.js.map