struffer
Version:
Struct + Buffer = Struffer
129 lines • 5.43 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const alsatian_1 = require("alsatian");
const common_1 = require("../src/common");
let TotalBitsTests = class TotalBitsTests {
default(num, bitCount) {
alsatian_1.Expect(common_1.totalBits(num)).toBe(bitCount);
}
};
__decorate([
alsatian_1.TestCase(2, 2),
alsatian_1.TestCase(-1, 2),
alsatian_1.TestCase(32, 6),
alsatian_1.TestCase(255, 8),
alsatian_1.TestCase(-127, 8),
alsatian_1.Test('Default')
], TotalBitsTests.prototype, "default", null);
TotalBitsTests = __decorate([
alsatian_1.TestFixture('totalBits tests')
], TotalBitsTests);
exports.TotalBitsTests = TotalBitsTests;
let SplitIntoBitsTests = class SplitIntoBitsTests {
unsignedSplit(num, bits) {
alsatian_1.Expect(common_1.splitIntoBits(num)).toEqual(bits);
alsatian_1.Expect(common_1.splitIntoBits(num, false)).toEqual(bits);
}
signedSplit(num, bits) {
alsatian_1.Expect(common_1.splitIntoBits(num, true)).toEqual(bits);
}
};
__decorate([
alsatian_1.TestCase(1, [1]),
alsatian_1.TestCase(32, [1, 0, 0, 0, 0, 0]),
alsatian_1.TestCase(-1, [1]),
alsatian_1.TestCase(-23, [0, 1, 0, 0, 1]),
alsatian_1.Test('Unsigned integer split')
], SplitIntoBitsTests.prototype, "unsignedSplit", null);
__decorate([
alsatian_1.TestCase(1, [0, 1]),
alsatian_1.TestCase(32, [0, 1, 0, 0, 0, 0, 0]),
alsatian_1.TestCase(-1, [1, 1]),
alsatian_1.TestCase(-23, [1, 0, 1, 0, 0, 1]),
alsatian_1.Test('Signed integer split')
], SplitIntoBitsTests.prototype, "signedSplit", null);
SplitIntoBitsTests = __decorate([
alsatian_1.TestFixture('splitIntoBits tests')
], SplitIntoBitsTests);
exports.SplitIntoBitsTests = SplitIntoBitsTests;
let UnsignedSplitTests = class UnsignedSplitTests {
default(num, bits, bitCount) {
alsatian_1.Expect(common_1.unsignedSplit(num, (bitCount !== undefined) ? bitCount : undefined)).toEqual(bits);
}
};
__decorate([
alsatian_1.TestCase(3, [1, 1]),
alsatian_1.TestCase(6, [0, 0, 1, 1, 0], 5),
alsatian_1.Test('Default')
], UnsignedSplitTests.prototype, "default", null);
UnsignedSplitTests = __decorate([
alsatian_1.TestFixture('unsignedSplit tests')
], UnsignedSplitTests);
exports.UnsignedSplitTests = UnsignedSplitTests;
let JoinBitsTests = class JoinBitsTests {
default(bits, num) {
alsatian_1.Expect(common_1.joinBits(bits)).toBe(num);
}
};
__decorate([
alsatian_1.TestCase([1, 1], 3),
alsatian_1.TestCase([1, 0, 1, 0], 10),
alsatian_1.Test('Default')
], JoinBitsTests.prototype, "default", null);
JoinBitsTests = __decorate([
alsatian_1.TestFixture('joinBits tests')
], JoinBitsTests);
exports.JoinBitsTests = JoinBitsTests;
let JoinSignedBitsTests = class JoinSignedBitsTests {
default(bits, num) {
alsatian_1.Expect(common_1.joinSignedBits(bits)).toBe(num);
}
};
__decorate([
alsatian_1.TestCase([0, 1, 1], 3),
alsatian_1.TestCase([0, 1, 0, 1, 0], 10),
alsatian_1.TestCase([1, 0, 1], -3),
alsatian_1.TestCase([1, 0, 1, 1, 0], -10),
alsatian_1.Test('Default')
], JoinSignedBitsTests.prototype, "default", null);
JoinSignedBitsTests = __decorate([
alsatian_1.TestFixture('joinSignedBits tests')
], JoinSignedBitsTests);
exports.JoinSignedBitsTests = JoinSignedBitsTests;
const type = {
LittleEndian: common_1.MemberEndianness.LittleEndian,
BigEndian: common_1.MemberEndianness.BigEndian,
Signed: common_1.MemberSignature.Signed,
Unsigned: common_1.MemberSignature.Unsigned,
};
let ParseTypeTests = class ParseTypeTests {
default(type, bitSize, signature, endianness) {
const info = common_1.parseType(type);
alsatian_1.Expect(info.bitSize).toBe(bitSize);
alsatian_1.Expect(info.signature).toBe(signature);
alsatian_1.Expect(info.endianness).toBe(endianness);
}
};
__decorate([
alsatian_1.TestCase('byte', 8, type.Signed, type.LittleEndian),
alsatian_1.TestCase('unsigned byte', 8, type.Unsigned, type.LittleEndian),
alsatian_1.TestCase('signed unsigned signed unsigned byte', 8, type.Signed, type.LittleEndian),
alsatian_1.TestCase('long short short short long int', 16, type.Signed, type.LittleEndian),
alsatian_1.TestCase('int_23be', 23, type.Signed, type.BigEndian),
alsatian_1.TestCase('uint2', 2, type.Unsigned, type.LittleEndian),
alsatian_1.TestCase('u8 BE', 8, type.Unsigned, type.BigEndian),
alsatian_1.TestCase('i3', 3, type.Signed, type.LittleEndian),
alsatian_1.TestCase('long char_be', 16, type.Signed, type.BigEndian),
alsatian_1.Test('Default')
], ParseTypeTests.prototype, "default", null);
ParseTypeTests = __decorate([
alsatian_1.TestFixture('parseType tests')
], ParseTypeTests);
exports.ParseTypeTests = ParseTypeTests;
//# sourceMappingURL=utils.test.js.map